react-addons-shallow-compare
Advanced tools
Comparing version 15.5.2 to 15.6.0-rc.1
29
index.js
@@ -1,28 +0,1 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule shallowCompare | ||
*/ | ||
'use strict'; | ||
var shallowEqual = require('fbjs/lib/shallowEqual'); | ||
/** | ||
* Does a shallow comparison for props and state. | ||
* See ReactComponentWithPureRenderMixin | ||
* See also https://facebook.github.io/react/docs/shallow-compare.html | ||
*/ | ||
function shallowCompare(instance, nextProps, nextState) { | ||
return ( | ||
!shallowEqual(instance.props, nextProps) || | ||
!shallowEqual(instance.state, nextState) | ||
); | ||
} | ||
module.exports = shallowCompare; | ||
module.exports = require('react/lib/shallowCompare'); |
{ | ||
"name": "react-addons-shallow-compare", | ||
"version": "15.5.2", | ||
"version": "15.6.0-rc.1", | ||
"main": "index.js", | ||
@@ -12,5 +12,8 @@ "repository": "facebook/react", | ||
"dependencies": { | ||
"fbjs": "^0.8.4", | ||
"fbjs": "^0.8.9", | ||
"object-assign": "^4.1.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^15.6.0-rc.1" | ||
}, | ||
"files": [ | ||
@@ -20,15 +23,4 @@ "LICENSE", | ||
"README.md", | ||
"index.js", | ||
"react-addons-shallow-compare.js", | ||
"react-addons-shallow-compare.min.js" | ||
], | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"devDependencies": { | ||
"jest": "^19.0.2", | ||
"react": "^15.4.2", | ||
"react-addons-test-utils": "^15.4.2", | ||
"react-dom": "^15.4.2" | ||
} | ||
} | ||
"index.js" | ||
] | ||
} |
# react-addons-shallow-compare | ||
>**Note:** | ||
>This is a legacy React addon, and is no longer maintained. | ||
> | ||
>We don't encourage using it in new code, but it exists for backwards compatibility. | ||
>The recommended migration path is to use [`React.PureComponent`](https://facebook.github.io/react/docs/react-api.html#react.purecomponent) instead. | ||
This package provides the React shallowCompare add-on. | ||
**Importing** | ||
```javascript | ||
import shallowCompare from 'react-addons-shallow-compare'; // ES6 | ||
var shallowCompare = require('react-addons-shallow-compare'); // ES5 with npm | ||
``` | ||
If you prefer a `<script>` tag, you can get it from `React.addons.shallowCompare` with: | ||
```html | ||
<!-- development version --> | ||
<script src="https://unpkg.com/react-addons-shallow-compare/react-addons-shallow-compare.js"></script> | ||
<!-- production version --> | ||
<script src="https://unpkg.com/react-addons-shallow-compare/react-addons-shallow-compare.min.js"></script> | ||
``` | ||
In this case, make sure to put the `<script>` tag after React. | ||
## Overview | ||
Before [`React.PureComponent`](https://facebook.github.io/react/docs/react-api.html#react.purecomponent) was introduced, `shallowCompare` was commonly used to achieve the same functionality as [`PureRenderMixin`](https://www.npmjs.com/package/react-addons-pure-render-mixin) while using ES6 classes with React. | ||
If your React component's render function is "pure" (in other words, it renders the same result given the same props and state), you can use this helper function for a performance boost in some cases. | ||
Example: | ||
```js | ||
export class SampleComponent extends React.Component { | ||
shouldComponentUpdate(nextProps, nextState) { | ||
return shallowCompare(this, nextProps, nextState); | ||
} | ||
render() { | ||
return <div className={this.props.className}>foo</div>; | ||
} | ||
} | ||
``` | ||
`shallowCompare` performs a shallow equality check on the current `props` and `nextProps` objects as well as the current `state` and `nextState` objects. | ||
It does this by iterating on the keys of the objects being compared and returning true when the values of a key in each object are not strictly equal. | ||
`shallowCompare` returns `true` if the shallow comparison for props or state fails and therefore the component should update. | ||
`shallowCompare` returns `false` if the shallow comparison for props and state both pass and therefore the component does not need to update. | ||
See <https://facebook.github.io/react/docs/shallow-compare.html> for more information. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
1
4150
3
5
0
5
2
+ Addedcreate-react-class@15.7.0(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedreact@15.7.0(transitive)
+ Addedreact-is@16.13.1(transitive)
Updatedfbjs@^0.8.9