Skip to content
This repository has been archived by the owner on Feb 23, 2019. It is now read-only.

Commit

Permalink
Update to new state syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdotdesign committed Jul 29, 2018
1 parent 210fcf3 commit 5fff05a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 69 deletions.
38 changes: 15 additions & 23 deletions tests/Http.mint
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,16 @@ suite "Http.sendWithID" {
}
}

record Test.Http {
status : Number,
error : String,
body : String
}

component Test.Http {
property method : String = "GET"
property timeout : Bool = false
property url : String = "/blah"
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 {
Expand All @@ -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
}

Expand All @@ -229,15 +221,15 @@ component Test.Http {
fun render : Html {
<div>
<error>
<{ state.error }>
<{ errorMessage }>
</error>

<content>
<{ state.body }>
<{ body }>
</content>

<status>
<{ Number.toString(state.status) }>
<{ Number.toString(status) }>
</status>
</div>
}
Expand Down
12 changes: 4 additions & 8 deletions tests/Promise.mint
Original file line number Diff line number Diff line change
@@ -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 }
}
}

Expand All @@ -18,14 +14,14 @@ component Test.Promise {
result =
Promise.resolve("resolved")

next { state | result = result }
next { result = result }
}
}

fun render : Html {
<div>
<result>
<{ state.result }>
<{ result }>
</result>

<resolve onClick={(event : Html.Event) : Void => { resolve() }}/>
Expand Down
10 changes: 3 additions & 7 deletions tests/Provider/AnimationFrame.mint
Original file line number Diff line number Diff line change
@@ -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 {
<div>
<{ Number.toString(state.frames) }>
<{ Number.toString(frames) }>
</div>
}
}
Expand Down
26 changes: 9 additions & 17 deletions tests/Provider/Mouse.mint
Original file line number Diff line number Diff line change
@@ -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 {
<div>
<clicks>
<{ Number.toString(state.clicks) }>
<{ Number.toString(clicks) }>
</clicks>

<moves>
<{ Number.toString(state.moves) }>
<{ Number.toString(moves) }>
</moves>

<ups>
<{ Number.toString(state.ups) }>
<{ Number.toString(ups) }>
</ups>
</div>
}
Expand Down
10 changes: 3 additions & 7 deletions tests/Provider/Scroll.mint
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +10,7 @@ component Test.Provider.Scroll {

fun render : Html {
<div::base>
<{ Number.toString(state.position) }>
<{ Number.toString(position) }>
</div>
}
}
Expand Down
10 changes: 3 additions & 7 deletions tests/Provider/Tick.mint
Original file line number Diff line number Diff line change
@@ -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 {
<div>
<{ Number.toString(state.counter) }>
<{ Number.toString(counter) }>
</div>
}
}
Expand Down

0 comments on commit 5fff05a

Please sign in to comment.