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

Commit

Permalink
Changing SetDimensions to make width and height mandatory.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisajenkins committed Jul 27, 2017
1 parent 0443dd3 commit 50350fc
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/Halogen/ECharts.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Control.Monad.Aff.Class (class MonadAff)
import Data.Foldable (for_, traverse_)
import Data.Foreign (Foreign)
import Data.Int (toNumber)
import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Maybe (Maybe(..), maybe)
import Data.Traversable (for)
import Data.Tuple.Nested (type (/\), (/\))

Expand Down Expand Up @@ -52,7 +52,7 @@ data EChartsQuery a
| Reset (EM.DSL ETP.OptionI) a
| Resize a
| Clear a
| SetDimensions { width Maybe Int, height Maybe Int } a
| SetDimensions { width Int, height Int } a
| GetOptions (Maybe Foreign a)
| GetWidth (Int a)
| GetHeight (Int a)
Expand Down Expand Up @@ -81,7 +81,7 @@ echarts
H.Component HH.HTML EChartsQuery (Dimensions /\ Unit) EChartsMessage g
echarts theme =
echarts' theme \(dim /\ _) →
Just $ H.action $ SetDimensions { width: Just dim.width, height: Just dim.height }
Just $ H.action $ SetDimensions dim

echarts'
eff g i
Expand Down Expand Up @@ -142,12 +142,10 @@ eval (Clear next) = do
pure next
eval (SetDimensions { width, height } next) = do
state <- H.get
let newWidth = fromMaybe state.width width
newHeight = fromMaybe state.height height

-- Only trigger a resize is the dimensions have actually changed.
when (newWidth /= state.width || newHeight /= state.height)
do H.modify _{ width = newWidth, height = newHeight }
when (width /= state.width || height /= state.height)
do H.modify _{ width = width, height = height }
for_ state.chart $ liftEff <<< EC.resize
pure next
eval (GetOptions continue) = do
Expand Down

0 comments on commit 50350fc

Please sign in to comment.