Skip to content

Commit

Permalink
feat: as a dev I want to be able to use setState callback in the comp…
Browse files Browse the repository at this point in the history
…onentConstruction
  • Loading branch information
demetriusj committed Apr 8, 2015
1 parent d357a27 commit ba0304f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/isomorphic/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,21 @@ pipeline.prototype.setProps = function(obj) {
utils.objectUnion([mergeObj], this.props, {deleteUndefined:true});
};

pipeline.prototype.setState = function(obj) {
pipeline.prototype.setState = function(obj, cb) {
if(typeof obj !== 'object') {
throw new Error('Cannot merge non objects to context state')
}
} /*
TODO: need to support the fn(previousState, currentProps) version
need to update Unit test and make sure the namescpae is mantained
else if(typeof obj !== 'function') {
obj = obj(this.props.__initState, this.props)
}*/

var mergeObj = this.buildMergeObjFromNamespace({__initState:obj});
utils.objectUnion([mergeObj], this.props, {deleteUndefined:true});
if(typeof cb === 'function') {
cb();
}
};

/**
Expand Down

0 comments on commit ba0304f

Please sign in to comment.