Created
March 24, 2015 14:08
-
-
Save zerkalica/5eb3e8a5ce6d6ed7e385 to your computer and use it in GitHub Desktop.
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
export default class Page extends React.Component { | |
static props = { | |
actions: PageActions, | |
dispatcher: Dispatcher, | |
config: 'config.Page' | |
} | |
static state = { | |
status: 'PageStore.status', | |
currentTodo: 'PageStore.currentTodo', | |
isEditCurrentTodo: 'PageStore.isEditCurrentTodo' | |
} | |
constructor({props, state, updater}) { | |
super(props) | |
this.state = state | |
this._updaterDefinition = updater(state => this.setState(state)) | |
} | |
componentDidMount() { | |
this.props.dispatcher.mount(this._updaterDefinition) | |
} | |
componentWillUnmount() { | |
this.props.dispatcher.unmount(this._updaterDefinition) | |
} | |
shouldComponentUpdate(nextProps, nextState) { | |
return this.state !== nextState | |
} | |
render() { | |
return this.markup(this.props, this.state) | |
} | |
markup = ({actions}, {currentTodo, isEditCurrentTodo, status}) => ( | |
<div class="page"> | |
<h1 class="page__header">Test page</h1> | |
<div class="page__status"> | |
Status: {status} | |
</div> | |
<TodoView todo={currentTodo} isEdit={isEditCurrentTodo} actions={actions}/> | |
<button class="page__button__add" onClick={actions.addTodo}>Add empty todo</button> | |
</div> | |
) | |
} |
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
@Annotate({ | |
props: { | |
actions: PageActions, | |
dispatcher: Dispatcher, | |
config: 'config.Page' | |
}, | |
state: { | |
status: 'PageStore.status', | |
currentTodo: 'PageStore.currentTodo', | |
isEditCurrentTodo: 'PageStore.isEditCurrentTodo' | |
} | |
}) | |
export default class Page extends React.Component { | |
constructor({props, state, updater}) { | |
super(props) | |
this.state = state | |
this._updaterDefinition = updater(state => this.setState(state)) | |
} | |
componentDidMount() { | |
this.props.dispatcher.mount(this._updaterDefinition) | |
} | |
componentWillUnmount() { | |
this.props.dispatcher.unmount(this._updaterDefinition) | |
} | |
shouldComponentUpdate(nextProps, nextState) { | |
return this.state !== nextState | |
} | |
render() { | |
return this.markup(this.props, this.state) | |
} | |
markup = ({actions}, {currentTodo, isEditCurrentTodo, status}) => ( | |
<div class="page"> | |
<h1 class="page__header">Test page</h1> | |
<div class="page__status"> | |
Status: {status} | |
</div> | |
<TodoView todo={currentTodo} isEdit={isEditCurrentTodo} actions={actions}/> | |
<button class="page__button__add" onClick={actions.addTodo}>Add empty todo</button> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment