Add some jsdoc
This commit is contained in:
parent
fe1d881412
commit
dea78333ff
@ -1,6 +1,40 @@
|
||||
import freeze from './freeze';
|
||||
|
||||
export default function constant(object) {
|
||||
const frozen = freeze(object);
|
||||
/**
|
||||
* Returns a function that always returns the supplied value.
|
||||
*
|
||||
* Useful for replacing an object outright rather than merging it.
|
||||
*
|
||||
* @function
|
||||
* @sig a -> (* -> a)
|
||||
* @memberOf u
|
||||
* @param {*} value what to return from returned function.
|
||||
* @return {function} a new function that will always return value.
|
||||
*
|
||||
* @example
|
||||
* var alwaysFour = u.constant(4);
|
||||
* expect(alwaysFour(32)).toEqual(4);
|
||||
*
|
||||
* @example
|
||||
* var user = {
|
||||
* name: 'Mitch',
|
||||
* favorites: {
|
||||
* band: 'Nirvana',
|
||||
* movie: 'The Matrix'
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* var newFavorites = {
|
||||
* band: 'Coldplay'
|
||||
* };
|
||||
*
|
||||
* var result = u({ favorites: u.constant(newFavorites) }, user);
|
||||
*
|
||||
* expect(result).toEqual({ name: 'Mitch', favorites: { band: 'Coldplay' } });
|
||||
*/
|
||||
function constant(value) {
|
||||
const frozen = freeze(value);
|
||||
return () => frozen;
|
||||
}
|
||||
|
||||
export default constant;
|
||||
|
@ -22,7 +22,18 @@ function recur(object) {
|
||||
return object;
|
||||
}
|
||||
|
||||
export default function freeze(object) {
|
||||
/**
|
||||
* Deeply freeze a plain javascript object.
|
||||
*
|
||||
* If `process.env.NODE_ENV === 'production'`, this returns the original object
|
||||
* witout freezing.
|
||||
*
|
||||
* @function
|
||||
* @sig a -> a
|
||||
* @param {object} object Object to freeze.
|
||||
* @return {object} Frozen object, unless in production, then the same object.
|
||||
*/
|
||||
function freeze(object) {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
return object;
|
||||
}
|
||||
@ -33,3 +44,5 @@ export default function freeze(object) {
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
export default freeze;
|
||||
|
@ -49,6 +49,8 @@ function updateArray(updates, object) {
|
||||
* update({ foo: x => (x + 1) }, { foo: 2 });
|
||||
* // => { foo: 3 }
|
||||
*
|
||||
* @function
|
||||
* @name update
|
||||
* @param {Object|Function} updates
|
||||
* @param {Object|Array} object to update
|
||||
* @return {Object|Array} new object with modifications
|
||||
|
Loading…
Reference in New Issue
Block a user