Skip to content

Commit

Permalink
Adds valueFn as a Config method (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hadley authored and eduardolundgren committed Apr 14, 2017
1 parent 497d8cd commit 91bb1f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/metal-state/src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ const Config = {
return mergeConfig(this, {
value
});
},

/**
* Adds a valueFn that will return a default value for the `State` configuration.
* @param {!function()} valueFn
* @return {!Object} `State` configuration object.
*/
valueFn(valueFn) {
return mergeConfig(this, {
valueFn
});
}
};

Expand Down
9 changes: 9 additions & 0 deletions packages/metal-state/test/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ describe('Config', function() {
}, config.config);
});

it('should return config with specified "valueFn"', function() {
var valueFn = () => {};
var config = Config.valueFn(valueFn);
assert.ok(core.isObject(config));
assert.deepEqual({
valueFn
}, config.config);
});

it('should return config with specified "setter"', function() {
var setter = () => {
};
Expand Down

0 comments on commit 91bb1f2

Please sign in to comment.