{"_id":"shallow-element-equals","_rev":"2798153","name":"shallow-element-equals","description":"Efficient shallow equality algorithm that also allows checks for react element equality of children props","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"intelligibabble","email":""}],"time":{"modified":"2022-07-18T11:45:17.000Z","created":"2016-10-04T17:18:59.198Z","1.0.1":"2016-10-16T22:18:18.608Z","1.0.0":"2016-10-04T17:18:59.198Z"},"users":{},"author":{"name":"Leland Richardson","email":"leland.m.richardson@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/lelandrichardson/shallow-element-equals.git"},"versions":{"1.0.1":{"name":"shallow-element-equals","version":"1.0.1","description":"Efficient shallow equality algorithm that also allows checks for react element equality of children props","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/lelandrichardson/shallow-element-equals.git"},"keywords":["react","react-native","shouldComponentUpdate","shallowCompare","react-addons","performance","shallow-equal"],"author":{"name":"Leland Richardson","email":"leland.m.richardson@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/lelandrichardson/shallow-element-equals/issues"},"homepage":"https://github.com/lelandrichardson/shallow-element-equals#readme","dependencies":{"style-equal":"^1.0.0"},"devDependencies":{"babel-core":"^6.17.0","babel-preset-airbnb":"^2.1.1","chai":"^3.5.0","mocha":"^3.1.0","react":"^15.3.2"},"gitHead":"0657c032ca6ea41fd923c8c5ae48c2ee04c82788","_id":"shallow-element-equals@1.0.1","_shasum":"50739b7d94ad7567a134173d3f4422387ed57ce6","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"intelligibabble","email":"leland.m.richardson@gmail.com"},"dist":{"shasum":"50739b7d94ad7567a134173d3f4422387ed57ce6","size":3441,"noattachment":false,"key":"/shallow-element-equals/-/shallow-element-equals-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/shallow-element-equals/download/shallow-element-equals-1.0.1.tgz"},"maintainers":[{"name":"intelligibabble","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/shallow-element-equals-1.0.1.tgz_1476656298352_0.18079056381247938"},"directories":{},"publish_time":1476656298608,"_hasShrinkwrap":false,"_cnpm_publish_time":1476656298608,"_cnpmcore_publish_time":"2021-12-17T03:51:13.299Z"},"1.0.0":{"name":"shallow-element-equals","version":"1.0.0","description":"Efficient shallow equality algorithm that also allows checks for react element equality of children props","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/lelandrichardson/shallow-element-equals.git"},"keywords":["react","react-native","shouldComponentUpdate","shallowCompare","react-addons","performance","shallow-equal"],"author":{"name":"Leland Richardson","email":"leland.m.richardson@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/lelandrichardson/shallow-element-equals/issues"},"homepage":"https://github.com/lelandrichardson/shallow-element-equals#readme","dependencies":{"style-equal":"^1.0.0"},"devDependencies":{"babel-core":"^6.17.0","babel-preset-airbnb":"^2.1.1","chai":"^3.5.0","mocha":"^3.1.0","react":"^15.3.2"},"gitHead":"54cbf63be80b9479d9b7938813ec89f0b6951061","_id":"shallow-element-equals@1.0.0","_shasum":"5bf5029440f02475f670a2d2da2302b13b02bde9","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"intelligibabble","email":"leland.m.richardson@gmail.com"},"dist":{"shasum":"5bf5029440f02475f670a2d2da2302b13b02bde9","size":3428,"noattachment":false,"key":"/shallow-element-equals/-/shallow-element-equals-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/shallow-element-equals/download/shallow-element-equals-1.0.0.tgz"},"maintainers":[{"name":"intelligibabble","email":""}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/shallow-element-equals-1.0.0.tgz_1475601536023_0.09400129155255854"},"directories":{},"publish_time":1475601539198,"_hasShrinkwrap":false,"_cnpm_publish_time":1475601539198,"_cnpmcore_publish_time":"2021-12-17T03:51:13.545Z"}},"readme":"# shallow-element-equals\n\nEfficient shallow equality algorithm that also allows checks for react element equality of children props\n\n## Why\n\n`shouldComponentUpdate` is a powerful way to improve performance of react and react native applications,\nbut often you have components which you can expect to be \"pure\", but you also want them to have an API\nthat accepts children.\n\nHaving a `children` prop pretty much removes any chance of using a \"shallow\" equality comparison of props,\nsince `React.createElement` will return a new object reference on every call, so JSX elements are always\nnew object references.\n\n`shallowElementEquals` takes this into account, and treats `children` props in a special way such that it will\nassume that all of the children elements provided to a component are \"pure\" as well, and just the props/types\ncould be compared for an optimized comparison.\n\n## Be careful using this\n\nThis is dangerous. Don't use this function if you don't understand its consequences.  By having a component adopt\na `shouldComponentUpdate` method like this, you are assuming something about the components that people are \npassing into your component as children that may not be true (ie, that they are pure). If this is not true,\nthe consumers of your component may have their application behave in ways that they do not expect, and the\nreason will be completely opaque to them.\n\nI would probably not recommend using this type of an optimization on public code or open source projects where\nlots of people will be using it without understanding these assumptions.\n\n\n## Installation\n\n```bash\nnpm i shallow-element-equals --save\n```\n\n\n## Usage\n\n```js\nimport shallowElementEquals from 'shallow-element-equals';\n\n// ...\n\nshouldComponentUpdate(nextProps) {\n  return !shallowElementEquals(this.props, nextProps);\n}\n```\n\n\n## Examples of how this works\n\nSee the [tests](test/shallowElementEquals-test.js) to understand better what this will match on.\n","_attachments":{},"homepage":"https://github.com/lelandrichardson/shallow-element-equals#readme","bugs":{"url":"https://github.com/lelandrichardson/shallow-element-equals/issues"},"license":"MIT"}