Skip to content

[v2] new API and new implementation with useMutableSource #12

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

Closed
wants to merge 90 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
2ba7353
wip: v2
dai-shi Feb 14, 2020
507fab6
yarn, webpack config
dai-shi Feb 14, 2020
fbc92a1
wip: v2 with useMutableSource
dai-shi Feb 14, 2020
2784e96
wip: some fixes
dai-shi Feb 14, 2020
a07830a
wip: memo context value
dai-shi Feb 14, 2020
2322910
wip: combine useMemo
dai-shi Feb 14, 2020
51f6a5e
use npm-run-all
dai-shi Feb 14, 2020
c10cf75
update dev dependencies
dai-shi Feb 14, 2020
de0117f
update README
dai-shi Feb 14, 2020
41416fb
wip: simplify a bit more
dai-shi Feb 15, 2020
eaa5b3d
update comment
dai-shi Feb 15, 2020
bdd17af
ts-jest config
dai-shi Feb 15, 2020
b88b623
follow new API
dai-shi Feb 15, 2020
26c8a16
named importing hooks
dai-shi Feb 16, 2020
62b4dcb
update code with upcoming useMutableSource
dai-shi Feb 20, 2020
656ab8c
new API: selector in the 2nd arg of useContext
dai-shi Feb 20, 2020
67a6c32
update with the latest RFC
dai-shi Feb 20, 2020
c924b2a
revert handleChange
dai-shi Feb 20, 2020
ff52b56
update docs
dai-shi Feb 21, 2020
2450505
use layout effect with priority
dai-shi Feb 22, 2020
34c9281
move mutation in layout effect, but this would lead tearing.
dai-shi Feb 22, 2020
6e1869b
failing tearing spec
dai-shi Feb 22, 2020
0bc13d2
end up using calculateChangedBits, while that was the major motivatio…
dai-shi Feb 22, 2020
1e26281
merge v1
dai-shi Feb 24, 2020
e96fac6
merge v1 again
dai-shi Feb 24, 2020
883e14e
convert basic spec, why failing?
dai-shi Feb 24, 2020
68f5698
revert calculateChangedBits hack
dai-shi Feb 24, 2020
b783367
examples follow new api
dai-shi Feb 24, 2020
a0d921a
we should probably give up with solving tearing with parent.
dai-shi Feb 28, 2020
e12e4fb
runtime check message
dai-shi Feb 28, 2020
b318953
clean up a left over, update README
dai-shi Feb 28, 2020
76fd2d6
Merge branch 'v1' into v2
dai-shi Mar 2, 2020
6a6f401
merge master
dai-shi Mar 2, 2020
537e1d9
update README
dai-shi Mar 2, 2020
db9f7b2
update README
dai-shi Mar 4, 2020
6d248f1
a workaround for the possible bug in useMutableSource
dai-shi Mar 6, 2020
8b35dec
remove scheduler, update dev deps
dai-shi Mar 8, 2020
8a8f228
jest --preset
dai-shi Mar 8, 2020
1dec8e3
update dependencies
dai-shi Mar 12, 2020
aed3d1d
update README
dai-shi Mar 12, 2020
aee640c
add stale props spec (failing)
dai-shi Mar 12, 2020
cbadd4d
run compile
dai-shi Mar 12, 2020
448f8be
update package.json
dai-shi Mar 17, 2020
13eed63
update yarn.lock
dai-shi Mar 22, 2020
09bb83c
Merge branch 'master' into v2
dai-shi Mar 22, 2020
76ae3da
Merge branch 'master' into v2
dai-shi Mar 22, 2020
b641936
Merge branch 'master' into v2
dai-shi Mar 22, 2020
b70e336
use scheduler to control priority for useTransition
dai-shi Mar 24, 2020
8e64f1b
merge master
dai-shi Mar 24, 2020
5ed8c3a
ended up using any
dai-shi Mar 24, 2020
f05a7c9
run compile; 2.0.0-alpha.2
dai-shi Mar 24, 2020
4adef15
apidoc
dai-shi Mar 24, 2020
0069b8c
fix typo
dai-shi Mar 24, 2020
7464250
export custom Context type
dai-shi Mar 24, 2020
4da2478
2.0.0-alpha.3
dai-shi Mar 24, 2020
96d4197
fix format
dai-shi Mar 24, 2020
ef50db3
update dependencies
dai-shi Apr 10, 2020
8d0698d
update README
dai-shi Apr 11, 2020
0a78b8c
merge master
dai-shi May 22, 2020
43507b6
fix eslint rule
dai-shi May 22, 2020
2fcf1a2
wrap function for getSnapshot workaround
dai-shi May 22, 2020
b4d59ea
2.0.0-alpha.4
dai-shi May 31, 2020
2dff03d
run compile
dai-shi May 31, 2020
f187fb4
update README
dai-shi May 31, 2020
3b72120
merge master
dai-shi Jul 2, 2020
b571171
v2.0.0-alpha.5
dai-shi Jul 2, 2020
7f952c8
update dev deps and unstable_ prefix
dai-shi Aug 3, 2020
ce4ae34
v2.0.0-alpha.6
dai-shi Aug 3, 2020
1120fb2
fix typo
dai-shi Aug 18, 2020
ba4b50f
proper default context value
dai-shi Sep 2, 2020
076b6a9
trying to support branching
dai-shi Sep 2, 2020
163e226
change the priority utility function to a hook
dai-shi Sep 17, 2020
feba3aa
v2.0.0-alpha.7
dai-shi Sep 17, 2020
faa7e75
merge master
dai-shi Sep 17, 2020
5acfa3f
merge master
dai-shi Sep 24, 2020
deb2170
useIsoLayoutEffect from master
dai-shi Sep 24, 2020
7b52117
implement BridgeProvider
dai-shi Sep 24, 2020
389582d
user blocking priority for update
dai-shi Sep 24, 2020
4446313
v2.0.0-alpha.9
dai-shi Sep 29, 2020
c7dc332
merge master
dai-shi Oct 1, 2020
c1edd25
fix test
dai-shi Oct 1, 2020
f1bfa64
merge master
dai-shi Oct 1, 2020
c3b41b0
merge master
dai-shi Oct 2, 2020
2ec77f4
merge master
dai-shi Oct 3, 2020
9b3d3b2
merge master and update deps
dai-shi Nov 9, 2020
fb28545
Merge branch 'master' into v2
dai-shi Nov 28, 2020
08908dc
merge master and adjust everything
dai-shi Dec 1, 2020
24016c5
merge master
dai-shi Dec 3, 2020
5aea090
merge master; keep useBridgeValue
dai-shi Dec 12, 2020
bb8a2e5
fix: test/06
dai-shi Dec 12, 2020
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
Prev Previous commit
Next Next commit
fix test
  • Loading branch information
dai-shi committed Oct 1, 2020
commit c1edd259f80cf7d3b00ad2d2b4dd03ea6d088bad
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"import/no-unresolved": ["error", { "ignore": ["use-context-selector"] }],
"symbol-description": "off",
"no-underscore-dangle": "off",
"no-use-before-define": "off"
"no-use-before-define": "off",
"no-redeclare": "off"
},
"overrides": [{
"files": ["__tests__/**/*"],
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ const functionMap = new WeakMap<Function, { [FUNCTION_SYMBOL]: Function }>();

const ORIGINAL_PROVIDER = Symbol();

/* eslint-disable no-unused-vars, @typescript-eslint/no-unused-vars */
// @ts-ignore
type ContextValue<Value> = {
[SOURCE_SYMBOL]: any;
[UPDATE_SYMBOL]: <T>(thunk: () => T) => T;
};
/* eslint-enable no-unused-vars, @typescript-eslint/no-unused-vars */

type RefValue<Value> = MutableRefObject<{
v: number; // "v" = version
Expand Down Expand Up @@ -127,7 +129,7 @@ export function createContext<Value>(defaultValue: Value) {
[ORIGINAL_PROVIDER]: Provider<ContextValue<Value>>;
})[ORIGINAL_PROVIDER] = context.Provider;
(context as unknown as Context<Value>).Provider = createProvider(context.Provider);
delete context.Consumer; // no support for Consumer
delete (context as any).Consumer; // no support for Consumer
return context as unknown as Context<Value>;
}

Expand All @@ -140,11 +142,11 @@ const subscribe = (
return () => listeners.delete(callback);
};

export function useContext<Value>(context: Context<Value>): Value
export function useContext<Value>(context: Context<Value>): Value;
export function useContext<Value, Selected>(
context: Context<Value>,
selector: (value: Value) => Selected,
): Selected
): Selected;

/**
* This hook returns context value with optional selector.
Expand Down Expand Up @@ -236,7 +238,7 @@ export function useContextUpdate(
* </Renderer>
* );
*/
export const BridgeProvider: React.FC<{
export const BridgeProvider: FC<{
context: Context<any>;
value: any;
}> = ({ context, value, children }) => {
Expand Down