Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steamerjs/pure-render-immutable-decorator
适配immutable的react pure-render-decorator
https://github.com/steamerjs/pure-render-immutable-decorator
Last synced: about 1 month ago
JSON representation
适配immutable的react pure-render-decorator
- Host: GitHub
- URL: https://github.com/steamerjs/pure-render-immutable-decorator
- Owner: steamerjs
- Created: 2017-02-09T09:08:29.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-10T09:20:46.000Z (almost 8 years ago)
- Last Synced: 2024-10-15T05:31:04.613Z (2 months ago)
- Language: JavaScript
- Size: 80.1 KB
- Stars: 6
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
## pure-render-immutable-decorator
compare props and state automatically
### Install
```
$ npm install pure-render-immutable-decorator --save
```### Usage
If you don't care the data in `shouldComponentUpdate`, you can just use the decorator way. But you have to install `babel-plugin-transform-decorators-legacy` plugin for compilation.
```js
import pureRender from "pure-render-immutable-decorator";@pureRender
class List extends Component {
constructor(props, context) {
super(props, context);
}render() {
return (
);
}
}```
If you need to modify logic in `shouldComponentUpdate`, you can use it like this:
```js
import { deepCompare } from "pure-render-immutable-decorator";class List extends Component {
constructor(props, context) {
super(props, context);
}shouldComponentUpdate(nextProps, nextState) {
// some logic
var shouldUpdate = /* some logic */
return deepCompare(this, nextProps, nextState) && shouldUpdate;
}
render() {
return (
);
}
}```
### Non-Immutable Version
* [pure-render-deepCompare-decorator](https://github.com/SteamerTeam/pure-render-deepCompare-decorator)