diff --git a/bower.json b/bower.json index 3f19404..d47a420 100644 --- a/bower.json +++ b/bower.json @@ -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", diff --git a/example/src/Main.purs b/example/src/Main.purs index 8069170..1636f9d 100644 --- a/example/src/Main.purs +++ b/example/src/Main.purs @@ -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) @@ -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 diff --git a/package.json b/package.json index d9c1683..3f25a10 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Halogen/ECharts.purs b/src/Halogen/ECharts.purs index 7282ec7..f97c8e7 100644 --- a/src/Halogen/ECharts.purs +++ b/src/Halogen/ECharts.purs @@ -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 @@ -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 @@ -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 = ( echarts ∷ ET.ECHARTS @@ -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