Skip to content

Commit

Permalink
Changes isStatics to be isIgnorable and overridable.
Browse files Browse the repository at this point in the history
First step in deprecating statics field as magic ignorable for public API.
  • Loading branch information
mikaelbr committed Jul 16, 2015
1 parent 254fb1d commit a28d595
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
20 changes: 18 additions & 2 deletions shouldupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var filter = require('lodash.pick'),
isEqual = require('lodash.isequal');

var isNotIgnorable = not(or(isStatics, isChildren));

/**
* Directly fetch `shouldComponentUpdate` mixin to use outside of Omniscient.
Expand Down Expand Up @@ -57,8 +56,11 @@ function factory (methods) {
_isEqualState = methods.isEqualState || isEqualState,
_isEqualProps = methods.isEqualProps || isEqualProps,
_isImmutable = methods.isImmutable || isImmutable,
_isIgnorable = methods.isIgnorable || isIgnorable,
_unCursor = methods.unCursor || unCursor;

var isNotIgnorable = not(or(_isIgnorable, isChildren));

shouldComponentUpdate.isCursor = _isCursor;
shouldComponentUpdate.isEqualState = _isEqualState;
shouldComponentUpdate.isEqualProps = _isEqualProps;
Expand Down Expand Up @@ -261,7 +263,21 @@ function not (fn) {
};
}

function isStatics (_, key) {
/**
* Predicate to check if a property on props should be ignored or not.
* For now this defaults to ignore if property key is `statics`, but that
* is deprecated behaviour, and will be removed by the next major release.
*
* Override through `shouldComponentUpdate.withDefaults`.
*
* @param {Object} value
* @param {String} key
*
* @module shouldComponentUpdate.isIgnorable
* @returns {Boolean}
* @api public
*/
function isIgnorable (_, key) {
return key === 'statics';
}

Expand Down
17 changes: 17 additions & 0 deletions tests/shouldComponentUpdate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,23 @@ describe('shouldComponentUpdate', function () {
done();
});

it('should have overridable isIgnorable', function () {
var numCalls = 0;
var local = shouldComponentUpdate.withDefaults({
isIgnorable: function foobar (value, key) {
numCalls++;
return key === 'ignore';
}
});

shouldNotUpdate({
cursor: { ignore: 'hello' },
nextCursor: { ignore: 'bye' }
}, local);

numCalls.should.be.above(1);
});

it('should have debug on product of withDefaults', function () {
var localComponent = shouldComponentUpdate.withDefaults({
isCursor: function () { }
Expand Down

0 comments on commit a28d595

Please sign in to comment.