You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @providesModule shallowEqual * @typechecks * @flow *//*eslint-disable no-self-compare */'use strict';consthasOwnProperty=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 */functionis(x: mixed,y: mixed): boolean{// SameValue algorithmif(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 redundantreturnx!==0||y!==0||1/x===1/y;}else{// Step 6.a: NaN == NaNreturnx!==x&&y!==y;}}/** * Performs equality by iterating through keys on an object and returning false * when any key has values which are not strictly equal between the arguments. * Returns true when the values of all keys are strictly equal. */functionshallowEqual(objA: mixed,objB: mixed): boolean{if(is(objA,objB)){returntrue;}if(typeofobjA!=='object'||objA===null||typeofobjB!=='object'||objB===null){returnfalse;}constkeysA=Object.keys(objA);constkeysB=Object.keys(objB);if(keysA.length!==keysB.length){returnfalse;}// Test for A's keys different from B.for(leti=0;i<keysA.length;i++){if(!hasOwnProperty.call(objB,keysA[i])||!is(objA[keysA[i]],objB[keysA[i]])){returnfalse;}}returntrue;}module.exports=shallowEqual;
The text was updated successfully, but these errors were encountered:
React 中的 diff 算法,以及优化相关内容
一图胜千言啊
shouldComponentUpdate 相关
除了 diff 算法,我们可以谈谈具体的 compare 是如何比较的
shouldComponentUpdate
浅对比
React.PureComponent
React.PureComponent
-->React.Component
React.memo
props
export default React.memo (Component);
fbjs 源码
什么是 fbjs ,这有 2 段说明
shoullowEqual
代码阅读说明:function is()
目的是相当于===
,基础类型直接比较结果,同时兼容判断 +0 和 -0 ,以及 NaN 和 NaNfunction shallowEqual()
分了几步function is()
function is()
下面是 Facebook 的
shoullowEqual
的源代码,GitHub 链接The text was updated successfully, but these errors were encountered: