diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-04-27 21:52:15 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-04-27 21:52:15 +0100 |
commit | 10bc93f41efdd9aab25e1e0d29b02b3b961158c5 (patch) | |
tree | 9d9c8fc3daf61326b7ebe4781be8d58e7dc8444a /test/example/main.gleam | |
parent | 19ec0b446041f77a623e574656442c76d75107ae (diff) | |
download | lustre-10bc93f41efdd9aab25e1e0d29b02b3b961158c5.tar.gz lustre-10bc93f41efdd9aab25e1e0d29b02b3b961158c5.zip |
:bookmark: Code for 3.0.0-rc.13.0.0-rc.1
Diffstat (limited to 'test/example/main.gleam')
-rw-r--r-- | test/example/main.gleam | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/test/example/main.gleam b/test/example/main.gleam deleted file mode 100644 index 21c4067..0000000 --- a/test/example/main.gleam +++ /dev/null @@ -1,73 +0,0 @@ -// IMPORTS --------------------------------------------------------------------- - -import lustre -import lustre/cmd.{ Cmd } -import lustre/element.{ Element } - -import example/application/counter - -// MAIN ------------------------------------------------------------------------ - -pub fn main () -> Nil { - let selector = "[data-lustre-container]" - let program = lustre.application(init(), update, render) - - // `lustre.start` can return an `Error` if no DOM element is found that matches - // the selector. This is a fatal error for our examples, so we panic if that - // happens. - let assert Ok(dispatch) = lustre.start(program, selector) - - dispatch(Counter(counter.Incr)) - dispatch(Counter(counter.Incr)) - dispatch(Counter(counter.Incr)) - - Nil -} - -// STATE ----------------------------------------------------------------------- - -type State { - State( - counter: counter.State - ) -} - -fn init () -> #(State, Cmd(Action)) { - let #(counter, counter_cmds) = counter.init() - let state = State( - counter - ) - - #(state, cmd.map(counter_cmds, Counter)) -} - -// UPDATE ---------------------------------------------------------------------- - -type Action { - Counter(counter.Action) -} - -fn update (state: State, action: Action) -> #(State, Cmd(Action)) { - case action { - Counter(counter_action) -> { - let #(counter, counter_cmds) = counter.update(state.counter, counter_action) - let state = State( - counter - ) - - #(state, cmd.map(counter_cmds, Counter)) - } - } -} - -// RENDER ---------------------------------------------------------------------- - -fn render (state: State) -> Element(Action) { - element.div([], [ - element.details([], [ - element.summary([], [ element.text("Counter") ]), - counter.render(state.counter) - |> element.map(Counter) - ]) - ]) -} |