@fluentui/react-context-selector 0.0.0-nightlyf3ce1fbe1d20211110.1 → 0.0.0-nightlyfc5cfdc52420220215.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +93 -6
- package/CHANGELOG.md +35 -6
- package/lib/createContext.js +53 -40
- package/lib/createContext.js.map +1 -1
- package/lib/useContextSelector.js +65 -48
- package/lib/useContextSelector.js.map +1 -1
- package/lib/useHasParentContext.js +8 -5
- package/lib/useHasParentContext.js.map +1 -1
- package/lib-commonjs/createContext.js +64 -44
- package/lib-commonjs/createContext.js.map +1 -1
- package/lib-commonjs/index.js +34 -8
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types.js +4 -1
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/useContextSelector.js +75 -51
- package/lib-commonjs/useContextSelector.js.map +1 -1
- package/lib-commonjs/useHasParentContext.js +16 -7
- package/lib-commonjs/useHasParentContext.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.json
CHANGED
@@ -2,17 +2,104 @@
|
|
2
2
|
"name": "@fluentui/react-context-selector",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
6
|
-
"tag": "@fluentui/react-context-selector_v0.0.0-
|
7
|
-
"version": "0.0.0-
|
5
|
+
"date": "Tue, 15 Feb 2022 04:11:39 GMT",
|
6
|
+
"tag": "@fluentui/react-context-selector_v0.0.0-nightlyfc5cfdc52420220215.1",
|
7
|
+
"version": "0.0.0-nightlyfc5cfdc52420220215.1",
|
8
8
|
"comments": {
|
9
9
|
"prerelease": [
|
10
10
|
{
|
11
11
|
"author": "email not defined",
|
12
12
|
"package": "@fluentui/react-context-selector",
|
13
|
-
"commit": "
|
13
|
+
"commit": "911569f28daa07a66ee59e1d8b7cfaf6f86051e9",
|
14
14
|
"comment": "Release nightly v9"
|
15
15
|
},
|
16
|
+
{
|
17
|
+
"author": "beachball",
|
18
|
+
"package": "@fluentui/react-context-selector",
|
19
|
+
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightlyfc5cfdc52420220215.1",
|
20
|
+
"commit": "911569f28daa07a66ee59e1d8b7cfaf6f86051e9"
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"date": "Thu, 10 Feb 2022 08:51:09 GMT",
|
27
|
+
"tag": "@fluentui/react-context-selector_v9.0.0-rc.1",
|
28
|
+
"version": "9.0.0-rc.1",
|
29
|
+
"comments": {
|
30
|
+
"none": [
|
31
|
+
{
|
32
|
+
"author": "martinhochel@microsoft.com",
|
33
|
+
"package": "@fluentui/react-context-selector",
|
34
|
+
"commit": "8dfa712156b70414205b87b5b6d099367b0c297d",
|
35
|
+
"comment": "chore: use storybook runner for all vNext packages"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"author": "olfedias@microsoft.com",
|
39
|
+
"package": "@fluentui/react-context-selector",
|
40
|
+
"commit": "c061e98be4b4a718c72a144a1f60bb5515824612",
|
41
|
+
"comment": "remove inline-style-expand-shorthand from tsconfigs"
|
42
|
+
}
|
43
|
+
],
|
44
|
+
"prerelease": [
|
45
|
+
{
|
46
|
+
"author": "lingfangao@hotmail.com",
|
47
|
+
"package": "@fluentui/react-context-selector",
|
48
|
+
"commit": "c00913d50e2dd15bbfbb0757cefe43b192ff1d7f",
|
49
|
+
"comment": "Bump Fluent UI packages to 9.0.0-rc"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"author": "tristan.watanabe@gmail.com",
|
53
|
+
"package": "@fluentui/react-context-selector",
|
54
|
+
"commit": "13f940ea4687d769dd2faf61edc27ff75f6bb565",
|
55
|
+
"comment": "Allow React 17 in peerDependencies."
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"author": "beachball",
|
59
|
+
"package": "@fluentui/react-context-selector",
|
60
|
+
"comment": "Bump @fluentui/react-utilities to v9.0.0-rc.1",
|
61
|
+
"commit": "e6c855f6d9019d6c73668d15fc9bc3a13291a6c8"
|
62
|
+
}
|
63
|
+
]
|
64
|
+
}
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"date": "Thu, 25 Nov 2021 08:34:13 GMT",
|
68
|
+
"tag": "@fluentui/react-context-selector_v9.0.0-beta.4",
|
69
|
+
"version": "9.0.0-beta.4",
|
70
|
+
"comments": {
|
71
|
+
"none": [
|
72
|
+
{
|
73
|
+
"author": "olfedias@microsoft.com",
|
74
|
+
"package": "@fluentui/react-context-selector",
|
75
|
+
"commit": "59b3bebb1944aa35f8e8754beec16dcc95f1d5fb",
|
76
|
+
"comment": "update tooling configs"
|
77
|
+
}
|
78
|
+
],
|
79
|
+
"prerelease": [
|
80
|
+
{
|
81
|
+
"author": "beachball",
|
82
|
+
"package": "@fluentui/react-context-selector",
|
83
|
+
"comment": "Bump @fluentui/react-utilities to v9.0.0-beta.4",
|
84
|
+
"commit": "48d236ac53a4950fabc3ddd52f91dac93ca0195b"
|
85
|
+
}
|
86
|
+
]
|
87
|
+
}
|
88
|
+
},
|
89
|
+
{
|
90
|
+
"date": "Fri, 12 Nov 2021 13:25:22 GMT",
|
91
|
+
"tag": "@fluentui/react-context-selector_v9.0.0-beta.3",
|
92
|
+
"version": "9.0.0-beta.3",
|
93
|
+
"comments": {
|
94
|
+
"none": [
|
95
|
+
{
|
96
|
+
"author": "lingfangao@hotmail.com",
|
97
|
+
"package": "@fluentui/react-context-selector",
|
98
|
+
"commit": "00f70581480b536e723fb69edf0ae617beac4807",
|
99
|
+
"comment": "Remove beta release tag"
|
100
|
+
}
|
101
|
+
],
|
102
|
+
"prerelease": [
|
16
103
|
{
|
17
104
|
"author": "gcox@microsoft.com",
|
18
105
|
"package": "@fluentui/react-context-selector",
|
@@ -22,8 +109,8 @@
|
|
22
109
|
{
|
23
110
|
"author": "beachball",
|
24
111
|
"package": "@fluentui/react-context-selector",
|
25
|
-
"comment": "Bump @fluentui/react-utilities to
|
26
|
-
"commit": "
|
112
|
+
"comment": "Bump @fluentui/react-utilities to v9.0.0-beta.3",
|
113
|
+
"commit": "742342e52c65066f779232e4e1302fedf0dd460d"
|
27
114
|
}
|
28
115
|
]
|
29
116
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,19 +1,48 @@
|
|
1
1
|
# Change Log - @fluentui/react-context-selector
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Tue, 15 Feb 2022 04:11:39 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
-
## [0.0.0-
|
7
|
+
## [0.0.0-nightlyfc5cfdc52420220215.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightlyfc5cfdc52420220215.1)
|
8
8
|
|
9
|
-
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-
|
9
|
+
Tue, 15 Feb 2022 04:11:39 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-rc.1..@fluentui/react-context-selector_v0.0.0-nightlyfc5cfdc52420220215.1)
|
11
|
+
|
12
|
+
### Changes
|
13
|
+
|
14
|
+
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/911569f28daa07a66ee59e1d8b7cfaf6f86051e9) by email not defined)
|
15
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightlyfc5cfdc52420220215.1 ([commit](https://github.com/microsoft/fluentui/commit/911569f28daa07a66ee59e1d8b7cfaf6f86051e9) by beachball)
|
16
|
+
|
17
|
+
## [9.0.0-rc.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-rc.1)
|
18
|
+
|
19
|
+
Thu, 10 Feb 2022 08:51:09 GMT
|
20
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.4..@fluentui/react-context-selector_v9.0.0-rc.1)
|
21
|
+
|
22
|
+
### Changes
|
23
|
+
|
24
|
+
- Bump Fluent UI packages to 9.0.0-rc ([PR #21623](https://github.com/microsoft/fluentui/pull/21623) by lingfangao@hotmail.com)
|
25
|
+
- Allow React 17 in peerDependencies. ([PR #21544](https://github.com/microsoft/fluentui/pull/21544) by tristan.watanabe@gmail.com)
|
26
|
+
- Bump @fluentui/react-utilities to v9.0.0-rc.1 ([commit](https://github.com/microsoft/fluentui/commit/e6c855f6d9019d6c73668d15fc9bc3a13291a6c8) by beachball)
|
27
|
+
|
28
|
+
## [9.0.0-beta.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.4)
|
29
|
+
|
30
|
+
Thu, 25 Nov 2021 08:34:13 GMT
|
31
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.3..@fluentui/react-context-selector_v9.0.0-beta.4)
|
32
|
+
|
33
|
+
### Changes
|
34
|
+
|
35
|
+
- Bump @fluentui/react-utilities to v9.0.0-beta.4 ([PR #20762](https://github.com/microsoft/fluentui/pull/20762) by beachball)
|
36
|
+
|
37
|
+
## [9.0.0-beta.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.3)
|
38
|
+
|
39
|
+
Fri, 12 Nov 2021 13:25:22 GMT
|
40
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.2..@fluentui/react-context-selector_v9.0.0-beta.3)
|
11
41
|
|
12
42
|
### Changes
|
13
43
|
|
14
|
-
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/c7a7f2302f3cfcbc6cd026f4d0ee4d5a2810371a) by email not defined)
|
15
44
|
- Updated beta and RC components to ES2019 ([PR #20405](https://github.com/microsoft/fluentui/pull/20405) by gcox@microsoft.com)
|
16
|
-
- Bump @fluentui/react-utilities to
|
45
|
+
- Bump @fluentui/react-utilities to v9.0.0-beta.3 ([PR #20583](https://github.com/microsoft/fluentui/pull/20583) by beachball)
|
17
46
|
|
18
47
|
## [9.0.0-beta.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.2)
|
19
48
|
|
package/lib/createContext.js
CHANGED
@@ -1,47 +1,60 @@
|
|
1
1
|
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
|
2
2
|
import * as React from 'react';
|
3
3
|
import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
valueRef.current = props.value;
|
21
|
-
versionRef.current += 1;
|
22
|
-
runWithPriority(NormalPriority, () => {
|
23
|
-
contextValue.current.listeners.forEach(listener => {
|
24
|
-
listener([versionRef.current, props.value]);
|
25
|
-
});
|
26
|
-
});
|
27
|
-
}, [props.value]);
|
28
|
-
return React.createElement(Original, { value: contextValue.current }, props.children);
|
29
|
-
};
|
30
|
-
/* istanbul ignore else */
|
31
|
-
if (process.env.NODE_ENV !== 'production') {
|
32
|
-
Provider.displayName = 'ContextSelector.Provider';
|
4
|
+
|
5
|
+
const createProvider = Original => {
|
6
|
+
const Provider = props => {
|
7
|
+
// Holds an actual "props.value"
|
8
|
+
const valueRef = React.useRef(props.value); // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
|
9
|
+
|
10
|
+
const versionRef = React.useRef(0); // A stable object, is used to avoid context updates via mutation of its values.
|
11
|
+
|
12
|
+
const contextValue = React.useRef();
|
13
|
+
|
14
|
+
if (!contextValue.current) {
|
15
|
+
contextValue.current = {
|
16
|
+
value: valueRef,
|
17
|
+
version: versionRef,
|
18
|
+
listeners: []
|
19
|
+
};
|
33
20
|
}
|
34
|
-
|
21
|
+
|
22
|
+
useIsomorphicLayoutEffect(() => {
|
23
|
+
valueRef.current = props.value;
|
24
|
+
versionRef.current += 1;
|
25
|
+
runWithPriority(NormalPriority, () => {
|
26
|
+
contextValue.current.listeners.forEach(listener => {
|
27
|
+
listener([versionRef.current, props.value]);
|
28
|
+
});
|
29
|
+
});
|
30
|
+
}, [props.value]);
|
31
|
+
return /*#__PURE__*/React.createElement(Original, {
|
32
|
+
value: contextValue.current
|
33
|
+
}, props.children);
|
34
|
+
};
|
35
|
+
/* istanbul ignore else */
|
36
|
+
|
37
|
+
|
38
|
+
if (process.env.NODE_ENV !== 'production') {
|
39
|
+
Provider.displayName = 'ContextSelector.Provider';
|
40
|
+
}
|
41
|
+
|
42
|
+
return Provider;
|
35
43
|
};
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
|
45
|
+
export const createContext = defaultValue => {
|
46
|
+
const context = /*#__PURE__*/React.createContext({
|
47
|
+
value: {
|
48
|
+
current: defaultValue
|
49
|
+
},
|
50
|
+
version: {
|
51
|
+
current: -1
|
52
|
+
},
|
53
|
+
listeners: []
|
54
|
+
});
|
55
|
+
context.Provider = createProvider(context.Provider); // We don't support Consumer API
|
56
|
+
|
57
|
+
delete context.Consumer;
|
58
|
+
return context;
|
46
59
|
};
|
47
60
|
//# sourceMappingURL=createContext.js.map
|
package/lib/createContext.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA,SAAS,yBAAT,QAA0C,2BAA1C;AACA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,uBAAuB,IAAI,cAApC,EAAoD,wBAAwB,IAAI,eAAhF,QAAuG,WAAvG;;AAIA,MAAM,cAAc,GAAW,QAAR,IAAyD;AAC9E,QAAM,QAAQ,GAAyC,KAAK,IAAG;AAC7D;AACA,UAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,KAAK,CAAC,KAAnB,CAAjB,CAF6D,CAG7D;;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MAAA,OAAO,EAAE,CAAC;AAAZ,KAF8C;AAGvD,IAAA,SAAS,EAAE;AAH4C,GAAzC,CAAhB;AAMA,EAAA,OAAO,CAAC,QAAR,GAAmB,cAAc,CAAQ,OAAO,CAAC,QAAhB,CAAjC,CAP0E,CAS1E;;AACA,SAAS,OAAsC,CAAC,QAAhD;AAEA,SAAQ,OAAR;AACD,CAbM","sourceRoot":""}
|
@@ -5,63 +5,80 @@ import * as React from 'react';
|
|
5
5
|
* It will only accept context created by `createContext`.
|
6
6
|
* It will trigger re-render if only the selected value is referencially changed.
|
7
7
|
*/
|
8
|
+
|
8
9
|
export const useContextSelector = (context, selector) => {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
if (objectIs(prevState[0], payload[1])) {
|
25
|
-
return prevState; // do not update
|
26
|
-
}
|
27
|
-
const nextSelected = selector(payload[1]);
|
28
|
-
if (objectIs(prevState[1], nextSelected)) {
|
29
|
-
return prevState; // do not update
|
30
|
-
}
|
31
|
-
return [payload[1], nextSelected];
|
32
|
-
}
|
33
|
-
catch (e) {
|
34
|
-
// ignored (stale props or some other reason)
|
35
|
-
}
|
36
|
-
// explicitly spread to enforce typing
|
37
|
-
return [prevState[0], prevState[1]]; // schedule update
|
38
|
-
}, [value, selected]);
|
39
|
-
if (!objectIs(state[1], selected)) {
|
40
|
-
// schedule re-render
|
41
|
-
// this is safe because it's self contained
|
42
|
-
dispatch(undefined);
|
10
|
+
const contextValue = React.useContext(context);
|
11
|
+
const {
|
12
|
+
value: {
|
13
|
+
current: value
|
14
|
+
},
|
15
|
+
version: {
|
16
|
+
current: version
|
17
|
+
},
|
18
|
+
listeners
|
19
|
+
} = contextValue;
|
20
|
+
const selected = selector(value);
|
21
|
+
const [state, dispatch] = React.useReducer((prevState, payload) => {
|
22
|
+
if (!payload) {
|
23
|
+
// early bail out when is dispatched during render
|
24
|
+
return [value, selected];
|
43
25
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
26
|
+
|
27
|
+
if (payload[0] <= version) {
|
28
|
+
if (objectIs(prevState[1], selected)) {
|
29
|
+
return prevState; // bail out
|
30
|
+
}
|
31
|
+
|
32
|
+
return [value, selected];
|
33
|
+
}
|
34
|
+
|
35
|
+
try {
|
36
|
+
if (objectIs(prevState[0], payload[1])) {
|
37
|
+
return prevState; // do not update
|
38
|
+
}
|
39
|
+
|
40
|
+
const nextSelected = selector(payload[1]);
|
41
|
+
|
42
|
+
if (objectIs(prevState[1], nextSelected)) {
|
43
|
+
return prevState; // do not update
|
44
|
+
}
|
45
|
+
|
46
|
+
return [payload[1], nextSelected];
|
47
|
+
} catch (e) {// ignored (stale props or some other reason)
|
48
|
+
} // explicitly spread to enforce typing
|
49
|
+
|
50
|
+
|
51
|
+
return [prevState[0], prevState[1]]; // schedule update
|
52
|
+
}, [value, selected]);
|
53
|
+
|
54
|
+
if (!objectIs(state[1], selected)) {
|
55
|
+
// schedule re-render
|
56
|
+
// this is safe because it's self contained
|
57
|
+
dispatch(undefined);
|
58
|
+
}
|
59
|
+
|
60
|
+
useIsomorphicLayoutEffect(() => {
|
61
|
+
listeners.push(dispatch);
|
62
|
+
return () => {
|
63
|
+
const index = listeners.indexOf(dispatch);
|
64
|
+
listeners.splice(index, 1);
|
65
|
+
};
|
66
|
+
}, [listeners]);
|
67
|
+
return state[1];
|
52
68
|
};
|
53
69
|
/**
|
54
70
|
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
55
71
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
56
72
|
*/
|
57
73
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
74
|
+
|
58
75
|
function is(x, y) {
|
59
|
-
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
|
64
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
76
|
+
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
77
|
+
;
|
78
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
79
|
+
|
80
|
+
|
81
|
+
const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
65
82
|
// @ts-ignore fallback to native if it exists (not in IE11)
|
66
83
|
typeof Object.is === 'function' ? Object.is : is;
|
67
84
|
//# sourceMappingURL=useContextSelector.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/useContextSelector.ts"],"names":[],"mappings":"AAAA,SAAS,yBAAT,QAA0C,2BAA1C;AACA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAaA;;;;AAIG;;AACH,OAAO,MAAM,kBAAkB,GAAG,CAChC,OADgC,EAEhC,QAFgC,KAGf;AACjB,QAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;AAEA,QAAM;AACJ,IAAA,KAAK,EAAE;AAAE,MAAA,OAAO,EAAE;AAAX,KADH;AAEJ,IAAA,OAAO,EAAE;AAAE,MAAA,OAAO,EAAE;AAAX,KAFL;AAGJ,IAAA;AAHI,MAIF,YAJJ;AAKA,QAAM,QAAQ,GAAG,QAAQ,CAAC,KAAD,CAAzB;AAEA,QAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,UAAN,CACxB,CACE,SADF,EAEE,OAFF,KAKqC;AACnC,QAAI,CAAC,OAAL,EAAc;AACZ;AACA,aAAO,CAAC,KAAD,EAAQ,QAAR,CAAP;AACD;;AAED,QAAI,OAAO,CAAC,CAAD,CAAP,IAAc,OAAlB,EAA2B;AACzB,UAAI,QAAQ,CAAC,SAAS,CAAC,CAAD,CAAV,EAAe,QAAf,CAAZ,EAAsC;AACpC,eAAO,SAAP,CADoC,CAClB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,CAAN,IAAW,IAAI,CAAJ,KAAU,IAAI,CAArC,CAAD,IAA8C,CAAC,KAAK,CAAN,IAAW,CAAC,KAAK,CADjE,CACoE;AADpE;AAGD,C,CAED;;;AACA,MAAM,QAAQ,GACZ;AACA;AACA,OAAO,MAAM,CAAC,EAAd,KAAqB,UAArB,GAAkC,MAAM,CAAC,EAAzC,GAA8C,EAHhD","sourceRoot":""}
|
@@ -6,11 +6,14 @@ import * as React from 'react';
|
|
6
6
|
* @param context - context created by react-context-selector
|
7
7
|
* @returns whether the hook is wrapped by a parent context
|
8
8
|
*/
|
9
|
+
|
9
10
|
export function useHasParentContext(context) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
const contextValue = React.useContext(context);
|
12
|
+
|
13
|
+
if (contextValue.version) {
|
14
|
+
return contextValue.version.current !== -1;
|
15
|
+
}
|
16
|
+
|
17
|
+
return false;
|
15
18
|
}
|
16
19
|
//# sourceMappingURL=useHasParentContext.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/useHasParentContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAGA;;;;;;AAMG;;AACH,OAAM,SAAU,mBAAV,CAAqC,OAArC,EAA4D;AAChE,QAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;;AAEA,MAAI,YAAY,CAAC,OAAjB,EAA0B;AACxB,WAAO,YAAY,CAAC,OAAb,CAAqB,OAArB,KAAiC,CAAC,CAAzC;AACD;;AAED,SAAO,KAAP;AACD","sourceRoot":""}
|
@@ -1,51 +1,71 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
3
6
|
exports.createContext = void 0;
|
4
|
-
|
5
|
-
const
|
6
|
-
|
7
|
-
const
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
contextValue.current.listeners.forEach(listener => {
|
27
|
-
listener([versionRef.current, props.value]);
|
28
|
-
});
|
29
|
-
});
|
30
|
-
}, [props.value]);
|
31
|
-
return React.createElement(Original, { value: contextValue.current }, props.children);
|
32
|
-
};
|
33
|
-
/* istanbul ignore else */
|
34
|
-
if (process.env.NODE_ENV !== 'production') {
|
35
|
-
Provider.displayName = 'ContextSelector.Provider';
|
7
|
+
|
8
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
9
|
+
|
10
|
+
const React = /*#__PURE__*/require("react");
|
11
|
+
|
12
|
+
const scheduler_1 = /*#__PURE__*/require("scheduler");
|
13
|
+
|
14
|
+
const createProvider = Original => {
|
15
|
+
const Provider = props => {
|
16
|
+
// Holds an actual "props.value"
|
17
|
+
const valueRef = React.useRef(props.value); // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
|
18
|
+
|
19
|
+
const versionRef = React.useRef(0); // A stable object, is used to avoid context updates via mutation of its values.
|
20
|
+
|
21
|
+
const contextValue = React.useRef();
|
22
|
+
|
23
|
+
if (!contextValue.current) {
|
24
|
+
contextValue.current = {
|
25
|
+
value: valueRef,
|
26
|
+
version: versionRef,
|
27
|
+
listeners: []
|
28
|
+
};
|
36
29
|
}
|
37
|
-
|
30
|
+
|
31
|
+
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
32
|
+
valueRef.current = props.value;
|
33
|
+
versionRef.current += 1;
|
34
|
+
scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority, () => {
|
35
|
+
contextValue.current.listeners.forEach(listener => {
|
36
|
+
listener([versionRef.current, props.value]);
|
37
|
+
});
|
38
|
+
});
|
39
|
+
}, [props.value]);
|
40
|
+
return React.createElement(Original, {
|
41
|
+
value: contextValue.current
|
42
|
+
}, props.children);
|
43
|
+
};
|
44
|
+
/* istanbul ignore else */
|
45
|
+
|
46
|
+
|
47
|
+
if (process.env.NODE_ENV !== 'production') {
|
48
|
+
Provider.displayName = 'ContextSelector.Provider';
|
49
|
+
}
|
50
|
+
|
51
|
+
return Provider;
|
38
52
|
};
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
53
|
+
|
54
|
+
const createContext = defaultValue => {
|
55
|
+
const context = React.createContext({
|
56
|
+
value: {
|
57
|
+
current: defaultValue
|
58
|
+
},
|
59
|
+
version: {
|
60
|
+
current: -1
|
61
|
+
},
|
62
|
+
listeners: []
|
63
|
+
});
|
64
|
+
context.Provider = createProvider(context.Provider); // We don't support Consumer API
|
65
|
+
|
66
|
+
delete context.Consumer;
|
67
|
+
return context;
|
49
68
|
};
|
69
|
+
|
50
70
|
exports.createContext = createContext;
|
51
71
|
//# sourceMappingURL=createContext.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/createContext.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,WAAA,gBAAA,OAAA,CAAA,WAAA,CAAA;;AAIA,MAAM,cAAc,GAAW,QAAR,IAAyD;AAC9E,QAAM,QAAQ,GAAyC,KAAK,IAAG;AAC7D;AACA,UAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,KAAK,CAAC,KAAnB,CAAjB,CAF6D,CAG7D;;AACA,UAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAAa,CAAb,CAAnB,CAJ6D,CAM7D;;AACA,UAAM,YAAY,GAAG,KAAK,CAAC,MAAN,EAArB;;AAEA,QAAI,CAAC,YAAY,C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,OAAO,CAAC,QAAhB,CAAjC,CAP0E,CAS1E;;AACA,SAAS,OAAsC,CAAC,QAAhD;AAEA,SAAQ,OAAR;AACD,CAbM;;AAAM,OAAA,CAAA,aAAA,GAAa,aAAb","sourceRoot":""}
|
package/lib-commonjs/index.js
CHANGED
@@ -1,12 +1,38 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
3
6
|
exports.useHasParentContext = exports.useContextSelector = exports.createContext = void 0;
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
var
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
|
8
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
9
|
+
|
10
|
+
var createContext_1 = /*#__PURE__*/require("./createContext");
|
11
|
+
|
12
|
+
Object.defineProperty(exports, "createContext", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return createContext_1.createContext;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
|
19
|
+
var useContextSelector_1 = /*#__PURE__*/require("./useContextSelector");
|
20
|
+
|
21
|
+
Object.defineProperty(exports, "useContextSelector", {
|
22
|
+
enumerable: true,
|
23
|
+
get: function () {
|
24
|
+
return useContextSelector_1.useContextSelector;
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
var useHasParentContext_1 = /*#__PURE__*/require("./useHasParentContext");
|
29
|
+
|
30
|
+
Object.defineProperty(exports, "useHasParentContext", {
|
31
|
+
enumerable: true,
|
32
|
+
get: function () {
|
33
|
+
return useHasParentContext_1.useHasParentContext;
|
34
|
+
}
|
35
|
+
});
|
36
|
+
|
11
37
|
tslib_1.__exportStar(require("./types"), exports);
|
12
38
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,IAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,eAAA,EAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,GAAA,EAAA,YAAA;AAAA,WAAA,eAAA,CAAA,aAAA;AAAa;AAAb,CAAA;;AACT,IAAA,oBAAA,gBAAA,OAAA,CAAA,sBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,oBAAA,EAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,GAAA,EAAA,YAAA;AAAA,WAAA,oBAAA,CAAA,kBAAA;AAAkB;AAAlB,CAAA;;AACT,IAAA,qBAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,qBAAA,EAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,GAAA,EAAA,YAAA;AAAA,WAAA,qBAAA,CAAA,mBAAA;AAAmB;AAAnB,CAAA;;AACT,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA","sourceRoot":""}
|
package/lib-commonjs/types.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":""}
|
@@ -1,71 +1,95 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
3
6
|
exports.useContextSelector = void 0;
|
4
|
-
|
5
|
-
const
|
7
|
+
|
8
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
9
|
+
|
10
|
+
const React = /*#__PURE__*/require("react");
|
6
11
|
/**
|
7
12
|
* This hook returns context selected value by selector.
|
8
13
|
* It will only accept context created by `createContext`.
|
9
14
|
* It will trigger re-render if only the selected value is referencially changed.
|
10
15
|
*/
|
16
|
+
|
17
|
+
|
11
18
|
const useContextSelector = (context, selector) => {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if (objectIs(prevState[0], payload[1])) {
|
28
|
-
return prevState; // do not update
|
29
|
-
}
|
30
|
-
const nextSelected = selector(payload[1]);
|
31
|
-
if (objectIs(prevState[1], nextSelected)) {
|
32
|
-
return prevState; // do not update
|
33
|
-
}
|
34
|
-
return [payload[1], nextSelected];
|
35
|
-
}
|
36
|
-
catch (e) {
|
37
|
-
// ignored (stale props or some other reason)
|
38
|
-
}
|
39
|
-
// explicitly spread to enforce typing
|
40
|
-
return [prevState[0], prevState[1]]; // schedule update
|
41
|
-
}, [value, selected]);
|
42
|
-
if (!objectIs(state[1], selected)) {
|
43
|
-
// schedule re-render
|
44
|
-
// this is safe because it's self contained
|
45
|
-
dispatch(undefined);
|
19
|
+
const contextValue = React.useContext(context);
|
20
|
+
const {
|
21
|
+
value: {
|
22
|
+
current: value
|
23
|
+
},
|
24
|
+
version: {
|
25
|
+
current: version
|
26
|
+
},
|
27
|
+
listeners
|
28
|
+
} = contextValue;
|
29
|
+
const selected = selector(value);
|
30
|
+
const [state, dispatch] = React.useReducer((prevState, payload) => {
|
31
|
+
if (!payload) {
|
32
|
+
// early bail out when is dispatched during render
|
33
|
+
return [value, selected];
|
46
34
|
}
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
35
|
+
|
36
|
+
if (payload[0] <= version) {
|
37
|
+
if (objectIs(prevState[1], selected)) {
|
38
|
+
return prevState; // bail out
|
39
|
+
}
|
40
|
+
|
41
|
+
return [value, selected];
|
42
|
+
}
|
43
|
+
|
44
|
+
try {
|
45
|
+
if (objectIs(prevState[0], payload[1])) {
|
46
|
+
return prevState; // do not update
|
47
|
+
}
|
48
|
+
|
49
|
+
const nextSelected = selector(payload[1]);
|
50
|
+
|
51
|
+
if (objectIs(prevState[1], nextSelected)) {
|
52
|
+
return prevState; // do not update
|
53
|
+
}
|
54
|
+
|
55
|
+
return [payload[1], nextSelected];
|
56
|
+
} catch (e) {// ignored (stale props or some other reason)
|
57
|
+
} // explicitly spread to enforce typing
|
58
|
+
|
59
|
+
|
60
|
+
return [prevState[0], prevState[1]]; // schedule update
|
61
|
+
}, [value, selected]);
|
62
|
+
|
63
|
+
if (!objectIs(state[1], selected)) {
|
64
|
+
// schedule re-render
|
65
|
+
// this is safe because it's self contained
|
66
|
+
dispatch(undefined);
|
67
|
+
}
|
68
|
+
|
69
|
+
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
70
|
+
listeners.push(dispatch);
|
71
|
+
return () => {
|
72
|
+
const index = listeners.indexOf(dispatch);
|
73
|
+
listeners.splice(index, 1);
|
74
|
+
};
|
75
|
+
}, [listeners]);
|
76
|
+
return state[1];
|
55
77
|
};
|
78
|
+
|
56
79
|
exports.useContextSelector = useContextSelector;
|
57
80
|
/**
|
58
81
|
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
59
82
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
60
83
|
*/
|
61
84
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
85
|
+
|
62
86
|
function is(x, y) {
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
87
|
+
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
88
|
+
;
|
89
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
90
|
+
|
91
|
+
|
92
|
+
const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
69
93
|
// @ts-ignore fallback to native if it exists (not in IE11)
|
70
94
|
typeof Object.is === 'function' ?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ot":""}
|
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
3
6
|
exports.useHasParentContext = void 0;
|
4
|
-
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
5
9
|
/**
|
6
10
|
* Utility hook for contexts created by react-context-selector to determine if a parent context exists
|
7
11
|
* WARNING: This hook will not work for native React contexts
|
@@ -9,12 +13,17 @@ const React = require("react");
|
|
9
13
|
* @param context - context created by react-context-selector
|
10
14
|
* @returns whether the hook is wrapped by a parent context
|
11
15
|
*/
|
16
|
+
|
17
|
+
|
12
18
|
function useHasParentContext(context) {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
const contextValue = React.useContext(context);
|
20
|
+
|
21
|
+
if (contextValue.version) {
|
22
|
+
return contextValue.version.current !== -1;
|
23
|
+
}
|
24
|
+
|
25
|
+
return false;
|
18
26
|
}
|
27
|
+
|
19
28
|
exports.useHasParentContext = useHasParentContext;
|
20
29
|
//# sourceMappingURL=useHasParentContext.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/useHasParentContext.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAGA;;;;;;AAMG;;;AACH,SAAgB,mBAAhB,CAA2C,OAA3C,EAAkE;AAChE,QAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;;AAEA,MAAI,YAAY,CAAC,OAAjB,EAA0B;AACxB,WAAO,YAAY,CAAC,OAAb,CAAqB,OAArB,KAAiC,CAAC,CAAzC;AACD;;AAED,SAAO,KAAP;AACD;;AARD,OAAA,CAAA,mBAAA,GAAA,mBAAA","sourceRoot":""}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-context-selector",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-nightlyfc5cfdc52420220215.1",
|
4
4
|
"description": "React useContextSelector hook in userland",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -17,9 +17,10 @@
|
|
17
17
|
"code-style": "just-scripts code-style",
|
18
18
|
"just": "just-scripts",
|
19
19
|
"lint": "just-scripts lint",
|
20
|
-
"test": "jest",
|
20
|
+
"test": "jest --passWithNoTests",
|
21
21
|
"docs": "api-extractor run --config=config/api-extractor.local.json --local",
|
22
|
-
"build:local": "tsc -p . --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output dist/react-context-selector/src && yarn docs"
|
22
|
+
"build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output ./dist/packages/react-context-selector/src && yarn docs",
|
23
|
+
"type-check": "tsc -b tsconfig.json"
|
23
24
|
},
|
24
25
|
"devDependencies": {
|
25
26
|
"@fluentui/eslint-plugin": "*",
|
@@ -34,18 +35,17 @@
|
|
34
35
|
"react-test-renderer": "^16.3.0"
|
35
36
|
},
|
36
37
|
"dependencies": {
|
37
|
-
"@fluentui/react-utilities": "0.0.0-
|
38
|
+
"@fluentui/react-utilities": "0.0.0-nightlyfc5cfdc52420220215.1",
|
38
39
|
"scheduler": "^0.20.1",
|
39
40
|
"tslib": "^2.1.0"
|
40
41
|
},
|
41
42
|
"peerDependencies": {
|
42
|
-
"@types/react": ">=16.8.0 <
|
43
|
-
"@types/react-dom": ">=16.8.0 <
|
44
|
-
"react": ">=16.8.0 <
|
45
|
-
"react-dom": ">=16.8.0 <
|
43
|
+
"@types/react": ">=16.8.0 <18.0.0",
|
44
|
+
"@types/react-dom": ">=16.8.0 <18.0.0",
|
45
|
+
"react": ">=16.8.0 <18.0.0",
|
46
|
+
"react-dom": ">=16.8.0 <18.0.0"
|
46
47
|
},
|
47
48
|
"beachball": {
|
48
|
-
"tag": "beta",
|
49
49
|
"disallowedChangeTypes": [
|
50
50
|
"major",
|
51
51
|
"minor",
|