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 #26 from krisajenkins/master
Browse files Browse the repository at this point in the history
Performance improvement - call resize only when necessary.
  • Loading branch information
cryogenian authored Jul 28, 2017
2 parents d4d9205 + 50350fc commit 6c11c2f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Halogen/ECharts.purs
Original file line number Diff line number Diff line change
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 @@ -141,12 +141,12 @@ eval (Clear next) = do
for_ state.chart $ liftEff <<< EC.clear
pure next
eval (SetDimensions { width, height } next) = do
for_ width \w → do
H.modify _{ width = w }
for_ height \h → do
H.modify _{ height = h }
state ← H.get
for_ state.chart $ liftEff <<< EC.resize
state <- H.get

-- Only trigger a resize is the dimensions have actually changed.
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
state ← H.get
Expand Down

0 comments on commit 6c11c2f

Please sign in to comment.