Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #27 from cryogenian/events
Browse files Browse the repository at this point in the history
events, messages
  • Loading branch information
cryogenian authored Aug 18, 2017
2 parents 6c11c2f + 500e69d commit 9698a36
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"package.json"
],
"dependencies": {
"purescript-halogen": "^2.0.0",
"purescript-halogen": "^2.1.0",
"purescript-halogen-css": "^6.0.0",
"purescript-echarts": "^5.0.0"
"purescript-echarts": "^6.0.0"
},
"devDependencies": {
"purescript-debug": "^3.0.0",
Expand Down
10 changes: 5 additions & 5 deletions example/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ import Control.Monad.Aff (Aff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Random (randomInt, RANDOM)

import Data.Array ((!!), length, snoc, sort, reverse, head, filter)
import Data.Foldable (for_)
import Data.Maybe (Maybe(..), maybe)
import Data.Tuple.Nested ((/\))

import Halogen as H
import Halogen.Aff (runHalogenAff, awaitBody)
import Halogen.ECharts as EC
import Halogen.HTML.Events as HE
import Halogen.HTML as HH
import Halogen.Aff (runHalogenAff, awaitBody)
import Halogen.HTML.Events as HE
import Halogen.VDom.Driver (runUI)

import Options (options)

randomInArray e a. Array a Eff (random RANDOM|e) (Maybe a)
Expand Down Expand Up @@ -97,6 +94,9 @@ eval (HandleEChartsMessage ix EC.Initialized next) = do
for_ mbopt \opt →
void $ H.query ix $ H.action $ EC.Set opt
pure next
eval (HandleEChartsMessage ix (EC.EventRaised evt) next) = do
pure next


main Eff AppEffects Unit
main = runHalogenAff do
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"scripts": {
"clean": "rm -rf output .pulp-cache example/dist/test.js",
"build": "pulp build -- --censor-lib --strict",
"example": "npm run clean && pulp browserify --include example/src --to example/dist/test.js"
"example": "pulp browserify --include example/src --to example/dist/test.js",
"build:non-strict": "pulp build -- --censor-lib"
},
"dependencies": {
"pulp": "^11.0.0",
Expand Down
33 changes: 19 additions & 14 deletions src/Halogen/ECharts.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,31 @@ module Halogen.ECharts

import Prelude

import CSS.Geometry (width, height)
import CSS.Size (px)
import Control.Monad.Aff.AVar (AVAR)
import Control.Monad.Aff.Class (class MonadAff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Control.Monad.Eff.Ref (REF)
import Control.Monad.Aff.AVar (AVAR)
import Control.Monad.Aff.Class (class MonadAff)

import DOM (DOM)
import Data.Foldable (for_, traverse_)
import Data.Foreign (Foreign)
import Data.Int (toNumber)
import Data.Maybe (Maybe(..), maybe)
import Data.Traversable (for)
import Data.Tuple.Nested (type (/\), (/\))

import DOM (DOM)

import CSS.Geometry (width, height)
import CSS.Size (px)

import ECharts.Chart as EC
import ECharts.Event as EE
import ECharts.Monad as EM
import ECharts.Theme as ETheme
import ECharts.Types as ET
import ECharts.Monad as EM
import ECharts.Types.Phantom as ETP

import Halogen as H
import Halogen.HTML.CSS (style)
import Halogen.HTML as HH
import Halogen.HTML.CSS (style)
import Halogen.HTML.Properties as HP

import Halogen.Query.EventSource as ES

type EChartsState =
{ chart Maybe ET.Chart
Expand All @@ -47,6 +43,7 @@ type EChartsState =

data EChartsQuery a
= Init (Maybe ETheme.Theme) a
| HandleEvent ET.EChartsEvent (H.SubscribeStatus a)
| Dispose a
| Set (EM.DSL ETP.OptionI) a
| Reset (EM.DSL ETP.OptionI) a
Expand All @@ -57,7 +54,9 @@ data EChartsQuery a
| GetWidth (Int a)
| GetHeight (Int a)

data EChartsMessage = Initialized
data EChartsMessage
= Initialized
| EventRaised ET.EChartsEvent

type EChartsEffects eff =
( echartsET.ECHARTS
Expand Down Expand Up @@ -118,8 +117,14 @@ eval (Init theme next) = do
>>= traverse_ \el → do
chart ← liftEff $ maybe EC.init EC.initWithTheme theme el
H.modify _{ chart = Just chart }
H.subscribe
$ ES.eventSource (EE.listenAll chart)
( Just <<< H.request <<< HandleEvent )
H.raise Initialized
pure next
eval (HandleEvent evt reply) = do
H.raise $ EventRaised evt
pure $ reply H.Listening
eval (Dispose next) = do
state ← H.get
for_ state.chart $ liftEff <<< EC.dispose
Expand Down

0 comments on commit 9698a36

Please sign in to comment.