Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions demo/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import strict from './strict';
import reactRedux from './reactRedux';
import styledComponents from './styledComponents';
import logOwnerReasons from './logOwnerReasons';
import mobx from './mobx';

const demosList = {
bigList,
Expand All @@ -48,6 +49,7 @@ const demosList = {
reactReduxHOC,
styledComponents,
logOwnerReasons,
mobx,
};

const defaultDemoName = 'bigList';
Expand Down
58 changes: 58 additions & 0 deletions demo/src/mobx/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import ReactDom from 'react-dom';
import _ from 'lodash';
import { makeAutoObservable } from 'mobx';
import { observer } from 'mobx-react-lite';

export default {
description: 'Mobx',
fn({ domElement, whyDidYouRender }) {
whyDidYouRender(React);

class TestStore {
state = { nested: { value: '0' } };

constructor() {
makeAutoObservable(this);
}

increaseCount() {
this.state.nested.value++;
}

deepEqualsCount() {
this.state = _.cloneDeep(this.state);
}
}

const SimpleComponent = ({ testStore }) => {
// eslint-disable-next-line no-console
console.log('re-render!');

return (
<div>
<span>count: {testStore.state.nested.value}</span>
<button onClick={() => testStore.increaseCount()}>
Increase
</button>
<button onClick={() => testStore.deepEqualsCount()}>
deep Equals
</button>
</div>
);
};

const ObservedSimpleComponent = observer(SimpleComponent);

SimpleComponent.whyDidYouRender = true;
ObservedSimpleComponent.whyDidYouRender = true;

const testStore = new TestStore();

const Main = () => (
<ObservedSimpleComponent testStore={testStore}/>
);

ReactDom.render(<Main/>, domElement);
},
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"magic-string": "^0.25.7",
"mobx": "^6.0.4",
"mobx-react-lite": "^3.1.6",
"nollup": "^0.14.4",
"react": "^17.0.1",
"react-16": "npm:react@^16.14.0",
Expand All @@ -111,6 +113,7 @@
"rollup-plugin-commonjs-alternate": "^0.7.2",
"rollup-plugin-license": "^2.2.0",
"rollup-plugin-node-resolve": "^5.2.0",
"snapshot-diff": "^0.8.1",
"start-server-and-test": "^1.11.6",
"styled-components": "^5.2.1",
"typescript": "^4.1.3"
Expand Down
2 changes: 1 addition & 1 deletion tests/getUpdateInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ describe('getUpdateInfo', () => {
});

test('Props change by function', () => {
const input = {
const input = {
Component: TestComponent,
displayName: getDisplayName(TestComponent),
prevProps: { a: () => {} },
Expand Down
Loading