diff --git a/src/off_topic/internal/runtime.gleam b/src/off_topic/internal/runtime.gleam index 7aea962..daba353 100644 --- a/src/off_topic/internal/runtime.gleam +++ b/src/off_topic/internal/runtime.gleam @@ -90,7 +90,7 @@ type State(message) { tick: Int, element: Bool, config: Config, - cleanup: Option(fn() -> Nil), + cleanup: fn() -> Nil, last_fired: Int, delay_tick: Int, ) @@ -181,7 +181,7 @@ pub fn map( Remote(decoder:, ..) -> Remote(..subscription, decoder: decode.map(decoder, tagger)) - Batch(subscriptions) -> Batch(list.map(subscriptions, map(_, tagger))) + Batch(subscriptions) -> Batchs(list.map(subscriptions, map(_, tagger))) } } @@ -542,9 +542,8 @@ pub fn update( DelayFired(tick:, path:, delay_tick:, message:) -> { use state <- emit_message(model, path, subscriptions, update) case state { - Running(cleanup: Some(_), ..) - if state.tick == tick && state.delay_tick == delay_tick - -> Ok(message) + Running(..) if state.tick == tick && state.delay_tick == delay_tick -> + Ok(message) _ -> Error(Nil) } } @@ -697,8 +696,8 @@ fn started(tick, path, state, cleanup) { use #(state, _) <- result.map( update_at(state, path, fn(s) { case s { - Running(cleanup: None, ..) if s.tick == tick -> - Ok(#(Running(..s, cleanup: Some(cleanup)), Nil)) + Running(..) if s.tick == tick -> + Ok(#(Running(..s, cleanup: cleanup), Nil)) _ -> Error(Nil) } }), @@ -726,9 +725,7 @@ type Dispatch(message) { fn throttle_delay(now, state, tick, path, message) { use state <- update_at(state, path) case state { - Running(cleanup: Some(_), config:, last_fired:, delay_tick:, ..) - if state.tick == tick - -> { + Running(config:, last_fired:, delay_tick:, ..) if state.tick == tick -> { let throttle_passes = config.throttle == 0 || now - last_fired >= config.throttle let delay_tick = delay_tick + 1 @@ -789,8 +786,7 @@ fn diff_batch(tick, index, path, left, right, out, effects) { fn cleanup(state, path, effects) { case state { - Running(cleanup: None, ..) -> effects - Running(cleanup: Some(cleanup), ..) -> { + Running(cleanup:, ..) -> { [effect.from(fn(_) { cleanup() }), ..effects] } Connected(tick:, name:, ..) -> { @@ -870,8 +866,8 @@ fn running(tick: Int, element: Bool, config: Config) -> State(message) { Running( tick:, element:, - cleanup: None, config:, + cleanup: fn() { Nil }, last_fired: 0, delay_tick: 0, )