@fluentui/react-context-selector 0.0.0-nightlya372ad979820211103.1 → 0.0.0-nightlybc5ff01fb020211104.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 +12 -6
- package/CHANGELOG.md +7 -6
- package/lib/createContext.js +10 -10
- package/lib/createContext.js.map +1 -1
- package/lib/useContextSelector.js +11 -11
- package/lib/useContextSelector.js.map +1 -1
- package/lib/useHasParentContext.js +1 -1
- package/lib/useHasParentContext.js.map +1 -1
- package/lib-commonjs/createContext.js +13 -13
- package/lib-commonjs/createContext.js.map +1 -1
- package/lib-commonjs/index.js +1 -1
- package/lib-commonjs/useContextSelector.js +13 -13
- package/lib-commonjs/useContextSelector.js.map +1 -1
- package/lib-commonjs/useHasParentContext.js +2 -2
- package/lib-commonjs/useHasParentContext.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.json
CHANGED
@@ -2,22 +2,28 @@
|
|
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": "Thu, 04 Nov 2021 04:20:33 GMT",
|
6
|
+
"tag": "@fluentui/react-context-selector_v0.0.0-nightlybc5ff01fb020211104.1",
|
7
|
+
"version": "0.0.0-nightlybc5ff01fb020211104.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": "112d5b8815c25532184ed7c1407ba9a777e2f48d",
|
14
14
|
"comment": "Release nightly v9"
|
15
15
|
},
|
16
|
+
{
|
17
|
+
"author": "gcox@microsoft.com",
|
18
|
+
"package": "@fluentui/react-context-selector",
|
19
|
+
"commit": "c9bd5b5a02ae94a8239ce1b56cac2f0d0dbd3586",
|
20
|
+
"comment": "Updated beta and RC components to ES2019"
|
21
|
+
},
|
16
22
|
{
|
17
23
|
"author": "beachball",
|
18
24
|
"package": "@fluentui/react-context-selector",
|
19
|
-
"comment": "Bump @fluentui/react-utilities to v0.0.0-
|
20
|
-
"commit": "
|
25
|
+
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightlybc5ff01fb020211104.1",
|
26
|
+
"commit": "112d5b8815c25532184ed7c1407ba9a777e2f48d"
|
21
27
|
}
|
22
28
|
]
|
23
29
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
# Change Log - @fluentui/react-context-selector
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Thu, 04 Nov 2021 04:20:33 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
-
## [0.0.0-
|
7
|
+
## [0.0.0-nightlybc5ff01fb020211104.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightlybc5ff01fb020211104.1)
|
8
8
|
|
9
|
-
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.2..@fluentui/react-context-selector_v0.0.0-
|
9
|
+
Thu, 04 Nov 2021 04:20:33 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.2..@fluentui/react-context-selector_v0.0.0-nightlybc5ff01fb020211104.1)
|
11
11
|
|
12
12
|
### Changes
|
13
13
|
|
14
|
-
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/
|
15
|
-
-
|
14
|
+
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/112d5b8815c25532184ed7c1407ba9a777e2f48d) by email not defined)
|
15
|
+
- 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 v0.0.0-nightlybc5ff01fb020211104.1 ([commit](https://github.com/microsoft/fluentui/commit/112d5b8815c25532184ed7c1407ba9a777e2f48d) by beachball)
|
16
17
|
|
17
18
|
## [9.0.0-beta.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.2)
|
18
19
|
|
package/lib/createContext.js
CHANGED
@@ -1,14 +1,14 @@
|
|
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
|
-
|
4
|
+
const createProvider = (Original) => {
|
5
|
+
const Provider = props => {
|
6
6
|
// Holds an actual "props.value"
|
7
|
-
|
7
|
+
const valueRef = React.useRef(props.value);
|
8
8
|
// Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
|
9
|
-
|
9
|
+
const versionRef = React.useRef(0);
|
10
10
|
// A stable object, is used to avoid context updates via mutation of its values.
|
11
|
-
|
11
|
+
const contextValue = React.useRef();
|
12
12
|
if (!contextValue.current) {
|
13
13
|
contextValue.current = {
|
14
14
|
value: valueRef,
|
@@ -16,11 +16,11 @@ var createProvider = function (Original) {
|
|
16
16
|
listeners: [],
|
17
17
|
};
|
18
18
|
}
|
19
|
-
useIsomorphicLayoutEffect(
|
19
|
+
useIsomorphicLayoutEffect(() => {
|
20
20
|
valueRef.current = props.value;
|
21
21
|
versionRef.current += 1;
|
22
|
-
runWithPriority(NormalPriority,
|
23
|
-
contextValue.current.listeners.forEach(
|
22
|
+
runWithPriority(NormalPriority, () => {
|
23
|
+
contextValue.current.listeners.forEach(listener => {
|
24
24
|
listener([versionRef.current, props.value]);
|
25
25
|
});
|
26
26
|
});
|
@@ -33,8 +33,8 @@ var createProvider = function (Original) {
|
|
33
33
|
}
|
34
34
|
return Provider;
|
35
35
|
};
|
36
|
-
export
|
37
|
-
|
36
|
+
export const createContext = (defaultValue) => {
|
37
|
+
const context = React.createContext({
|
38
38
|
value: { current: defaultValue },
|
39
39
|
version: { current: -1 },
|
40
40
|
listeners: [],
|
package/lib/createContext.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,uBAAuB,IAAI,cAAc,EAAE,wBAAwB,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AAInH,
|
1
|
+
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,uBAAuB,IAAI,cAAc,EAAE,wBAAwB,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AAInH,MAAM,cAAc,GAAG,CAAQ,QAA6C,EAAE,EAAE;IAC9E,MAAM,QAAQ,GAAyC,KAAK,CAAC,EAAE;QAC7D,gCAAgC;QAChC,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3C,+GAA+G;QAC/G,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAEnC,gFAAgF;QAChF,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAuB,CAAC;QAEzD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;YACzB,YAAY,CAAC,OAAO,GAAG;gBACrB,KAAK,EAAE,QAAQ;gBACf,OAAO,EAAE,UAAU;gBACnB,SAAS,EAAE,EAAE;aACd,CAAC;SACH;QAED,yBAAyB,CAAC,GAAG,EAAE;YAC7B,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC;YAC/B,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;YAExB,eAAe,CAAC,cAAc,EAAE,GAAG,EAAE;gBAClC,YAAY,CAAC,OAA+B,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;oBACzE,QAAQ,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC9C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAElB,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxF,CAAC,CAAC;IAEF,0BAA0B;IAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,QAAQ,CAAC,WAAW,GAAG,0BAA0B,CAAC;KACnD;IAED,OAAQ,QAA2D,CAAC;AACtE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAQ,YAAmB,EAAkB,EAAE;IAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAsB;QACvD,KAAK,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;QAChC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;QACxB,SAAS,EAAE,EAAE;KACd,CAAC,CAAC;IAEH,OAAO,CAAC,QAAQ,GAAG,cAAc,CAAQ,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE3D,gCAAgC;IAChC,OAAS,OAAsC,CAAC,QAAQ,CAAC;IAEzD,OAAQ,OAAqC,CAAC;AAChD,CAAC,CAAC"}
|
@@ -5,11 +5,11 @@ 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
|
-
export
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
export const useContextSelector = (context, selector) => {
|
9
|
+
const contextValue = React.useContext(context);
|
10
|
+
const { value: { current: value }, version: { current: version }, listeners, } = contextValue;
|
11
|
+
const selected = selector(value);
|
12
|
+
const [state, dispatch] = React.useReducer((prevState, payload) => {
|
13
13
|
if (!payload) {
|
14
14
|
// early bail out when is dispatched during render
|
15
15
|
return [value, selected];
|
@@ -24,7 +24,7 @@ export var useContextSelector = function (context, selector) {
|
|
24
24
|
if (objectIs(prevState[0], payload[1])) {
|
25
25
|
return prevState; // do not update
|
26
26
|
}
|
27
|
-
|
27
|
+
const nextSelected = selector(payload[1]);
|
28
28
|
if (objectIs(prevState[1], nextSelected)) {
|
29
29
|
return prevState; // do not update
|
30
30
|
}
|
@@ -35,16 +35,16 @@ export var useContextSelector = function (context, selector) {
|
|
35
35
|
}
|
36
36
|
// explicitly spread to enforce typing
|
37
37
|
return [prevState[0], prevState[1]]; // schedule update
|
38
|
-
}, [value, selected])
|
38
|
+
}, [value, selected]);
|
39
39
|
if (!objectIs(state[1], selected)) {
|
40
40
|
// schedule re-render
|
41
41
|
// this is safe because it's self contained
|
42
42
|
dispatch(undefined);
|
43
43
|
}
|
44
|
-
useIsomorphicLayoutEffect(
|
44
|
+
useIsomorphicLayoutEffect(() => {
|
45
45
|
listeners.push(dispatch);
|
46
|
-
return
|
47
|
-
|
46
|
+
return () => {
|
47
|
+
const index = listeners.indexOf(dispatch);
|
48
48
|
listeners.splice(index, 1);
|
49
49
|
};
|
50
50
|
}, [listeners]);
|
@@ -60,7 +60,7 @@ function is(x, y) {
|
|
60
60
|
);
|
61
61
|
}
|
62
62
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
63
|
-
|
63
|
+
const objectIs =
|
64
64
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
65
65
|
// @ts-ignore fallback to native if it exists (not in IE11)
|
66
66
|
typeof Object.is === 'function' ? Object.is : is;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useContextSelector.js","sourceRoot":"","sources":["../src/useContextSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B;;;;GAIG;AACH,MAAM,CAAC,
|
1
|
+
{"version":3,"file":"useContextSelector.js","sourceRoot":"","sources":["../src/useContextSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAAuB,EACvB,QAA+C,EAChC,EAAE;IACjB,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;IAE5F,MAAM,EACJ,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EACzB,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAC7B,SAAS,GACV,GAAG,YAAY,CAAC;IACjB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEjC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,UAAU,CACxC,CACE,SAAmF,EACnF,OAEoC,EACH,EAAE;QACnC,IAAI,CAAC,OAAO,EAAE;YACZ,kDAAkD;YAClD,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;SACnC;QAED,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE;YACzB,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE;gBACpC,OAAO,SAAS,CAAC,CAAC,WAAW;aAC9B;YAED,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;SACnC;QAED,IAAI;YACF,IAAI,QAAQ,CAA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,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,sCAAsC;KACzG,CAAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,MAAM,QAAQ;AACZ,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAO,MAAM,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC"}
|
@@ -7,7 +7,7 @@ import * as React from 'react';
|
|
7
7
|
* @returns whether the hook is wrapped by a parent context
|
8
8
|
*/
|
9
9
|
export function useHasParentContext(context) {
|
10
|
-
|
10
|
+
const contextValue = React.useContext(context);
|
11
11
|
if (contextValue.version) {
|
12
12
|
return contextValue.version.current !== -1;
|
13
13
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useHasParentContext.js","sourceRoot":"","sources":["../src/useHasParentContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAQ,OAAuB;IAChE,
|
1
|
+
{"version":3,"file":"useHasParentContext.js","sourceRoot":"","sources":["../src/useHasParentContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAQ,OAAuB;IAChE,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;IAE5F,IAAI,YAAY,CAAC,OAAO,EAAE;QACxB,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;KAC5C;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
@@ -1,17 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.createContext = void 0;
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
const react_utilities_1 = require("@fluentui/react-utilities");
|
5
|
+
const React = require("react");
|
6
|
+
const scheduler_1 = require("scheduler");
|
7
|
+
const createProvider = (Original) => {
|
8
|
+
const Provider = props => {
|
9
9
|
// Holds an actual "props.value"
|
10
|
-
|
10
|
+
const valueRef = React.useRef(props.value);
|
11
11
|
// Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
|
12
|
-
|
12
|
+
const versionRef = React.useRef(0);
|
13
13
|
// A stable object, is used to avoid context updates via mutation of its values.
|
14
|
-
|
14
|
+
const contextValue = React.useRef();
|
15
15
|
if (!contextValue.current) {
|
16
16
|
contextValue.current = {
|
17
17
|
value: valueRef,
|
@@ -19,11 +19,11 @@ var createProvider = function (Original) {
|
|
19
19
|
listeners: [],
|
20
20
|
};
|
21
21
|
}
|
22
|
-
react_utilities_1.useIsomorphicLayoutEffect(
|
22
|
+
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
23
23
|
valueRef.current = props.value;
|
24
24
|
versionRef.current += 1;
|
25
|
-
scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority,
|
26
|
-
contextValue.current.listeners.forEach(
|
25
|
+
scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority, () => {
|
26
|
+
contextValue.current.listeners.forEach(listener => {
|
27
27
|
listener([versionRef.current, props.value]);
|
28
28
|
});
|
29
29
|
});
|
@@ -36,8 +36,8 @@ var createProvider = function (Original) {
|
|
36
36
|
}
|
37
37
|
return Provider;
|
38
38
|
};
|
39
|
-
|
40
|
-
|
39
|
+
const createContext = (defaultValue) => {
|
40
|
+
const context = React.createContext({
|
41
41
|
value: { current: defaultValue },
|
42
42
|
version: { current: -1 },
|
43
43
|
listeners: [],
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../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AAC;IACxF,CAAC,CAAC;IAEF,0BAA0B;IAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,QAAQ,CAAC,WAAW,GAAG,0BAA0B,CAAC;KACnD;IAED,OAAQ,QAA2D,CAAC;AACtE,CAAC,CAAC;AAEK,MAAM,aAAa,GAAG,CAAQ,YAAmB,EAAkB,EAAE;IAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAsB;QACvD,KAAK,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;QAChC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;QACxB,SAAS,EAAE,EAAE;KACd,CAAC,CAAC;IAEH,OAAO,CAAC,QAAQ,GAAG,cAAc,CAAQ,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE3D,gCAAgC;IAChC,OAAS,OAAsC,CAAC,QAAQ,CAAC;IAEzD,OAAQ,OAAqC,CAAC;AAChD,CAAC,CAAC;AAbW,QAAA,aAAa,iBAaxB"}
|
package/lib-commonjs/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.useHasParentContext = exports.useContextSelector = exports.createContext = void 0;
|
4
|
-
|
4
|
+
const tslib_1 = require("tslib");
|
5
5
|
var createContext_1 = require("./createContext");
|
6
6
|
Object.defineProperty(exports, "createContext", { enumerable: true, get: function () { return createContext_1.createContext; } });
|
7
7
|
var useContextSelector_1 = require("./useContextSelector");
|
@@ -1,18 +1,18 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.useContextSelector = void 0;
|
4
|
-
|
5
|
-
|
4
|
+
const react_utilities_1 = require("@fluentui/react-utilities");
|
5
|
+
const React = require("react");
|
6
6
|
/**
|
7
7
|
* This hook returns context selected value by selector.
|
8
8
|
* It will only accept context created by `createContext`.
|
9
9
|
* It will trigger re-render if only the selected value is referencially changed.
|
10
10
|
*/
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
const useContextSelector = (context, selector) => {
|
12
|
+
const contextValue = React.useContext(context);
|
13
|
+
const { value: { current: value }, version: { current: version }, listeners, } = contextValue;
|
14
|
+
const selected = selector(value);
|
15
|
+
const [state, dispatch] = React.useReducer((prevState, payload) => {
|
16
16
|
if (!payload) {
|
17
17
|
// early bail out when is dispatched during render
|
18
18
|
return [value, selected];
|
@@ -27,7 +27,7 @@ var useContextSelector = function (context, selector) {
|
|
27
27
|
if (objectIs(prevState[0], payload[1])) {
|
28
28
|
return prevState; // do not update
|
29
29
|
}
|
30
|
-
|
30
|
+
const nextSelected = selector(payload[1]);
|
31
31
|
if (objectIs(prevState[1], nextSelected)) {
|
32
32
|
return prevState; // do not update
|
33
33
|
}
|
@@ -38,16 +38,16 @@ var useContextSelector = function (context, selector) {
|
|
38
38
|
}
|
39
39
|
// explicitly spread to enforce typing
|
40
40
|
return [prevState[0], prevState[1]]; // schedule update
|
41
|
-
}, [value, selected])
|
41
|
+
}, [value, selected]);
|
42
42
|
if (!objectIs(state[1], selected)) {
|
43
43
|
// schedule re-render
|
44
44
|
// this is safe because it's self contained
|
45
45
|
dispatch(undefined);
|
46
46
|
}
|
47
|
-
react_utilities_1.useIsomorphicLayoutEffect(
|
47
|
+
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
48
48
|
listeners.push(dispatch);
|
49
|
-
return
|
50
|
-
|
49
|
+
return () => {
|
50
|
+
const index = listeners.indexOf(dispatch);
|
51
51
|
listeners.splice(index, 1);
|
52
52
|
};
|
53
53
|
}, [listeners]);
|
@@ -64,7 +64,7 @@ function is(x, y) {
|
|
64
64
|
);
|
65
65
|
}
|
66
66
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
67
|
-
|
67
|
+
const objectIs =
|
68
68
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
69
69
|
// @ts-ignore fallback to native if it exists (not in IE11)
|
70
70
|
typeof Object.is === 'function' ? Object.is : is;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useContextSelector.js","sourceRoot":"","sources":["../src/useContextSelector.ts"],"names":[],"mappings":";;;AAAA
|
1
|
+
{"version":3,"file":"useContextSelector.js","sourceRoot":"","sources":["../src/useContextSelector.ts"],"names":[],"mappings":";;;AAAA,+DAAsE;AACtE,+BAA+B;AAa/B;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,CAChC,OAAuB,EACvB,QAA+C,EAChC,EAAE;IACjB,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;IAE5F,MAAM,EACJ,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EACzB,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAC7B,SAAS,GACV,GAAG,YAAY,CAAC;IACjB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEjC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,UAAU,CACxC,CACE,SAAmF,EACnF,OAEoC,EACH,EAAE;QACnC,IAAI,CAAC,OAAO,EAAE;YACZ,kDAAkD;YAClD,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;SACnC;QAED,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE;YACzB,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE;gBACpC,OAAO,SAAS,CAAC,CAAC,WAAW;aAC9B;YAED,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;SACnC;QAED,IAAI;YACF,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gBACtC,OAAO,SAAS,CAAC,CAAC,gBAAgB;aACnC;YAED,MAAM,YAAY,GAAG,QA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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,sCAAsC;KACzG,CAAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,MAAM,QAAQ;AACZ,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAO,MAAM,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.useHasParentContext = void 0;
|
4
|
-
|
4
|
+
const React = require("react");
|
5
5
|
/**
|
6
6
|
* Utility hook for contexts created by react-context-selector to determine if a parent context exists
|
7
7
|
* WARNING: This hook will not work for native React contexts
|
@@ -10,7 +10,7 @@ var React = require("react");
|
|
10
10
|
* @returns whether the hook is wrapped by a parent context
|
11
11
|
*/
|
12
12
|
function useHasParentContext(context) {
|
13
|
-
|
13
|
+
const contextValue = React.useContext(context);
|
14
14
|
if (contextValue.version) {
|
15
15
|
return contextValue.version.current !== -1;
|
16
16
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useHasParentContext.js","sourceRoot":"","sources":["../src/useHasParentContext.ts"],"names":[],"mappings":";;;AAAA
|
1
|
+
{"version":3,"file":"useHasParentContext.js","sourceRoot":"","sources":["../src/useHasParentContext.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAG/B;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAQ,OAAuB;IAChE,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;IAE5F,IAAI,YAAY,CAAC,OAAO,EAAE;QACxB,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;KAC5C;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AARD,kDAQC"}
|
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-nightlybc5ff01fb020211104.1",
|
4
4
|
"description": "React useContextSelector hook in userland",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -34,7 +34,7 @@
|
|
34
34
|
"react-test-renderer": "^16.3.0"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@fluentui/react-utilities": "0.0.0-
|
37
|
+
"@fluentui/react-utilities": "0.0.0-nightlybc5ff01fb020211104.1",
|
38
38
|
"scheduler": "^0.20.1",
|
39
39
|
"tslib": "^2.1.0"
|
40
40
|
},
|