-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to dryadic 0.2.0 - moved Store back into supercollider.js
- Loading branch information
1 parent
8e051c0
commit 7048f31
Showing
7 changed files
with
50 additions
and
5 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
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,43 @@ | ||
|
||
import Immutable from 'immutable'; | ||
|
||
/** | ||
* A store that holds the state tree. | ||
* | ||
* Holds an Immutable.Map and offers functions to mutate sub-states in that tree, | ||
* and stores the new state. | ||
* | ||
*/ | ||
export default class Store { | ||
|
||
constructor() { | ||
this.state = Immutable.Map(); | ||
} | ||
|
||
getIn(keys, notSetValue) { | ||
return this.state.getIn(keys, notSetValue); | ||
} | ||
|
||
/** | ||
* Fetch the object at keys | ||
* pass it to the function which mutates it and returns new sub state. | ||
*/ | ||
mutateState(keys, fn) { | ||
this.state = this.state.updateIn(keys, Immutable.Map(), fn); | ||
} | ||
|
||
/** | ||
* Fetch one part of the state, | ||
* mutate it with the callback, | ||
* which returns result, subState. | ||
* Save the subState back into state and return the result. | ||
* | ||
* @returns {any} result | ||
*/ | ||
mutateStateAndReturn(keys, fn) { | ||
var result, subState; | ||
[result, subState] = fn(this.state.getIn(keys, Immutable.Map())); | ||
this.state = this.state.setIn(keys, subState); | ||
return result; | ||
} | ||
} |
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