Skip to content

Commit 7af609d

Browse files
Merge branch 'release/1.0.0'
2 parents ca24f86 + f3b7747 commit 7af609d

11 files changed

+894
-101
lines changed

Diff for: .babelrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"plugins": ["transform-object-rest-spread"],
23
"presets": ["es2015", "react"]
34
}

Diff for: .editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ end_of_line = lf
99
insert_final_newline = true
1010
indent_style = tab
1111

12-
[package.json]
12+
[{.babelrc,package.json}]
1313
indent_style = space
1414
indent_size = 2

Diff for: .eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/coverage/*
2+
/lib/*

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Drew Keller
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# react-component-update
2+
3+
[![Build Status](https://travis-ci.org/wimpyprogrammer/react-component-update.svg?branch=master)](https://travis-ci.org/wimpyprogrammer/react-component-update)
4+
[![codecov](https://codecov.io/gh/wimpyprogrammer/react-component-update/branch/master/graph/badge.svg)](https://codecov.io/gh/wimpyprogrammer/react-component-update)
5+
6+
Adds convenience lifecycle events to your React components.
7+
8+
- `componentWillMountOrReceiveProps(nextProps)` - Combines the [`componentWillMount()`](https://facebook.github.io/react/docs/react-component.html#componentwillmount) and [`componentWillReceiveProps(nextProps)`](https://facebook.github.io/react/docs/react-component.html#componentwillreceiveprops) events. This allows you to consolidate all pre-`render()` logic.
9+
10+
- `componentDidMountOrUpdate(prevProps, prevState)` - Combines the [`componentDidMount()`](https://facebook.github.io/react/docs/react-component.html#componentdidmount) and [`componentDidUpdate(prevProps, prevState)`](https://facebook.github.io/react/docs/react-component.html#componentdidupdate) events. This allows you to consolidate all post-`render()` logic.
11+
12+
## Installation
13+
14+
Published on `npm` as [`react-component-update`](https://www.npmjs.com/package/react-component-update).
15+
16+
npm users:
17+
```
18+
npm install --save react-component-update
19+
```
20+
21+
yarn users:
22+
```
23+
yarn add react-component-update
24+
```
25+
26+
`react-component-update` does not include its own version of React. It will use whatever version is already installed in your project.
27+
28+
## Usage
29+
30+
To extend React's `Component` class:
31+
32+
```js
33+
import React from 'react';
34+
import { Component } from 'react-component-update';
35+
36+
class MyReactComponent extends Component {
37+
componentWillMountOrReceiveProps(nextProps) {
38+
// Code that runs before every render(). For example, check that the data
39+
// used by this component has already loaded, otherwise trigger an AJAX
40+
// request for it. nextProps contains the props that render() will receive.
41+
}
42+
43+
componentDidMountOrUpdate(prevProps, prevState) {
44+
// Code that runs after every render(). For example, inspect the latest DOM
45+
// to get the height of the rendered elements. prevProps and prevState
46+
// contain the props and state that render() will receive.
47+
}
48+
49+
render() {
50+
return <div />;
51+
}
52+
}
53+
```
54+
55+
Or to extend React's `PureComponent` class (available in React v15.3.0+):
56+
```js
57+
import { PureComponent } from 'react-component-update';
58+
```
59+
60+
For compatibility with [`create-react-class`](https://www.npmjs.com/package/create-react-class), use the `withEvents()` higher-order component.
61+
62+
```js
63+
import createReactClass from 'create-react-class';
64+
import { withEvents } from 'react-component-update';
65+
66+
const MyReactComponent = createReactClass(withEvents({
67+
componentWillMountOrReceiveProps: function(nextProps) {
68+
// Code that runs before every render().
69+
},
70+
71+
componentDidMountOrUpdate: function(prevProps, prevState) {
72+
// Code that runs after every render().
73+
},
74+
75+
render: function() {
76+
return <div />;
77+
}
78+
}));
79+
```
80+
81+
## Mixing with your own lifecycle events
82+
83+
`react-component-update` implements four lifecycle events of the React base classes:
84+
- `componentWillMount()`
85+
- `componentDidMount()`
86+
- `componentWillReceiveProps()`
87+
- `componentDidUpdate()`
88+
89+
If you extend `Component` or `PureComponent` from `react-component-update` and you also implement these events in your component, you will need to call the corresponding `super()` method like so:
90+
91+
```js
92+
componentWillMount() {
93+
super.componentWillMount();
94+
}
95+
96+
componentDidMount() {
97+
super.componentDidMount();
98+
}
99+
100+
componentWillReceiveProps(nextProps) {
101+
super.componentWillReceiveProps(nextProps);
102+
}
103+
104+
componentDidUpdate(prevProps, prevState) {
105+
super.componentDidUpdate(prevProps, prevState);
106+
}
107+
```
108+
109+
The `super()` method can be called anywhere in your function to suit your needs.
110+
111+
If you use the `withEvents()` higher-order component, you do not need to add any extra code to your events. The new event (ex. `componentDidMountOrUpdate()`) will always run after the related built-in event (ex. `componentDidUpdate()`).
112+
113+
## License
114+
115+
[MIT](/LICENSE.md)

Diff for: package.json

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-component-update",
3-
"version": "1.0.0-alpha",
3+
"version": "1.0.0",
44
"description": "Extends the native React Component to streamline updates",
55
"main": "lib/index.js",
66
"scripts": {
@@ -17,18 +17,20 @@
1717
"url": "git+https://github.com/wimpyprogrammer/react-component-update.git"
1818
},
1919
"author": "Drew Keller <drew@wimpyprogrammer.com>",
20-
"license": "ISC",
20+
"license": "MIT",
2121
"bugs": {
2222
"url": "https://github.com/wimpyprogrammer/react-component-update/issues"
2323
},
2424
"homepage": "https://github.com/wimpyprogrammer/react-component-update#readme",
2525
"devDependencies": {
2626
"babel-cli": "^6.26.0",
2727
"babel-jest": "^20.0.3",
28+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
2829
"babel-preset-es2015": "^6.24.1",
2930
"babel-preset-react": "^6.24.1",
3031
"chai": "^4.0.2",
3132
"codecov": "^2.3.0",
33+
"create-react-class": "^15.6.0",
3234
"dirty-chai": "^2.0.0",
3335
"enzyme": "^2.8.2",
3436
"eslint": "^3.19.0",
@@ -44,13 +46,20 @@
4446
"react-dom": "*",
4547
"react-test-renderer": "*",
4648
"rimraf": "^2.6.1",
47-
"sinon": "^2.3.4"
49+
"sinon": "^3.2.1",
50+
"sinon-chai": "^2.13.0"
4851
},
4952
"peerDependencies": {
5053
"react": "*"
5154
},
5255
"jest": {
5356
"coverageDirectory": "./coverage/",
54-
"collectCoverage": true
57+
"collectCoverage": true,
58+
"testMatch": [
59+
"**/src/*.spec.js?(x)"
60+
]
61+
},
62+
"dependencies": {
63+
"lodash.wrap": "^4.1.1"
5564
}
5665
}

0 commit comments

Comments
 (0)