Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #11 from hvolschenk/fix/update-dependencies
Browse files Browse the repository at this point in the history
Fix/update dependencies
  • Loading branch information
hvolschenk committed Mar 15, 2020
2 parents 2174ef2 + 9bf079d commit 78fc748
Show file tree
Hide file tree
Showing 7 changed files with 5,188 additions and 3,729 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ cache:
notifications:
email: false
node_js:
- '10'
- '12'
after_success:
- npm run build
- npm run travis-deploy-once "npm run semantic-release"
- npx semantic-release
- npm run coveralls
branches:
except:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM node:dubnium-alpine
FROM node:erbium-alpine

ENV HOME /home/node/app

WORKDIR $HOME

VOLUME [$HOME]

RUN chown -Rv node:node $HOME
RUN chown -R node:node $HOME
USER node
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,16 @@ information:

#### Mounting:

* `componentWillMount()`

* `UNSAFE_componentDidMount()` or `componentDidMount()`
* `componentDidMount()`

#### Updating

* `UNSAFE_componentWillReceiveProps(nextProps)` or `componentWillReceiveProps(nextProps)`

* `shouldComponentUpdate(nextProps, nextState)`

This method should return a boolean value. If no value (or a non-booean value) is returned,
**Lifecycler** will return `true` for you. Because these are still stateless components,
`nextState` will always be `null`.

* `UNSAFE_componentWillUpdate(nextProps, nextState)` or `componentWillUpdate(nextProps, nextState)`

Because these are still stateless components, `nextState` will always be `null`.

* `componentDidUpdate(prevProps, prevState)`

Because these are still stateless components, `nextState` will always be `null`.
Expand Down
8,656 changes: 5,131 additions & 3,525 deletions package-lock.json

Large diffs are not rendered by default.

69 changes: 34 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,43 @@
"lodash.isboolean": "^3.0.3",
"lodash.isfunction": "^3.0.9",
"prop-types": "^15.7.2",
"react": "^16.9.0"
"react": "^16.13.0"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-proposal-do-expressions": "^7.5.0",
"@babel/plugin-proposal-export-default-from": "^7.5.2",
"@babel/plugin-proposal-export-namespace-from": "^7.5.2",
"@babel/plugin-proposal-function-bind": "^7.2.0",
"@babel/plugin-proposal-function-sent": "^7.5.0",
"@babel/plugin-proposal-json-strings": "^7.2.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
"@babel/plugin-proposal-numeric-separator": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
"@babel/plugin-proposal-pipeline-operator": "^7.5.0",
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-import-meta": "^7.2.0",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-proposal-do-expressions": "^7.8.3",
"@babel/plugin-proposal-export-default-from": "^7.8.3",
"@babel/plugin-proposal-export-namespace-from": "^7.8.3",
"@babel/plugin-proposal-function-bind": "^7.8.3",
"@babel/plugin-proposal-function-sent": "^7.8.3",
"@babel/plugin-proposal-json-strings": "^7.8.3",
"@babel/plugin-proposal-logical-assignment-operators": "^7.8.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-proposal-numeric-separator": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
"@babel/plugin-proposal-pipeline-operator": "^7.8.3",
"@babel/plugin-proposal-throw-expressions": "^7.8.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.8.3",
"@babel/preset-env": "^7.8.7",
"@babel/preset-react": "^7.8.3",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.2",
"babel-jest": "^24.8.0",
"coveralls": "^3.0.6",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^18.0.0",
"eslint-plugin-import": "^2.18.2",
"babel-eslint": "^10.1.0",
"babel-jest": "^25.1.0",
"coveralls": "^3.0.9",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.2",
"jest": "^24.8.0",
"react-dom": "^16.9.0",
"semantic-release": "^15.13.19",
"travis-deploy-once": "^5.0.11"
"eslint-plugin-react": "^7.19.0",
"jest": "^25.1.0",
"react-dom": "^16.13.0",
"semantic-release": "^17.0.4"
}
}
24 changes: 0 additions & 24 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,13 @@ const applyLifecycleMethod = (method) => (...parameters) => {
};

class Lifecycler extends React.Component {
UNSAFE_componentWillMount() {
const { componentWillMount, UNSAFE_componentWillMount } = this.props;
applyLifecycleMethod(UNSAFE_componentWillMount || componentWillMount)();
}
componentDidMount() {
applyLifecycleMethod(this.props.componentDidMount)();
}
UNSAFE_componentWillReceiveProps(nextProps) {
const { componentWillReceiveProps, UNSAFE_componentWillReceiveProps } = this.props;
applyLifecycleMethod(UNSAFE_componentWillReceiveProps || componentWillReceiveProps)(nextProps);
}
shouldComponentUpdate(nextProps, nextState) {
const should = applyLifecycleMethod(this.props.shouldComponentUpdate)(nextProps, nextState);
return isBoolean(should) ? should : true;
}
UNSAFE_componentWillUpdate(nextProps, nextState) {
const { componentWillUpdate, UNSAFE_componentWillUpdate } = this.props;
applyLifecycleMethod(UNSAFE_componentWillUpdate || componentWillUpdate)(nextProps, nextState);
}
componentDidUpdate(previousProps, previousState) {
applyLifecycleMethod(this.props.componentDidUpdate)(previousProps, previousState);
}
Expand All @@ -45,27 +33,15 @@ Lifecycler.propTypes = {
children: PropTypes.node.isRequired,
componentDidMount: PropTypes.func,
componentDidUpdate: PropTypes.func,
componentWillMount: PropTypes.func,
componentWillReceiveProps: PropTypes.func,
componentWillUnmount: PropTypes.func,
componentWillUpdate: PropTypes.func,
shouldComponentUpdate: PropTypes.func,
UNSAFE_componentWillMount: PropTypes.func,
UNSAFE_componentWillReceiveProps: PropTypes.func,
UNSAFE_componentWillUpdate: PropTypes.func,
};

Lifecycler.defaultProps = {
componentDidMount: undefined,
componentDidUpdate: undefined,
componentWillMount: undefined,
componentWillReceiveProps: undefined,
componentWillUnmount: undefined,
componentWillUpdate: undefined,
shouldComponentUpdate: undefined,
UNSAFE_componentWillMount: undefined,
UNSAFE_componentWillReceiveProps: undefined,
UNSAFE_componentWillUpdate: undefined,
};

export default Lifecycler;
150 changes: 18 additions & 132 deletions src/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,12 @@ describe('Rendering', () => {
});

describe('Mounting', () => {
describe('With explicitly unsafe lifecycle methods', () => {
const componentDidMount = jest.fn();
const componentWillMount = jest.fn();
const UNSAFE_componentWillMount = jest.fn();

beforeAll(() => {
shallow(
<Lifecycler
componentDidMount={componentDidMount}
componentWillMount={componentWillMount}
UNSAFE_componentWillMount={UNSAFE_componentWillMount}
>
<Children />
</Lifecycler>,
);
});

test('Calls \'componentDidMount\'', () => {
expect(componentDidMount.mock.calls.length).toBe(1);
});

test('Calls \'UNSAFE_componentWillMount\'', () => {
expect(UNSAFE_componentWillMount.mock.calls.length).toBe(1);
});

test('Does not call \'componentWillMount\'', () => {
expect(componentWillMount.mock.calls.length).toBe(0);
});
});

describe('With old unsafe lifecycle methods', () => {
const componentDidMount = jest.fn();
const componentWillMount = jest.fn();

beforeAll(() => {
shallow(
<Lifecycler
componentDidMount={componentDidMount}
componentWillMount={componentWillMount}
>
<Lifecycler componentDidMount={componentDidMount}>
<Children />
</Lifecycler>,
);
Expand All @@ -69,103 +35,6 @@ describe('Mounting', () => {
test('Calls \'componentDidMount\'', () => {
expect(componentDidMount.mock.calls.length).toBe(1);
});

test('Calls \'componentWillMount\'', () => {
expect(componentWillMount.mock.calls.length).toBe(1);
});
});
});

describe('Updating', () => {
describe('With explicitly unsafe lifecycle methods', () => {
const componentDidUpdate = jest.fn();
const componentWillReceiveProps = jest.fn();
const componentWillUpdate = jest.fn();
const shouldComponentUpdate = jest.fn();
const UNSAFE_componentWillReceiveProps = jest.fn();
const UNSAFE_componentWillUpdate = jest.fn();
const nextProps = { next: 'props' };

let instanceProps;

beforeAll(() => {
const wrapper = shallow(
<Lifecycler
componentDidUpdate={componentDidUpdate}
componentWillReceiveProps={componentWillReceiveProps}
componentWillUpdate={componentWillUpdate}
shouldComponentUpdate={shouldComponentUpdate}
UNSAFE_componentWillReceiveProps={UNSAFE_componentWillReceiveProps}
UNSAFE_componentWillUpdate={UNSAFE_componentWillUpdate}
>
<Children />
</Lifecycler>,
);
instanceProps = wrapper.instance().props;
wrapper.setProps(nextProps);
});

test('Calls \'UNSAFE_componentWillReceiveProps\'', () => {
expect(UNSAFE_componentWillReceiveProps.mock.calls[0][0])
.toEqual({ ...instanceProps, ...nextProps });
});

test('Does not call \'componentWillReceiveProps\'', () => {
expect(componentWillReceiveProps.mock.calls.length).toBe(0);
});

test('Calls \'shouldComponentUpdate\'', () => {
expect(shouldComponentUpdate.mock.calls[0])
.toEqual([{ ...instanceProps, ...nextProps }, {}]);
});

test('Calls \'UNSAFE_componentWillUpdate\'', () => {
expect(UNSAFE_componentWillUpdate.mock.calls[0])
.toEqual([{ ...instanceProps, ...nextProps }, {}]);
});

test('Does not call \'componentWillUpdate\'', () => {
expect(componentWillUpdate.mock.calls.length).toBe(0);
});

test('Calls \'componentDidUpdate\'', () => {
expect(componentDidUpdate.mock.calls[0]).toEqual([instanceProps, null]);
});
});

describe('With old unsafe lifecycle methods', () => {
const componentDidUpdate = jest.fn();
const componentWillReceiveProps = jest.fn();
const componentWillUpdate = jest.fn();
const shouldComponentUpdate = jest.fn();
const nextProps = { next: 'props' };

let instanceProps;

beforeAll(() => {
const wrapper = shallow(
<Lifecycler
componentDidUpdate={componentDidUpdate}
componentWillReceiveProps={componentWillReceiveProps}
componentWillUpdate={componentWillUpdate}
shouldComponentUpdate={shouldComponentUpdate}
>
<Children />
</Lifecycler>,
);
instanceProps = wrapper.instance().props;
wrapper.setProps(nextProps);
});

test('Calls \'componentWillReceiveProps\'', () => {
expect(componentWillReceiveProps.mock.calls[0])
.toEqual([{ ...instanceProps, ...nextProps }]);
});

test('Calls \'componentWillUpdate\'', () => {
expect(componentWillUpdate.mock.calls[0])
.toEqual([{ ...instanceProps, ...nextProps }, {}]);
});
});
});

Expand Down Expand Up @@ -208,6 +77,23 @@ describe('Returns the value for \'shouldComponentUpdate\' if it is a boolean', (
});
});

describe('Updating', () => {
const componentDidUpdate = jest.fn();

beforeAll(() => {
const wrapper = mount(
<Lifecycler componentDidUpdate={componentDidUpdate}>
<Children />
</Lifecycler>,
);
wrapper.setProps({});
});

test('Calls \'componentDidUpdate\'', () => {
expect(componentDidUpdate.mock.calls.length).toBe(1);
});
});

describe('Unmounting', () => {
const componentWillUnmount = jest.fn();

Expand Down

0 comments on commit 78fc748

Please sign in to comment.