-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement basic lifecycle hooks #17
base: master
Are you sure you want to change the base?
Conversation
To properly implement class Parent extends Reduxable {
constructor() {
super({ child: new Child() }, { someReducer: x => x })
}
}
new Parent()
// will call the Child's `componentWillMount` before the Parent's one We should consider change the API moving the initial state creation to a method like
The same case would look like class Parent extends Reduxable {
getInitialState() {
return {
child: new Child()
}
}
static reducers = {
someReducer: x => x
}
} @jpgarcia @ignacioola I'd like to discuss with you this :) |
c743a9e
to
af34041
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Closes #14
This is the updated list of the already implemented lifecycle hooks:
API spec
It's important to well define the behavior for each one to avoid breaking the API in the future.
componentWillMount()
This hook receives no parameters and executes when the component will be mounted.
In this stage the state and reducers are not mounted yet, so no reducers can be called.
It should be called in the same order the Reduxables are instantiated: if we have a
Child
reduxable and aParent
reduxable who has aChild
instance in its state, then thecomponentWillMount()
will be called first for theParent
and the for theChild
.componentDidMount()
This hook receives no parameters and executes when the component is already mounted.
In this stage the state and reducers are already mounted, so any reducer can be called.
It should be called in the opposite direction than the
componentWillMount
: if we have aChild
reduxable and aParent
reduxable who has aChild
instance in its state, then thecomponentDidMount()
will be called first for theChild
and the for theParent
.actionWillDispatch(action)
This hook receives an
action
as parameter and executes immediately before that action dispatch.actionDidDispatch(action)
This hook receives an
action
as parameter and executes immediately after that action dispatch.stateWillChange(newState)
This hook receives the
newState
as parameter and executes immediately before setting thatnewState
.newState
is the state to be set or a copy.stateDidChange()
This hook receives no parameters and executes immediately after the state has changed.