Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] new implementation with useMutableSource #43

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
224d125
v2: useMutableSource
dai-shi Mar 11, 2020
32890c9
revert e2e snapshots to 7c125accf3a8dbca1359b146a00bf5fee6ad324e
dai-shi Mar 11, 2020
e15d06c
typing for build
dai-shi Mar 11, 2020
6fbd8b8
update e2e snapshots
dai-shi Mar 11, 2020
63f1223
update dependencies
dai-shi Mar 12, 2020
7917893
run compile; update README
dai-shi Mar 12, 2020
9a18ff6
add a comment
dai-shi Mar 12, 2020
7e65394
fix internal type
dai-shi Mar 12, 2020
1ef2b3d
fix useTrackedState not to return stale state
dai-shi Mar 12, 2020
4b11fc3
cleaner useTrackedState without refs/effects
dai-shi Mar 16, 2020
053e579
2.0.0-alpha.3
dai-shi Mar 16, 2020
8eb9650
update package.json
dai-shi Mar 17, 2020
ab673b1
merge master
dai-shi Mar 24, 2020
2a630ea
Merge branch 'master' into v2
dai-shi Mar 24, 2020
79f1bd5
re-implement on top of use-context-selector v2-alpha
dai-shi Mar 24, 2020
f69e62f
run compile; v2.0.0-alpha.4
dai-shi Mar 24, 2020
a712d13
more wait in e2e for stability
dai-shi Mar 24, 2020
d2e774f
merge master
dai-shi Apr 19, 2020
b081ed1
merge master
dai-shi May 13, 2020
66465e7
merge master, update deps
dai-shi May 13, 2020
7fadd7c
merge master and update deps
dai-shi Jun 23, 2020
bad1fce
fix eslint error
dai-shi Jun 23, 2020
1fb167c
fix useTrackedState with lastAffected
dai-shi Jun 25, 2020
a391c0c
fix 11 snapshot
dai-shi Jun 25, 2020
c92bc8e
v2.0.0-alpha.5
dai-shi Jun 25, 2020
72910b1
run compile; v2.0.0-alpha.6
dai-shi Jun 25, 2020
f9470b8
remove dist
dai-shi Jul 2, 2020
475d708
update dependencies
dai-shi Jul 2, 2020
758d05b
github actions instead of travis
dai-shi Jul 2, 2020
93c801f
github actions instead of travis
dai-shi Jul 2, 2020
b90e6aa
update badges
dai-shi Jul 2, 2020
b5c808b
modern build
dai-shi Jul 2, 2020
b708308
v2.0.0-alpha.7
dai-shi Jul 2, 2020
3274952
merge master (update dev deps)
dai-shi Aug 3, 2020
5d73562
add eslint rule exception (hmm
dai-shi Aug 3, 2020
c937140
update snapshots
dai-shi Aug 4, 2020
2e1ac70
v2.0.0-alpha.8
dai-shi Aug 4, 2020
c0659e0
Merge branch 'master' into v2
dai-shi Aug 24, 2020
b331fec
merge master
dai-shi Sep 8, 2020
66bb45f
update proxy-compare v1.0.3 and simplify utils
dai-shi Nov 1, 2020
bacb436
merge master
dai-shi Nov 3, 2020
a635f90
update use-context-selector useContextUpdate
dai-shi Nov 3, 2020
91ce359
v2.0.0-alpha.9
dai-shi Nov 3, 2020
fc29c12
fix type annotation (failed to compile)
dai-shi Nov 3, 2020
670a53b
merge master (v1.5.0)
dai-shi Dec 4, 2020
39404f3
merge master
dai-shi Dec 12, 2020
588dc79
sync with master
dai-shi Dec 19, 2020
5b87354
merge master
dai-shi Dec 19, 2020
e9b1177
update snapshot
dai-shi Dec 19, 2020
d3c2127
Merge branch 'master' into v2
dai-shi Dec 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions __tests__/e2e/__snapshots__/01_minimal.ts.snap

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions __tests__/e2e/__snapshots__/02_typescript.ts.snap

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions __tests__/e2e/__snapshots__/03_usestate.ts.snap

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions __tests__/e2e/__snapshots__/04_selector.ts.snap

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions __tests__/e2e/__snapshots__/05_container.ts.snap

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions __tests__/e2e/__snapshots__/11_form.ts.snap

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions __tests__/e2e/__snapshots__/14_dynamic.ts.snap

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "react-tracked",
"description": "Simple and fast global state with React Context. Eliminate unnecessary re-renders without hassle.",
"version": "1.5.1",
"version": "2.0.0-alpha.9",
"publishConfig": {
"tag": "next"
},
"author": "Daishi Kato",
"repository": {
"type": "git",
Expand Down Expand Up @@ -66,7 +69,7 @@
"license": "MIT",
"dependencies": {
"proxy-compare": "1.1.3",
"use-context-selector": "1.3.2"
"use-context-selector": "2.0.0-alpha.9"
},
"devDependencies": {
"@testing-library/react": "^11.2.2",
Expand Down Expand Up @@ -105,7 +108,7 @@
"webpack-dev-server": "^3.11.0"
},
"peerDependencies": {
"react": ">=16.8.0",
"scheduler": ">=0.19.0"
"react": ">=18.0.0",
"scheduler": ">=1.0.0"
}
}
4 changes: 2 additions & 2 deletions src/useSelector.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useDebugValue } from 'react';
import { Context, useContextSelector } from 'use-context-selector';
import { Context, useContext } from 'use-context-selector';

export const useSelector = <State, Selected>(
StateContext: Context<State>,
selector: (state: State) => Selected,
) => {
const selected = useContextSelector(StateContext, selector);
const selected = useContext(StateContext, selector);
useDebugValue(selected);
return selected;
};
4 changes: 2 additions & 2 deletions src/useTrackedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useReducer,
useRef,
} from 'react';
import { Context, useContextSelector } from 'use-context-selector';
import { Context, useContext } from 'use-context-selector';
import {
createDeepProxy,
isDeepChanged,
Expand Down Expand Up @@ -89,7 +89,7 @@ export const useTrackedState = <State>(
return nextState;
};
}, [deepChangedMode]);
const state = useContextSelector(StateContext, selector);
const state = useContext(StateContext, selector);
if (typeof process === 'object' && process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks
useAffectedDebugValue(state, affected);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10116,10 +10116,10 @@ url@^0.11.0:
punycode "1.3.2"
querystring "0.2.0"

use-context-selector@1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/use-context-selector/-/use-context-selector-1.3.2.tgz#326a76875be2914c2d5cabf63349cbd9fda09d34"
integrity sha512-XRRlZD8+FIac3RtmOEqq8SizNEQI6oldteuOWu+F+pDooiJPPaFgw+8wckX+/fuJ80DRJB9HP99UdIq8A1YSMA==
use-context-selector@2.0.0-alpha.9:
version "2.0.0-alpha.9"
resolved "https://registry.yarnpkg.com/use-context-selector/-/use-context-selector-2.0.0-alpha.9.tgz#bc932267ee5ac19e12f0845a7bcd1cf2b243d43f"
integrity sha512-fpkGKvjtdIB599NFCHKrk2wb+1FhuY8OWimBCvGU8GrvTErGPwrcAM1wHXsc8MNkUlsgNPjVHC/x+egtddWeNQ==

use-reducer-async@^2.0.1:
version "2.0.1"
Expand Down