-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a setState and emitChange method
- Loading branch information
1 parent
1d62528
commit 6e45ae4
Showing
5 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import assert from 'assert' | ||
import Alt from '../dist/alt-with-runtime' | ||
|
||
let alt = new Alt() | ||
|
||
let actions = alt.generateActions('fire', 'nothing') | ||
|
||
class MyStore { | ||
constructor() { | ||
this.foo = 1 | ||
this.bindListeners({ increment: actions.FIRE, nothing: actions.NOTHING }) | ||
} | ||
|
||
increment() { | ||
this.retVal = this.setState({ foo: this.foo + 1 }) | ||
return this.retVal | ||
} | ||
|
||
nothing() { | ||
this.setState() | ||
} | ||
} | ||
|
||
let myStore = alt.createStore(MyStore) | ||
|
||
export default { | ||
'using setState to set the state'() { | ||
actions.fire() | ||
|
||
let changes = 0 | ||
let fart = () => { | ||
changes += 1 | ||
assert.equal(changes, 1, 'listen was fired once') | ||
} | ||
|
||
myStore.listen(fart) | ||
|
||
assert.equal(myStore.getState().foo, 2, 'foo was incremented') | ||
assert.equal(myStore.getState().retVal, false, 'return value of setState is false') | ||
|
||
myStore.unlisten(fart) | ||
|
||
// calling set state without anything doesn't make things crash and burn | ||
actions.nothing() | ||
} | ||
} |