diff --git a/README.md b/README.md index 53001c4..132176f 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ if it's clicked it will trigger state mutation. This is to emulate mutating an external state outside of React, for example updating state by Redux middleware. -The render has intentionaly expensive computation. +The render has intentionally expensive computation. If the mutation happens during rendering with in a tree, there could be an inconsistency in the state. If it finds the inconsistency, the test will fail. @@ -91,327 +91,345 @@ yarn jest:update ``` With useTransition Level 1 - ✓ No tearing finally on update (8111 ms) - ✓ No tearing finally on mount (4750 ms) + ✓ No tearing finally on update (7990 ms) + ✓ No tearing finally on mount (4608 ms) Level 2 - ✓ No tearing temporarily on update (13089 ms) - ✓ No tearing temporarily on mount (4658 ms) + ✓ No tearing temporarily on update (12955 ms) + ✓ No tearing temporarily on mount (4546 ms) Level 3 - ✕ Can interrupt render (time slicing) (8052 ms) - ✕ Can branch state (wip state) (6770 ms) + ✕ Can interrupt render (time slicing) (7926 ms) + ✕ Can branch state (wip state) (6655 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9729 ms) - ✓ No tearing finally on mount (4734 ms) + ✓ No tearing finally on update (9568 ms) + ✓ No tearing finally on mount (4544 ms) Level 2 - ✓ No tearing temporarily on update (14749 ms) - ✓ No tearing temporarily on mount (4728 ms) + ✓ No tearing temporarily on update (14627 ms) + ✓ No tearing temporarily on mount (4569 ms) zustand With useTransition Level 1 - ✓ No tearing finally on update (8125 ms) - ✓ No tearing finally on mount (4687 ms) + ✓ No tearing finally on update (7994 ms) + ✓ No tearing finally on mount (4623 ms) Level 2 - ✓ No tearing temporarily on update (13062 ms) - ✓ No tearing temporarily on mount (4666 ms) + ✓ No tearing temporarily on update (12966 ms) + ✓ No tearing temporarily on mount (4505 ms) Level 3 - ✕ Can interrupt render (time slicing) (8024 ms) - ✕ Can branch state (wip state) (6772 ms) + ✕ Can interrupt render (time slicing) (7922 ms) + ✕ Can branch state (wip state) (6679 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9725 ms) - ✓ No tearing finally on mount (4692 ms) + ✓ No tearing finally on update (9631 ms) + ✓ No tearing finally on mount (4641 ms) Level 2 - ✓ No tearing temporarily on update (14756 ms) - ✓ No tearing temporarily on mount (4670 ms) + ✓ No tearing temporarily on update (14656 ms) + ✓ No tearing temporarily on mount (4544 ms) react-tracked With useTransition Level 1 - ✓ No tearing finally on update (5632 ms) - ✓ No tearing finally on mount (9615 ms) + ✓ No tearing finally on update (5586 ms) + ✓ No tearing finally on mount (9520 ms) Level 2 - ✓ No tearing temporarily on update (8722 ms) - ✓ No tearing temporarily on mount (9589 ms) + ✓ No tearing temporarily on update (8625 ms) + ✓ No tearing temporarily on mount (9455 ms) Level 3 - ✓ Can interrupt render (time slicing) (3669 ms) - ✓ Can branch state (wip state) (8249 ms) + ✓ Can interrupt render (time slicing) (3555 ms) + ✓ Can branch state (wip state) (8216 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (15459 ms) - ✓ No tearing finally on mount (6622 ms) + ✓ No tearing finally on update (15399 ms) + ✓ No tearing finally on mount (6528 ms) Level 2 - ✓ No tearing temporarily on update (19592 ms) - ✓ No tearing temporarily on mount (6537 ms) + ✓ No tearing temporarily on update (19473 ms) + ✓ No tearing temporarily on mount (8479 ms) constate With useTransition Level 1 - ✓ No tearing finally on update (4647 ms) - ✓ No tearing finally on mount (7621 ms) + ✓ No tearing finally on update (4526 ms) + ✓ No tearing finally on mount (7464 ms) Level 2 - ✓ No tearing temporarily on update (8764 ms) - ✓ No tearing temporarily on mount (7591 ms) + ✓ No tearing temporarily on update (8619 ms) + ✓ No tearing temporarily on mount (8491 ms) Level 3 - ✓ Can interrupt render (time slicing) (3714 ms) - ✓ Can branch state (wip state) (5250 ms) + ✓ Can interrupt render (time slicing) (3635 ms) + ✓ Can branch state (wip state) (5159 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9732 ms) - ✓ No tearing finally on mount (5751 ms) + ✓ No tearing finally on update (9626 ms) + ✓ No tearing finally on mount (6629 ms) Level 2 - ✓ No tearing temporarily on update (14753 ms) - ✓ No tearing temporarily on mount (5707 ms) + ✓ No tearing temporarily on update (14643 ms) + ✓ No tearing temporarily on mount (5578 ms) react-hooks-global-state With useTransition Level 1 - ✓ No tearing finally on update (8100 ms) - ✓ No tearing finally on mount (4751 ms) + ✓ No tearing finally on update (7954 ms) + ✓ No tearing finally on mount (4564 ms) Level 2 - ✓ No tearing temporarily on update (13116 ms) - ✓ No tearing temporarily on mount (4700 ms) + ✓ No tearing temporarily on update (12975 ms) + ✓ No tearing temporarily on mount (4525 ms) Level 3 - ✕ Can interrupt render (time slicing) (8062 ms) - ✕ Can branch state (wip state) (6786 ms) + ✕ Can interrupt render (time slicing) (7896 ms) + ✕ Can branch state (wip state) (6648 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9723 ms) - ✓ No tearing finally on mount (4731 ms) + ✓ No tearing finally on update (9624 ms) + ✓ No tearing finally on mount (4547 ms) Level 2 - ✓ No tearing temporarily on update (14743 ms) - ✓ No tearing temporarily on mount (4708 ms) + ✓ No tearing temporarily on update (14636 ms) + ✓ No tearing temporarily on mount (4549 ms) use-context-selector-base With useTransition Level 1 - ✓ No tearing finally on update (8020 ms) - ✓ No tearing finally on mount (7604 ms) + ✓ No tearing finally on update (7851 ms) + ✓ No tearing finally on mount (8476 ms) Level 2 - ✓ No tearing temporarily on update (13002 ms) - ✓ No tearing temporarily on mount (8606 ms) + ✓ No tearing temporarily on update (12836 ms) + ✓ No tearing temporarily on mount (8496 ms) Level 3 - ✕ Can interrupt render (time slicing) (7974 ms) - ✕ Can branch state (wip state) (7783 ms) + ✕ Can interrupt render (time slicing) (7846 ms) + ✕ Can branch state (wip state) (7629 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9726 ms) - ✓ No tearing finally on mount (5784 ms) + ✓ No tearing finally on update (9706 ms) + ✓ No tearing finally on mount (5650 ms) Level 2 - ✓ No tearing temporarily on update (14788 ms) - ✓ No tearing temporarily on mount (5710 ms) + ✓ No tearing temporarily on update (14623 ms) + ✓ No tearing temporarily on mount (5590 ms) use-context-selector With useTransition Level 1 - ✓ No tearing finally on update (5554 ms) - ✓ No tearing finally on mount (11611 ms) + ✓ No tearing finally on update (5503 ms) + ✓ No tearing finally on mount (11504 ms) Level 2 - ✓ No tearing temporarily on update (8704 ms) - ✓ No tearing temporarily on mount (11607 ms) + ✓ No tearing temporarily on update (8629 ms) + ✓ No tearing temporarily on mount (11478 ms) Level 3 - ✓ Can interrupt render (time slicing) (3672 ms) - ✓ Can branch state (wip state) (8246 ms) + ✓ Can interrupt render (time slicing) (3565 ms) + ✓ Can branch state (wip state) (8202 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (15470 ms) - ✓ No tearing finally on mount (8634 ms) + ✓ No tearing finally on update (15341 ms) + ✓ No tearing finally on mount (6542 ms) Level 2 - ✓ No tearing temporarily on update (19581 ms) - ✓ No tearing temporarily on mount (6546 ms) + ✓ No tearing temporarily on update (20063 ms) + ✓ No tearing temporarily on mount (8598 ms) use-subscription With useTransition Level 1 - ✓ No tearing finally on update (8099 ms) - ✓ No tearing finally on mount (4675 ms) + ✓ No tearing finally on update (7989 ms) + ✓ No tearing finally on mount (4610 ms) Level 2 - ✓ No tearing temporarily on update (13124 ms) - ✓ No tearing temporarily on mount (4722 ms) + ✓ No tearing temporarily on update (12955 ms) + ✓ No tearing temporarily on mount (4541 ms) Level 3 - ✕ Can interrupt render (time slicing) (8035 ms) - ✕ Can branch state (wip state) (6806 ms) + ✕ Can interrupt render (time slicing) (7947 ms) + ✕ Can branch state (wip state) (6656 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9767 ms) - ✓ No tearing finally on mount (4717 ms) + ✓ No tearing finally on update (9612 ms) + ✓ No tearing finally on mount (4555 ms) Level 2 - ✓ No tearing temporarily on update (14739 ms) - ✓ No tearing temporarily on mount (4732 ms) + ✓ No tearing temporarily on update (14580 ms) + ✓ No tearing temporarily on mount (4588 ms) apollo-client With useTransition Level 1 - ✓ No tearing finally on update (8281 ms) - ✓ No tearing finally on mount (5745 ms) + ✓ No tearing finally on update (8142 ms) + ✓ No tearing finally on mount (4638 ms) Level 2 - ✓ No tearing temporarily on update (13237 ms) - ✓ No tearing temporarily on mount (5695 ms) + ✓ No tearing temporarily on update (13105 ms) + ✓ No tearing temporarily on mount (5551 ms) Level 3 - ✕ Can interrupt render (time slicing) (8222 ms) - ✕ Can branch state (wip state) (7864 ms) + ✕ Can interrupt render (time slicing) (8083 ms) + ✕ Can branch state (wip state) (7756 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (6578 ms) - ✓ No tearing finally on mount (5705 ms) + ✓ No tearing finally on update (6514 ms) + ✓ No tearing finally on mount (5679 ms) Level 2 - ✓ No tearing temporarily on update (9707 ms) - ✓ No tearing temporarily on mount (5712 ms) + ✓ No tearing temporarily on update (9692 ms) + ✓ No tearing temporarily on mount (4724 ms) recoil With useTransition Level 1 - ✓ No tearing finally on update (8152 ms) - ✓ No tearing finally on mount (4745 ms) + ✓ No tearing finally on update (8119 ms) + ✓ No tearing finally on mount (4729 ms) Level 2 - ✓ No tearing temporarily on update (13157 ms) - ✓ No tearing temporarily on mount (4749 ms) + ✓ No tearing temporarily on update (13109 ms) + ✓ No tearing temporarily on mount (4670 ms) Level 3 - ✕ Can interrupt render (time slicing) (8120 ms) - ✕ Can branch state (wip state) (6843 ms) + ✕ Can interrupt render (time slicing) (8047 ms) + ✕ Can branch state (wip state) (6808 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9760 ms) - ✓ No tearing finally on mount (4721 ms) + ✓ No tearing finally on update (9780 ms) + ✓ No tearing finally on mount (4673 ms) Level 2 - ✓ No tearing temporarily on update (14767 ms) - ✓ No tearing temporarily on mount (4737 ms) + ✓ No tearing temporarily on update (14784 ms) + ✓ No tearing temporarily on mount (4667 ms) recoil_UNSTABLE With useTransition Level 1 - ✓ No tearing finally on update (5645 ms) - ✓ No tearing finally on mount (6650 ms) + ✓ No tearing finally on update (5736 ms) + ✓ No tearing finally on mount (5624 ms) Level 2 - ✓ No tearing temporarily on update (8754 ms) - ✕ No tearing temporarily on mount (5640 ms) + ✓ No tearing temporarily on update (8723 ms) + ✕ No tearing temporarily on mount (5586 ms) Level 3 - ✓ Can interrupt render (time slicing) (3717 ms) - ✕ Can branch state (wip state) (10319 ms) + ✓ Can interrupt render (time slicing) (3763 ms) + ✕ Can branch state (wip state) (10277 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (11378 ms) - ✓ No tearing finally on mount (5713 ms) + ✓ No tearing finally on update (11399 ms) + ✓ No tearing finally on mount (5612 ms) Level 2 - ✓ No tearing temporarily on update (15525 ms) - ✕ No tearing temporarily on mount (5665 ms) + ✓ No tearing temporarily on update (15529 ms) + ✕ No tearing temporarily on mount (5579 ms) jotai With useTransition Level 1 - ✓ No tearing finally on update (5618 ms) - ✓ No tearing finally on mount (8607 ms) + ✓ No tearing finally on update (5633 ms) + ✓ No tearing finally on mount (6580 ms) Level 2 - ✓ No tearing temporarily on update (9730 ms) - ✕ No tearing temporarily on mount (8578 ms) + ✓ No tearing temporarily on update (9753 ms) + ✕ No tearing temporarily on mount (6550 ms) Level 3 - ✓ Can interrupt render (time slicing) (4676 ms) - ✕ Can branch state (wip state) (10271 ms) + ✓ Can interrupt render (time slicing) (4707 ms) + ✕ Can branch state (wip state) (10238 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (10739 ms) - ✓ No tearing finally on mount (6706 ms) + ✓ No tearing finally on update (10713 ms) + ✓ No tearing finally on mount (6736 ms) Level 2 - ✓ No tearing temporarily on update (15734 ms) - ✕ No tearing temporarily on mount (5714 ms) + ✓ No tearing temporarily on update (15726 ms) + ✕ No tearing temporarily on mount (5661 ms) use-atom With useTransition Level 1 - ✓ No tearing finally on update (6626 ms) - ✓ No tearing finally on mount (11617 ms) + ✓ No tearing finally on update (6616 ms) + ✓ No tearing finally on mount (9592 ms) Level 2 - ✓ No tearing temporarily on update (9775 ms) - ✓ No tearing temporarily on mount (11589 ms) + ✓ No tearing temporarily on update (9713 ms) + ✓ No tearing temporarily on mount (9559 ms) Level 3 - ✓ Can interrupt render (time slicing) (4690 ms) - ✓ Can branch state (wip state) (9250 ms) + ✓ Can interrupt render (time slicing) (4749 ms) + ✓ Can branch state (wip state) (9292 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (16475 ms) - ✓ No tearing finally on mount (6627 ms) + ✓ No tearing finally on update (16565 ms) + ✓ No tearing finally on mount (6647 ms) Level 2 - ✓ No tearing temporarily on update (20627 ms) - ✓ No tearing temporarily on mount (6540 ms) + ✓ No tearing temporarily on update (20596 ms) + ✓ No tearing temporarily on mount (6604 ms) valtio With useTransition Level 1 - ✓ No tearing finally on update (8110 ms) - ✓ No tearing finally on mount (4768 ms) + ✓ No tearing finally on update (8087 ms) + ✓ No tearing finally on mount (4701 ms) Level 2 - ✓ No tearing temporarily on update (13113 ms) - ✓ No tearing temporarily on mount (4706 ms) + ✓ No tearing temporarily on update (13031 ms) + ✓ No tearing temporarily on mount (4741 ms) Level 3 - ✕ Can interrupt render (time slicing) (8121 ms) - ✕ Can branch state (wip state) (6826 ms) + ✕ Can interrupt render (time slicing) (8028 ms) + ✕ Can branch state (wip state) (6785 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9745 ms) - ✓ No tearing finally on mount (4755 ms) + ✓ No tearing finally on update (9729 ms) + ✓ No tearing finally on mount (4694 ms) Level 2 - ✓ No tearing temporarily on update (14761 ms) - ✓ No tearing temporarily on mount (4708 ms) + ✓ No tearing temporarily on update (14789 ms) + ✓ No tearing temporarily on mount (4682 ms) effector With useTransition Level 1 - ✓ No tearing finally on update (10346 ms) - ✓ No tearing finally on mount (4740 ms) + ✓ No tearing finally on update (8153 ms) + ✓ No tearing finally on mount (4653 ms) Level 2 - ✓ No tearing temporarily on update (13097 ms) - ✓ No tearing temporarily on mount (4744 ms) + ✓ No tearing temporarily on update (13080 ms) + ✓ No tearing temporarily on mount (4668 ms) Level 3 - ✕ Can interrupt render (time slicing) (8078 ms) - ✕ Can branch state (wip state) (6775 ms) + ✕ Can interrupt render (time slicing) (8003 ms) + ✕ Can branch state (wip state) (6776 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9720 ms) - ✓ No tearing finally on mount (4734 ms) + ✓ No tearing finally on update (9689 ms) + ✓ No tearing finally on mount (4730 ms) Level 2 - ✓ No tearing temporarily on update (14758 ms) - ✓ No tearing temporarily on mount (4709 ms) + ✓ No tearing temporarily on update (14725 ms) + ✓ No tearing temporarily on mount (4608 ms) react-rxjs With useTransition Level 1 - ✓ No tearing finally on update (8130 ms) - ✓ No tearing finally on mount (4737 ms) + ✓ No tearing finally on update (8066 ms) + ✓ No tearing finally on mount (4658 ms) Level 2 - ✓ No tearing temporarily on update (13148 ms) - ✓ No tearing temporarily on mount (4702 ms) + ✓ No tearing temporarily on update (13040 ms) + ✓ No tearing temporarily on mount (4637 ms) Level 3 - ✕ Can interrupt render (time slicing) (8085 ms) - ✕ Can branch state (wip state) (6770 ms) + ✕ Can interrupt render (time slicing) (8027 ms) + ✕ Can branch state (wip state) (6797 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9747 ms) - ✓ No tearing finally on mount (4728 ms) + ✓ No tearing finally on update (9765 ms) + ✓ No tearing finally on mount (4625 ms) Level 2 - ✓ No tearing temporarily on update (14747 ms) - ✓ No tearing temporarily on mount (4677 ms) + ✓ No tearing temporarily on update (14783 ms) + ✓ No tearing temporarily on mount (4642 ms) simplux With useTransition Level 1 - ✓ No tearing finally on update (4634 ms) - ✓ No tearing finally on mount (8634 ms) + ✓ No tearing finally on update (4613 ms) + ✓ No tearing finally on mount (8591 ms) Level 2 - ✓ No tearing temporarily on update (8760 ms) - ✓ No tearing temporarily on mount (6573 ms) + ✓ No tearing temporarily on update (8730 ms) + ✓ No tearing temporarily on mount (8572 ms) Level 3 - ✓ Can interrupt render (time slicing) (3705 ms) - ✕ Can branch state (wip state) (9243 ms) + ✓ Can interrupt render (time slicing) (3712 ms) + ✕ Can branch state (wip state) (9293 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9706 ms) - ✓ No tearing finally on mount (6720 ms) + ✓ No tearing finally on update (9718 ms) + ✓ No tearing finally on mount (6708 ms) Level 2 - ✓ No tearing temporarily on update (14750 ms) - ✓ No tearing temporarily on mount (6629 ms) + ✓ No tearing temporarily on update (14698 ms) + ✓ No tearing temporarily on mount (5680 ms) react-query With useTransition Level 1 - ✓ No tearing finally on update (8195 ms) - ✓ No tearing finally on mount (4714 ms) + ✓ No tearing finally on update (8131 ms) + ✓ No tearing finally on mount (4716 ms) Level 2 - ✕ No tearing temporarily on update (13166 ms) - ✓ No tearing temporarily on mount (4711 ms) + ✕ No tearing temporarily on update (13174 ms) + ✓ No tearing temporarily on mount (4655 ms) Level 3 - ✕ Can interrupt render (time slicing) (8127 ms) - ✕ Can branch state (wip state) (6812 ms) + ✕ Can interrupt render (time slicing) (8120 ms) + ✕ Can branch state (wip state) (6807 ms) With useDeferredValue Level 1 - ✓ No tearing finally on update (9629 ms) - ✓ No tearing finally on mount (4679 ms) + ✓ No tearing finally on update (9594 ms) + ✓ No tearing finally on mount (4665 ms) + Level 2 + ✓ No tearing temporarily on update (13721 ms) + ✓ No tearing temporarily on mount (4653 ms) + mobx-react-lite + With useTransition + Level 1 + ✓ No tearing finally on update (4651 ms) + ✓ No tearing finally on mount (5610 ms) Level 2 - ✓ No tearing temporarily on update (13776 ms) - ✓ No tearing temporarily on mount (4714 ms) + ✕ No tearing temporarily on update (8739 ms) + ✕ No tearing temporarily on mount (6586 ms) + Level 3 + ✓ Can interrupt render (time slicing) (3692 ms) + ✕ Can branch state (wip state) (3071 ms) + With useDeferredValue + Level 1 + ✓ No tearing finally on update (9777 ms) + ✓ No tearing finally on mount (6595 ms) + Level 2 + ✓ No tearing temporarily on update (14724 ms) + ✕ No tearing temporarily on mount (6568 ms) ``` @@ -652,6 +670,19 @@ yarn jest:update :white_check_mark: :white_check_mark: + + mobx-react-lite + :white_check_mark: + :white_check_mark: + :x: + :x: + :white_check_mark: + :x: + :white_check_mark: + :white_check_mark: + :white_check_mark: + :x: + diff --git a/__tests__/all_spec.js b/__tests__/all_spec.js index cb57206..fed256c 100644 --- a/__tests__/all_spec.js +++ b/__tests__/all_spec.js @@ -33,6 +33,7 @@ const names = [ 'react-rxjs', 'simplux', 'react-query', + 'mobx-react-lite', ]; names.forEach((name) => { diff --git a/package.json b/package.json index 9ae0aa1..66fdc0d 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "build:effector": "cross-env NAME=effector webpack", "build:react-rxjs": "cross-env NAME=react-rxjs webpack", "build:valtio": "cross-env NAME=valtio webpack", + "build:mobx-react-lite": "cross-env NAME=mobx-react-lite webpack", "build-all": "run-s build:*" }, "keywords": [ @@ -53,6 +54,8 @@ "effector-react": "^22.4.0", "graphql": "^16.6.0", "jotai": "^2.0.0", + "mobx": "^6.8.0", + "mobx-react-lite": "^3.4.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hooks-global-state": "^2.1.0", diff --git a/src/common.js b/src/common.js index 017acbf..d896f1d 100644 --- a/src/common.js +++ b/src/common.js @@ -67,6 +67,7 @@ export const createApp = ( useDouble, Root = React.Fragment, componentWrapper = React.memo, + mainWrapper = (fn) => fn, ) => { const Counter = componentWrapper(() => { const count = useCount(); @@ -80,7 +81,7 @@ export const createApp = ( return
{count}
; }); - const Main = () => { + const Main = mainWrapper(() => { const [isPending, startTransition] = useTransition(); const [mode, setMode] = useState(null); const transitionHide = () => { @@ -142,7 +143,7 @@ export const createApp = (
{mode === 'deferred' ? deferredCount : count}
); - }; + }); const App = () => ( diff --git a/src/mobx-react-lite/index.js b/src/mobx-react-lite/index.js new file mode 100644 index 0000000..fcda98c --- /dev/null +++ b/src/mobx-react-lite/index.js @@ -0,0 +1,36 @@ +import React, { useCallback } from 'react'; +import { observable, runInAction } from 'mobx'; +import { observer } from 'mobx-react-lite'; + +import { + reducer, + initialState, + selectCount, + incrementAction, + doubleAction, + createApp, +} from '../common'; + +const state = observable(initialState); + +const useCount = () => selectCount(state); + +const useIncrement = () => useCallback(() => { + const newState = reducer(state, incrementAction); + runInAction(() => { + Object.keys(newState).forEach((key) => { + state[key] = newState[key]; + }); + }); +}, []); + +const useDouble = () => useCallback(() => { + const newState = reducer(state, doubleAction); + runInAction(() => { + Object.keys(newState).forEach((key) => { + state[key] = newState[key]; + }); + }); +}, []); + +export default createApp(useCount, useIncrement, useDouble, React.Fragment, observer, observer); diff --git a/update_readme.js b/update_readme.js index 7d3d0d2..a399d4f 100644 --- a/update_readme.js +++ b/update_readme.js @@ -19,6 +19,7 @@ const libraries = { 'react-rxjs': 'react-rxjs', simplux: 'simplux', 'react-query': 'react-query', + 'mobx-react-lite': 'mobx-react-lite', }; const numTests = 10; diff --git a/yarn.lock b/yarn.lock index 2c9dd0c..def22d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5204,6 +5204,16 @@ mkdirp@^0.5.6: dependencies: minimist "^1.2.6" +mobx-react-lite@^3.4.0: + version "3.4.0" + resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-3.4.0.tgz#d59156a96889cdadad751e5e4dab95f28926dfff" + integrity sha512-bRuZp3C0itgLKHu/VNxi66DN/XVkQG7xtoBVWxpvC5FhAqbOCP21+nPhULjnzEqd7xBMybp6KwytdUpZKEgpIQ== + +mobx@^6.8.0: + version "6.8.0" + resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.8.0.tgz#59051755fdb5c8a9f3f2e0a9b6abaf86bab7f843" + integrity sha512-+o/DrHa4zykFMSKfS8Z+CPSEg5LW9tSNGTuN8o6MF1GKxlfkSHSeJn5UtgxvPkGgaouplnrLXCF+duAsmm6FHQ== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"