suggestions:
..But only if there are good use cased :-D
+1
afterCreateInstance to setup reactions! :D
Proposal:
preprocessSnapshot(snapshot) => snapshot (called before applying a snapshot, both during create and later on)postprocessSnapshot(snapshot) => snapshot (called when creating a snapshot)didCreate() called after instantation, but not during reconcilationdidAttach() called when node gets attached to a tree (not called if attached before creation)willDetach() called before detaching from a treewillDestroy() called before a node is killedNaming convention before/after resonates better with me.
@mweststrate Maybe add a preprocess and postprocess for patches too?
Merged by #98 and released as 0.3.3.
Following lifecycle hooks are now available:
afterCreatebeforeDestroyafterAttachbeforeDetachMore lifecycle hooks should be demand / use case driven. E.g. processing snapshots.
Also introduced the convenience method addDisposer which is useful in afterCreate, avoid the need to setup a beforeDestroy just to fire disposers.
E.g.:
const Todo = types.model({
afterCreate() {
addDisposer(this, reaction(() => getSnapshot(this), s => submitSnapshotToServer(s)))
}
})
Most helpful comment
Naming convention before/after resonates better with me.