From 5fff05a556045201d3620d5fedd43547685eb0c3 Mon Sep 17 00:00:00 2001 From: Gusztav Szikszai Date: Sun, 29 Jul 2018 08:50:43 +0200 Subject: [PATCH] Update to new state syntax. --- tests/Http.mint | 38 ++++++++++++------------------ tests/Promise.mint | 12 ++++------ tests/Provider/AnimationFrame.mint | 10 +++----- tests/Provider/Mouse.mint | 26 +++++++------------- tests/Provider/Scroll.mint | 10 +++----- tests/Provider/Tick.mint | 10 +++----- 6 files changed, 37 insertions(+), 69 deletions(-) diff --git a/tests/Http.mint b/tests/Http.mint index 1646ef6..2f8699b 100644 --- a/tests/Http.mint +++ b/tests/Http.mint @@ -148,12 +148,6 @@ suite "Http.sendWithID" { } } -record Test.Http { - status : Number, - error : String, - body : String -} - component Test.Http { property method : String = "GET" property timeout : Bool = false @@ -161,11 +155,9 @@ component Test.Http { property abort : Bool = false property error : Bool = false - state : Test.Http { - status = 0, - error = "", - body = "" - } + state errorMessage : String = "" + state status : Number = 0 + state body : String = "" fun componentDidMount : Void { do { @@ -190,34 +182,34 @@ component Test.Http { }) `) - next { state | status = response.status } + next { status = response.status } } catch Http.ErrorResponse => error { case (error.type) { Http.Error::NetworkError => next - { state | - error = "network-error", + { + errorMessage = "network-error", status = error.status } Http.Error::BadUrl => next - { state | - error = "bad-url", + { + errorMessage = "bad-url", status = error.status } Http.Error::Timeout => next - { state | - error = "timeout", + { + errorMessage = "timeout", status = error.status } Http.Error::Aborted => next - { state | - error = "aborted", + { + errorMessage = "aborted", status = error.status } @@ -229,15 +221,15 @@ component Test.Http { fun render : Html {
- <{ state.error }> + <{ errorMessage }> - <{ state.body }> + <{ body }> - <{ Number.toString(state.status) }> + <{ Number.toString(status) }>
} diff --git a/tests/Promise.mint b/tests/Promise.mint index 7432ea8..1963df9 100644 --- a/tests/Promise.mint +++ b/tests/Promise.mint @@ -1,15 +1,11 @@ -record Test.Promise { - result : String -} - component Test.Promise { - state : Test.Promise { result = "" } + state result : String = "" fun reject : Void { do { Promise.reject("rejected") } catch String => result { - next { state | result = result } + next { result = result } } } @@ -18,14 +14,14 @@ component Test.Promise { result = Promise.resolve("resolved") - next { state | result = result } + next { result = result } } } fun render : Html {
- <{ state.result }> + <{ result }> { resolve() }}/> diff --git a/tests/Provider/AnimationFrame.mint b/tests/Provider/AnimationFrame.mint index e071cea..6fc3250 100644 --- a/tests/Provider/AnimationFrame.mint +++ b/tests/Provider/AnimationFrame.mint @@ -1,15 +1,11 @@ -record Test.Provider.AnimationFrame { - frames : Number -} - component Test.Provider.AnimationFrame { - state : Test.Provider.AnimationFrame { frames = 0 } + state frames : Number = 0 - use Provider.AnimationFrame { frames = () : Void => { next { state | frames = state.frames + 1 } } } + use Provider.AnimationFrame { frames = () : Void => { next { frames = frames + 1 } } } fun render : Html {
- <{ Number.toString(state.frames) }> + <{ Number.toString(frames) }>
} } diff --git a/tests/Provider/Mouse.mint b/tests/Provider/Mouse.mint index 82d46a5..8406d12 100644 --- a/tests/Provider/Mouse.mint +++ b/tests/Provider/Mouse.mint @@ -1,34 +1,26 @@ -record Test.Provider.Mouse { - clicks : Number, - moves : Number, - ups : Number -} - component Test.Provider.Mouse { - state : Test.Provider.Mouse { - clicks = 0, - moves = 0, - ups = 0 - } + state clicks : Number = 0 + state moves : Number = 0 + state ups : Number = 0 use Provider.Mouse { - clicks = (event : Html.Event) : Void => { next { state | clicks = state.clicks + 1 } }, - moves = (event : Html.Event) : Void => { next { state | moves = state.moves + 1 } }, - ups = (event : Html.Event) : Void => { next { state | ups = state.ups + 1 } } + clicks = (event : Html.Event) : Void => { next { clicks = clicks + 1 } }, + moves = (event : Html.Event) : Void => { next { moves = moves + 1 } }, + ups = (event : Html.Event) : Void => { next { ups = ups + 1 } } } fun render : Html {
- <{ Number.toString(state.clicks) }> + <{ Number.toString(clicks) }> - <{ Number.toString(state.moves) }> + <{ Number.toString(moves) }> - <{ Number.toString(state.ups) }> + <{ Number.toString(ups) }>
} diff --git a/tests/Provider/Scroll.mint b/tests/Provider/Scroll.mint index 158903a..0285ee4 100644 --- a/tests/Provider/Scroll.mint +++ b/tests/Provider/Scroll.mint @@ -1,11 +1,7 @@ -record Test.Provider.Scroll { - position : Number -} - component Test.Provider.Scroll { - use Provider.Scroll { scrolls = (event : Html.Event) : Void => { next { state | position = Window.scrollTop() } } } + use Provider.Scroll { scrolls = (event : Html.Event) : Void => { next { position = Window.scrollTop() } } } - state : Test.Provider.Scroll { position = 0 } + state position : Number = 0 style base { height: 3000px; @@ -14,7 +10,7 @@ component Test.Provider.Scroll { fun render : Html { - <{ Number.toString(state.position) }> + <{ Number.toString(position) }>
} } diff --git a/tests/Provider/Tick.mint b/tests/Provider/Tick.mint index 7fbb93c..6b94f9e 100644 --- a/tests/Provider/Tick.mint +++ b/tests/Provider/Tick.mint @@ -1,15 +1,11 @@ -record Test.Provider.Tick { - counter : Number -} - component Test.Provider.Tick { - state : Test.Provider.Tick { counter = 0 } + state counter : Number = 0 - use Provider.Tick { ticks = () : Void => { next { state | counter = state.counter + 1 } } } + use Provider.Tick { ticks = () : Void => { next { counter = counter + 1 } } } fun render : Html {
- <{ Number.toString(state.counter) }> + <{ Number.toString(counter) }>
} }