Convert from a Purescript entry to a JS object

I am trying to convert a record to a JS vanilla object

module MyModule where

data Author = Author { name :: String, interests :: Array String }

phil :: Author
phil = Author { name: "Phil", interests: ["Functional Programming", "JavaScript"] }

when I access an object from JS

MyModule.phil

it contains other properties that don't interest me ( value0)

{"value0":{"name":"Phil","interests":["Functional Programming","JavaScript"]}}

how did you marshal records from the world of Purescript in JS?

+4
source share
1 answer

Section 10.16 of Purescript. For example, Phil Freeman shows an example of newtypewrapping a record:

newtype FormData = FormData 
   { firstName :: String
   , lastName  :: String
   , street    :: String
   , city      :: String
   , state     :: String
   , homePhone :: String
   , cellPhone :: String 
   }

Then in section 10.18 he writes:

" FormData - , FormData, JSON.stringify, JSON. , newtypes , ."

, , psc, . data newtype,

newtype Author = Author { name :: String, interests :: Array String }

phil :: Author
phil = Author { name: "Phil", interests: ["Functional Programming", "JavaScript"] }

// Generated by psc version 0.9.2
"use strict";
var Author = function (x) {
    return x;
};
var phil = {
    name: "Phil",
    interests: [ "Functional Programming", "JavaScript" ]
};
module.exports = {
    Author: Author,
    phil: phil
};
+7

Source: https://habr.com/ru/post/1650614/


All Articles