Skip to content

Instantly share code, notes, and snippets.

@zerkalica
Created March 24, 2015 14:08
Show Gist options
  • Save zerkalica/5eb3e8a5ce6d6ed7e385 to your computer and use it in GitHub Desktop.
Save zerkalica/5eb3e8a5ce6d6ed7e385 to your computer and use it in GitHub Desktop.
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>
)
}
@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