Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

Commit ac7dfdd

Browse files
committed
add JSON output
1 parent f667089 commit ac7dfdd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

psc-package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"prelude",
77
"psci-support",
88
"react-basic",
9+
"simple-json",
910
"test-unit"
1011
]
1112
}

src/Component/App.purs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Data.Maybe (Maybe(..), fromMaybe)
1010
import React.Basic (Component, JSX, Self, StateUpdate(..), capture, createComponent, make)
1111
import React.Basic.DOM as H
1212
import React.Basic.DOM.Events (preventDefault, targetValue)
13+
import Simple.JSON (class WriteForeign, writeImpl)
14+
import Simple.JSON as SimpleJSON
1315

1416
type Props =
1517
{}
@@ -25,10 +27,19 @@ type Form =
2527
type OptionLabel = String
2628
type OptionValue = String
2729
data Option = Option OptionLabel OptionValue
30+
31+
instance writeForeignOption :: WriteForeign Option where
32+
writeImpl (Option label value) = do
33+
writeImpl { label, value }
34+
2835
type Label = String
2936
type Name = String
3037
data Select = Select Name Label (Array Option)
3138

39+
instance writeForeignSelect :: WriteForeign Select where
40+
writeImpl (Select name label options) = do
41+
writeImpl { name, label, options }
42+
3243
type State =
3344
{ built :: Maybe (Array Select)
3445
, form :: Form
@@ -53,6 +64,10 @@ app = make component { initialState, render, update } {}
5364
buildFromForm :: Form -> Array Select
5465
buildFromForm { selects } = selects
5566

67+
jsonTextFromSelects :: Array Select -> String
68+
jsonTextFromSelects selects =
69+
SimpleJSON.writeJSON selects
70+
5671
initialForm :: Form
5772
initialForm =
5873
{ label: ""
@@ -190,6 +205,13 @@ render self@{ state: { built, form } } =
190205
)
191206
)
192207
]
208+
, H.div_
209+
[ H.span_
210+
[ H.text "selects (json)"
211+
]
212+
, H.textarea
213+
{ readOnly: true, value: jsonTextFromSelects form.selects }
214+
]
193215
]
194216
, H.div_
195217
[ H.button

0 commit comments

Comments
 (0)