Last active
November 2, 2015 13:25
-
-
Save terrierscript/aa53dd94c02e228c8164 to your computer and use it in GitHub Desktop.
Redux初めて触って色々わかったメモ ref: http://qiita.com/inuscript/items/8dc5af052a858023287f
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
function mapStateToProps(state) { | |
return { todos: state.todos }; | |
} | |
export default connect(mapStateToProps)(TodoApp); |
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
class UsersStore extends Marty.Store { | |
constructor(options) { | |
super(options); | |
this.state = []; | |
this.handlers = { | |
addUser: Constants.RECEIVE_USER | |
}; | |
} | |
addUser(user) { | |
this.state.push(user); | |
this.hasChanged(); | |
} | |
} |
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
function someReducer(state, action) { | |
switch (action.type) { | |
case SOME_ACTION: | |
return Object.assign({}, state, { | |
some: action.someValue | |
}); | |
default: | |
return state; | |
} | |
} |
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
<Provider store={store}> | |
{() => <App/>} | |
</Provider> |
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
function someReducer(state, action) { | |
switch (action.type) { | |
case SOME_ACTION: | |
state.someValue = action.someValue | |
return state; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment