@@ -1,32 +1,38 @@
1−
21module JavaScript.Experimental where
2+{-| A pair of very experimental functions for converting between
3+Elm records and JavaScript objects. It currently uses a best effort
4+conversion that can cause runtime errors. This API should change and
5+improve as we find its key failings.
6+-}
37
48import JavaScript (JSObject)
59import Native.JavaScript
610
7−-- Turn arbitrary JavaScript objects into Elm records.
8−-- Arrays are converted into lists, nested objects are allowed.
9−-- No `null` values or non-homogeneous arrays.
10−--
11−-- -- OK objects
12−-- { student:"Steve", scores:[83,94,99,72] }
13−-- { errorLevel:10, critical:true }
14−--
15−-- -- BAD objects
16−-- { answer:null }
17−-- { info:[true,42,'what'] }
11+{-| Turn arbitrary JavaScript objects into Elm records.
12+Arrays are converted into lists, nested objects are allowed.
13+No `null` values or non-homogeneous arrays.
14+
15+ -- OK objects
16+ { student:"Steve", scores:[83,94,99,72] }
17+ { errorLevel:10, critical:true }
18+
19+ -- BAD objects
20+ { answer:null }
21+ { info:[true,42,'what'] }
22+-}
1823toRecord : JSObject -> a
1924toRecord = Native.JavaScript.toRecord
2025
21−-- Turn arbitrary Elm records into JavaScript objects.
22−-- Lists become arrays, nested records are allowed. No ADTs.
23−--
24−-- -- OK records
25−-- { student="Steve", scores=[83,94,99,72] }
26−-- { errorLevel=10, critical=True }
27−--
28−-- -- BAD records
29−-- { answer = Nothing }
30−-- { result = Left "An error occurred" }
26+{-| Turn arbitrary Elm records into JavaScript objects.
27+Lists become arrays, nested records are allowed. No ADTs.
28+
29+ -- OK records
30+ { student="Steve", scores=[83,94,99,72] }
31+ { errorLevel=10, critical=True }
32+
33+ -- BAD records
34+ { answer = Nothing }
35+ { result = Left "An error occurred" }
36+-}
3137fromRecord : a -> JSObject
3238fromRecord = Native.JavaScript.fromRecord