Skip to content

Commit

Permalink
Merge pull request #9 from hjvvoorthuijsen/Callback-function-in-setState
Browse files Browse the repository at this point in the history
Callback function in set state
  • Loading branch information
antoinejaussoin authored Jun 17, 2020
2 parents 9f03f37 + b48883b commit e71fa50
Show file tree
Hide file tree
Showing 6 changed files with 14,280 additions and 6 deletions.
9 changes: 9 additions & 0 deletions Jooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,16 @@ var Jooks = /** @class */ (function () {
Jooks.prototype.mockUseState = function (defaultValue) {
var _this = this;
var localPointer = this.stateStore.pointer;
var isFunction = function (arg) { return typeof arg === 'function'; };
var setState = function (v) {
if (isFunction(v)) {
var newState = v(_this.stateStore.store[localPointer]);
if (_this.verbose) {
console.log('Set state to ', newState, ' pointer ', localPointer);
}
_this.stateStore.store[localPointer] = newState;
return;
}
if (_this.verbose) {
console.log('Set state to ', v, ' pointer ', localPointer);
}
Expand Down
Loading

0 comments on commit e71fa50

Please sign in to comment.