forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds why-did-you-update and example change. (mattermost#512)
- Loading branch information
Showing
5 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
|
||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
function is(x, y) { | ||
// SameValue algorithm | ||
if (x === y) { // Steps 1-5, 7-10 | ||
// Steps 6.b-6.e: +0 != -0 | ||
// Added the nonzero y check to make Flow happy, but it is redundant | ||
return x !== 0 || y !== 0 || 1 / x === 1 / y; | ||
} | ||
|
||
// Step 6.a: NaN == NaN | ||
return x !== x && y !== y; | ||
} | ||
|
||
function deepIs(x, y) { | ||
return JSON.stringify(x) === JSON.stringify(y); | ||
} | ||
|
||
/* | ||
* Adaptation of https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js | ||
* that allows specific keys to use a more expensive deep equality check. | ||
*/ | ||
function shallowEqualExceptKeys(objA, objB, deepKeys = []) { | ||
if (is(objA, objB)) { | ||
return true; | ||
} | ||
|
||
if (typeof objA !== 'object' || objA === null || | ||
typeof objB !== 'object' || objB === null) { | ||
return false; | ||
} | ||
|
||
const keysA = Object.keys(objA); | ||
const keysB = Object.keys(objB); | ||
|
||
if (keysA.length !== keysB.length) { | ||
return false; | ||
} | ||
|
||
// Test for A's keys different from B. | ||
for (let i = 0; i < keysA.length; i++) { | ||
if (!hasOwnProperty.call(objB, keysA[i])) { | ||
return false; | ||
} | ||
if (deepKeys.includes(keysA[i]) && !deepIs(objA[keysA[i]], objB[keysA[i]])) { | ||
return false; | ||
} | ||
if (!deepKeys.includes(keysA[i]) && !is(objA[keysA[i]], objB[keysA[i]])) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
module.exports = shallowEqualExceptKeys; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters