@fluentui/react-context-selector
Advanced tools
Comparing version 0.0.0-nightlyed2d7c8d6320211111.1 to 0.0.0-nightlyf1be0a972820211214.1
@@ -5,5 +5,5 @@ { | ||
{ | ||
"date": "Thu, 11 Nov 2021 13:12:40 GMT", | ||
"tag": "@fluentui/react-context-selector_v0.0.0-nightlyed2d7c8d6320211111.1", | ||
"version": "0.0.0-nightlyed2d7c8d6320211111.1", | ||
"date": "Tue, 14 Dec 2021 04:16:16 GMT", | ||
"tag": "@fluentui/react-context-selector_v0.0.0-nightlyf1be0a972820211214.1", | ||
"version": "0.0.0-nightlyf1be0a972820211214.1", | ||
"comments": { | ||
@@ -14,6 +14,52 @@ "prerelease": [ | ||
"package": "@fluentui/react-context-selector", | ||
"commit": "69054b5abc9c52ffb203f51ad40b49d9729af7d9", | ||
"commit": "3bda806f2deef1997fc6c070450a4a7aacb036ca", | ||
"comment": "Release nightly v9" | ||
}, | ||
{ | ||
"author": "beachball", | ||
"package": "@fluentui/react-context-selector", | ||
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightlyf1be0a972820211214.1", | ||
"commit": "3bda806f2deef1997fc6c070450a4a7aacb036ca" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Thu, 25 Nov 2021 08:34:13 GMT", | ||
"tag": "@fluentui/react-context-selector_v9.0.0-beta.4", | ||
"version": "9.0.0-beta.4", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"author": "olfedias@microsoft.com", | ||
"package": "@fluentui/react-context-selector", | ||
"commit": "59b3bebb1944aa35f8e8754beec16dcc95f1d5fb", | ||
"comment": "update tooling configs" | ||
} | ||
], | ||
"prerelease": [ | ||
{ | ||
"author": "beachball", | ||
"package": "@fluentui/react-context-selector", | ||
"comment": "Bump @fluentui/react-utilities to v9.0.0-beta.4", | ||
"commit": "48d236ac53a4950fabc3ddd52f91dac93ca0195b" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Fri, 12 Nov 2021 13:25:22 GMT", | ||
"tag": "@fluentui/react-context-selector_v9.0.0-beta.3", | ||
"version": "9.0.0-beta.3", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"author": "lingfangao@hotmail.com", | ||
"package": "@fluentui/react-context-selector", | ||
"commit": "00f70581480b536e723fb69edf0ae617beac4807", | ||
"comment": "Remove beta release tag" | ||
} | ||
], | ||
"prerelease": [ | ||
{ | ||
"author": "gcox@microsoft.com", | ||
@@ -27,4 +73,4 @@ "package": "@fluentui/react-context-selector", | ||
"package": "@fluentui/react-context-selector", | ||
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightlyed2d7c8d6320211111.1", | ||
"commit": "69054b5abc9c52ffb203f51ad40b49d9729af7d9" | ||
"comment": "Bump @fluentui/react-utilities to v9.0.0-beta.3", | ||
"commit": "742342e52c65066f779232e4e1302fedf0dd460d" | ||
} | ||
@@ -31,0 +77,0 @@ ] |
# Change Log - @fluentui/react-context-selector | ||
This log was last generated on Thu, 11 Nov 2021 13:12:40 GMT and should not be manually modified. | ||
This log was last generated on Tue, 14 Dec 2021 04:16:16 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## [0.0.0-nightlyed2d7c8d6320211111.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightlyed2d7c8d6320211111.1) | ||
## [0.0.0-nightlyf1be0a972820211214.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightlyf1be0a972820211214.1) | ||
Thu, 11 Nov 2021 13:12:40 GMT | ||
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.2..@fluentui/react-context-selector_v0.0.0-nightlyed2d7c8d6320211111.1) | ||
Tue, 14 Dec 2021 04:16:16 GMT | ||
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.4..@fluentui/react-context-selector_v0.0.0-nightlyf1be0a972820211214.1) | ||
### Changes | ||
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/69054b5abc9c52ffb203f51ad40b49d9729af7d9) by email not defined) | ||
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/3bda806f2deef1997fc6c070450a4a7aacb036ca) by email not defined) | ||
- Bump @fluentui/react-utilities to v0.0.0-nightlyf1be0a972820211214.1 ([commit](https://github.com/microsoft/fluentui/commit/3bda806f2deef1997fc6c070450a4a7aacb036ca) by beachball) | ||
## [9.0.0-beta.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.4) | ||
Thu, 25 Nov 2021 08:34:13 GMT | ||
[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) | ||
### Changes | ||
- Bump @fluentui/react-utilities to v9.0.0-beta.4 ([PR #20762](https://github.com/microsoft/fluentui/pull/20762) by beachball) | ||
## [9.0.0-beta.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.3) | ||
Fri, 12 Nov 2021 13:25:22 GMT | ||
[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) | ||
### Changes | ||
- Updated beta and RC components to ES2019 ([PR #20405](https://github.com/microsoft/fluentui/pull/20405) by gcox@microsoft.com) | ||
- Bump @fluentui/react-utilities to v0.0.0-nightlyed2d7c8d6320211111.1 ([commit](https://github.com/microsoft/fluentui/commit/69054b5abc9c52ffb203f51ad40b49d9729af7d9) by beachball) | ||
- Bump @fluentui/react-utilities to v9.0.0-beta.3 ([PR #20583](https://github.com/microsoft/fluentui/pull/20583) by beachball) | ||
@@ -18,0 +36,0 @@ ## [9.0.0-beta.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.2) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createContext = void 0; | ||
const react_utilities_1 = require("@fluentui/react-utilities"); | ||
const React = require("react"); | ||
const scheduler_1 = require("scheduler"); | ||
const createProvider = (Original) => { | ||
const Provider = props => { | ||
// Holds an actual "props.value" | ||
const valueRef = React.useRef(props.value); | ||
// Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider. | ||
const versionRef = React.useRef(0); | ||
// A stable object, is used to avoid context updates via mutation of its values. | ||
const contextValue = React.useRef(); | ||
if (!contextValue.current) { | ||
contextValue.current = { | ||
value: valueRef, | ||
version: versionRef, | ||
listeners: [], | ||
}; | ||
} | ||
react_utilities_1.useIsomorphicLayoutEffect(() => { | ||
valueRef.current = props.value; | ||
versionRef.current += 1; | ||
scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority, () => { | ||
contextValue.current.listeners.forEach(listener => { | ||
listener([versionRef.current, props.value]); | ||
}); | ||
}); | ||
}, [props.value]); | ||
return React.createElement(Original, { value: contextValue.current }, props.children); | ||
}; | ||
/* istanbul ignore else */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.displayName = 'ContextSelector.Provider'; | ||
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities"); | ||
const React = /*#__PURE__*/require("react"); | ||
const scheduler_1 = /*#__PURE__*/require("scheduler"); | ||
const createProvider = Original => { | ||
const Provider = props => { | ||
// Holds an actual "props.value" | ||
const valueRef = React.useRef(props.value); // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider. | ||
const versionRef = React.useRef(0); // A stable object, is used to avoid context updates via mutation of its values. | ||
const contextValue = React.useRef(); | ||
if (!contextValue.current) { | ||
contextValue.current = { | ||
value: valueRef, | ||
version: versionRef, | ||
listeners: [] | ||
}; | ||
} | ||
return Provider; | ||
react_utilities_1.useIsomorphicLayoutEffect(() => { | ||
valueRef.current = props.value; | ||
versionRef.current += 1; | ||
scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority, () => { | ||
contextValue.current.listeners.forEach(listener => { | ||
listener([versionRef.current, props.value]); | ||
}); | ||
}); | ||
}, [props.value]); | ||
return React.createElement(Original, { | ||
value: contextValue.current | ||
}, props.children); | ||
}; | ||
/* istanbul ignore else */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.displayName = 'ContextSelector.Provider'; | ||
} | ||
return Provider; | ||
}; | ||
const createContext = (defaultValue) => { | ||
const context = React.createContext({ | ||
value: { current: defaultValue }, | ||
version: { current: -1 }, | ||
listeners: [], | ||
}); | ||
context.Provider = createProvider(context.Provider); | ||
// We don't support Consumer API | ||
delete context.Consumer; | ||
return context; | ||
const createContext = defaultValue => { | ||
const context = React.createContext({ | ||
value: { | ||
current: defaultValue | ||
}, | ||
version: { | ||
current: -1 | ||
}, | ||
listeners: [] | ||
}); | ||
context.Provider = createProvider(context.Provider); // We don't support Consumer API | ||
delete context.Consumer; | ||
return context; | ||
}; | ||
exports.createContext = createContext; | ||
//# sourceMappingURL=createContext.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.useHasParentContext = exports.useContextSelector = exports.createContext = void 0; | ||
const tslib_1 = require("tslib"); | ||
var createContext_1 = require("./createContext"); | ||
Object.defineProperty(exports, "createContext", { enumerable: true, get: function () { return createContext_1.createContext; } }); | ||
var useContextSelector_1 = require("./useContextSelector"); | ||
Object.defineProperty(exports, "useContextSelector", { enumerable: true, get: function () { return useContextSelector_1.useContextSelector; } }); | ||
var useHasParentContext_1 = require("./useHasParentContext"); | ||
Object.defineProperty(exports, "useHasParentContext", { enumerable: true, get: function () { return useHasParentContext_1.useHasParentContext; } }); | ||
const tslib_1 = /*#__PURE__*/require("tslib"); | ||
var createContext_1 = /*#__PURE__*/require("./createContext"); | ||
Object.defineProperty(exports, "createContext", { | ||
enumerable: true, | ||
get: function () { | ||
return createContext_1.createContext; | ||
} | ||
}); | ||
var useContextSelector_1 = /*#__PURE__*/require("./useContextSelector"); | ||
Object.defineProperty(exports, "useContextSelector", { | ||
enumerable: true, | ||
get: function () { | ||
return useContextSelector_1.useContextSelector; | ||
} | ||
}); | ||
var useHasParentContext_1 = /*#__PURE__*/require("./useHasParentContext"); | ||
Object.defineProperty(exports, "useHasParentContext", { | ||
enumerable: true, | ||
get: function () { | ||
return useHasParentContext_1.useHasParentContext; | ||
} | ||
}); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
//# sourceMappingURL=types.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.useContextSelector = void 0; | ||
const react_utilities_1 = require("@fluentui/react-utilities"); | ||
const React = require("react"); | ||
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities"); | ||
const React = /*#__PURE__*/require("react"); | ||
/** | ||
@@ -11,47 +16,65 @@ * This hook returns context selected value by selector. | ||
*/ | ||
const useContextSelector = (context, selector) => { | ||
const contextValue = React.useContext(context); | ||
const { value: { current: value }, version: { current: version }, listeners, } = contextValue; | ||
const selected = selector(value); | ||
const [state, dispatch] = React.useReducer((prevState, payload) => { | ||
if (!payload) { | ||
// early bail out when is dispatched during render | ||
return [value, selected]; | ||
} | ||
if (payload[0] <= version) { | ||
if (objectIs(prevState[1], selected)) { | ||
return prevState; // bail out | ||
} | ||
return [value, selected]; | ||
} | ||
try { | ||
if (objectIs(prevState[0], payload[1])) { | ||
return prevState; // do not update | ||
} | ||
const nextSelected = selector(payload[1]); | ||
if (objectIs(prevState[1], nextSelected)) { | ||
return prevState; // do not update | ||
} | ||
return [payload[1], nextSelected]; | ||
} | ||
catch (e) { | ||
// ignored (stale props or some other reason) | ||
} | ||
// explicitly spread to enforce typing | ||
return [prevState[0], prevState[1]]; // schedule update | ||
}, [value, selected]); | ||
if (!objectIs(state[1], selected)) { | ||
// schedule re-render | ||
// this is safe because it's self contained | ||
dispatch(undefined); | ||
const contextValue = React.useContext(context); | ||
const { | ||
value: { | ||
current: value | ||
}, | ||
version: { | ||
current: version | ||
}, | ||
listeners | ||
} = contextValue; | ||
const selected = selector(value); | ||
const [state, dispatch] = React.useReducer((prevState, payload) => { | ||
if (!payload) { | ||
// early bail out when is dispatched during render | ||
return [value, selected]; | ||
} | ||
react_utilities_1.useIsomorphicLayoutEffect(() => { | ||
listeners.push(dispatch); | ||
return () => { | ||
const index = listeners.indexOf(dispatch); | ||
listeners.splice(index, 1); | ||
}; | ||
}, [listeners]); | ||
return state[1]; | ||
if (payload[0] <= version) { | ||
if (objectIs(prevState[1], selected)) { | ||
return prevState; // bail out | ||
} | ||
return [value, selected]; | ||
} | ||
try { | ||
if (objectIs(prevState[0], payload[1])) { | ||
return prevState; // do not update | ||
} | ||
const nextSelected = selector(payload[1]); | ||
if (objectIs(prevState[1], nextSelected)) { | ||
return prevState; // do not update | ||
} | ||
return [payload[1], nextSelected]; | ||
} catch (e) {// ignored (stale props or some other reason) | ||
} // explicitly spread to enforce typing | ||
return [prevState[0], prevState[1]]; // schedule update | ||
}, [value, selected]); | ||
if (!objectIs(state[1], selected)) { | ||
// schedule re-render | ||
// this is safe because it's self contained | ||
dispatch(undefined); | ||
} | ||
react_utilities_1.useIsomorphicLayoutEffect(() => { | ||
listeners.push(dispatch); | ||
return () => { | ||
const index = listeners.indexOf(dispatch); | ||
listeners.splice(index, 1); | ||
}; | ||
}, [listeners]); | ||
return state[1]; | ||
}; | ||
exports.useContextSelector = useContextSelector; | ||
@@ -63,11 +86,12 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function is(x, y) { | ||
return ((x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare | ||
); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const objectIs = | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
} // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore fallback to native if it exists (not in IE11) | ||
typeof Object.is === 'function' ? Object.is : is; | ||
//# sourceMappingURL=useContextSelector.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.useHasParentContext = void 0; | ||
const React = require("react"); | ||
const React = /*#__PURE__*/require("react"); | ||
/** | ||
@@ -12,10 +16,15 @@ * Utility hook for contexts created by react-context-selector to determine if a parent context exists | ||
*/ | ||
function useHasParentContext(context) { | ||
const contextValue = React.useContext(context); | ||
if (contextValue.version) { | ||
return contextValue.version.current !== -1; | ||
} | ||
return false; | ||
const contextValue = React.useContext(context); | ||
if (contextValue.version) { | ||
return contextValue.version.current !== -1; | ||
} | ||
return false; | ||
} | ||
exports.useHasParentContext = useHasParentContext; | ||
//# sourceMappingURL=useHasParentContext.js.map |
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities'; | ||
import * as React from 'react'; | ||
import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler'; | ||
const createProvider = (Original) => { | ||
const Provider = props => { | ||
// Holds an actual "props.value" | ||
const valueRef = React.useRef(props.value); | ||
// Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider. | ||
const versionRef = React.useRef(0); | ||
// A stable object, is used to avoid context updates via mutation of its values. | ||
const contextValue = React.useRef(); | ||
if (!contextValue.current) { | ||
contextValue.current = { | ||
value: valueRef, | ||
version: versionRef, | ||
listeners: [], | ||
}; | ||
} | ||
useIsomorphicLayoutEffect(() => { | ||
valueRef.current = props.value; | ||
versionRef.current += 1; | ||
runWithPriority(NormalPriority, () => { | ||
contextValue.current.listeners.forEach(listener => { | ||
listener([versionRef.current, props.value]); | ||
}); | ||
}); | ||
}, [props.value]); | ||
return React.createElement(Original, { value: contextValue.current }, props.children); | ||
}; | ||
/* istanbul ignore else */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.displayName = 'ContextSelector.Provider'; | ||
const createProvider = Original => { | ||
const Provider = props => { | ||
// Holds an actual "props.value" | ||
const valueRef = React.useRef(props.value); // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider. | ||
const versionRef = React.useRef(0); // A stable object, is used to avoid context updates via mutation of its values. | ||
const contextValue = React.useRef(); | ||
if (!contextValue.current) { | ||
contextValue.current = { | ||
value: valueRef, | ||
version: versionRef, | ||
listeners: [] | ||
}; | ||
} | ||
return Provider; | ||
useIsomorphicLayoutEffect(() => { | ||
valueRef.current = props.value; | ||
versionRef.current += 1; | ||
runWithPriority(NormalPriority, () => { | ||
contextValue.current.listeners.forEach(listener => { | ||
listener([versionRef.current, props.value]); | ||
}); | ||
}); | ||
}, [props.value]); | ||
return /*#__PURE__*/React.createElement(Original, { | ||
value: contextValue.current | ||
}, props.children); | ||
}; | ||
/* istanbul ignore else */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.displayName = 'ContextSelector.Provider'; | ||
} | ||
return Provider; | ||
}; | ||
export const createContext = (defaultValue) => { | ||
const context = React.createContext({ | ||
value: { current: defaultValue }, | ||
version: { current: -1 }, | ||
listeners: [], | ||
}); | ||
context.Provider = createProvider(context.Provider); | ||
// We don't support Consumer API | ||
delete context.Consumer; | ||
return context; | ||
export const createContext = defaultValue => { | ||
const context = /*#__PURE__*/React.createContext({ | ||
value: { | ||
current: defaultValue | ||
}, | ||
version: { | ||
current: -1 | ||
}, | ||
listeners: [] | ||
}); | ||
context.Provider = createProvider(context.Provider); // We don't support Consumer API | ||
delete context.Consumer; | ||
return context; | ||
}; | ||
//# sourceMappingURL=createContext.js.map |
@@ -8,46 +8,62 @@ import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities'; | ||
*/ | ||
export const useContextSelector = (context, selector) => { | ||
const contextValue = React.useContext(context); | ||
const { value: { current: value }, version: { current: version }, listeners, } = contextValue; | ||
const selected = selector(value); | ||
const [state, dispatch] = React.useReducer((prevState, payload) => { | ||
if (!payload) { | ||
// early bail out when is dispatched during render | ||
return [value, selected]; | ||
} | ||
if (payload[0] <= version) { | ||
if (objectIs(prevState[1], selected)) { | ||
return prevState; // bail out | ||
} | ||
return [value, selected]; | ||
} | ||
try { | ||
if (objectIs(prevState[0], payload[1])) { | ||
return prevState; // do not update | ||
} | ||
const nextSelected = selector(payload[1]); | ||
if (objectIs(prevState[1], nextSelected)) { | ||
return prevState; // do not update | ||
} | ||
return [payload[1], nextSelected]; | ||
} | ||
catch (e) { | ||
// ignored (stale props or some other reason) | ||
} | ||
// explicitly spread to enforce typing | ||
return [prevState[0], prevState[1]]; // schedule update | ||
}, [value, selected]); | ||
if (!objectIs(state[1], selected)) { | ||
// schedule re-render | ||
// this is safe because it's self contained | ||
dispatch(undefined); | ||
const contextValue = React.useContext(context); | ||
const { | ||
value: { | ||
current: value | ||
}, | ||
version: { | ||
current: version | ||
}, | ||
listeners | ||
} = contextValue; | ||
const selected = selector(value); | ||
const [state, dispatch] = React.useReducer((prevState, payload) => { | ||
if (!payload) { | ||
// early bail out when is dispatched during render | ||
return [value, selected]; | ||
} | ||
useIsomorphicLayoutEffect(() => { | ||
listeners.push(dispatch); | ||
return () => { | ||
const index = listeners.indexOf(dispatch); | ||
listeners.splice(index, 1); | ||
}; | ||
}, [listeners]); | ||
return state[1]; | ||
if (payload[0] <= version) { | ||
if (objectIs(prevState[1], selected)) { | ||
return prevState; // bail out | ||
} | ||
return [value, selected]; | ||
} | ||
try { | ||
if (objectIs(prevState[0], payload[1])) { | ||
return prevState; // do not update | ||
} | ||
const nextSelected = selector(payload[1]); | ||
if (objectIs(prevState[1], nextSelected)) { | ||
return prevState; // do not update | ||
} | ||
return [payload[1], nextSelected]; | ||
} catch (e) {// ignored (stale props or some other reason) | ||
} // explicitly spread to enforce typing | ||
return [prevState[0], prevState[1]]; // schedule update | ||
}, [value, selected]); | ||
if (!objectIs(state[1], selected)) { | ||
// schedule re-render | ||
// this is safe because it's self contained | ||
dispatch(undefined); | ||
} | ||
useIsomorphicLayoutEffect(() => { | ||
listeners.push(dispatch); | ||
return () => { | ||
const index = listeners.indexOf(dispatch); | ||
listeners.splice(index, 1); | ||
}; | ||
}, [listeners]); | ||
return state[1]; | ||
}; | ||
@@ -59,11 +75,12 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function is(x, y) { | ||
return ((x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare | ||
); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const objectIs = | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
} // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore fallback to native if it exists (not in IE11) | ||
typeof Object.is === 'function' ? Object.is : is; | ||
//# sourceMappingURL=useContextSelector.js.map |
@@ -9,9 +9,12 @@ import * as React from 'react'; | ||
*/ | ||
export function useHasParentContext(context) { | ||
const contextValue = React.useContext(context); | ||
if (contextValue.version) { | ||
return contextValue.version.current !== -1; | ||
} | ||
return false; | ||
const contextValue = React.useContext(context); | ||
if (contextValue.version) { | ||
return contextValue.version.current !== -1; | ||
} | ||
return false; | ||
} | ||
//# sourceMappingURL=useHasParentContext.js.map |
{ | ||
"name": "@fluentui/react-context-selector", | ||
"version": "0.0.0-nightlyed2d7c8d6320211111.1", | ||
"version": "0.0.0-nightlyf1be0a972820211214.1", | ||
"description": "React useContextSelector hook in userland", | ||
@@ -22,3 +22,4 @@ "main": "lib-commonjs/index.js", | ||
"docs": "api-extractor run --config=config/api-extractor.local.json --local", | ||
"build:local": "tsc -p . --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output dist/react-context-selector/src && yarn docs" | ||
"build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output ./dist/packages/react-context-selector/src && yarn docs", | ||
"type-check": "tsc -b tsconfig.json" | ||
}, | ||
@@ -38,3 +39,3 @@ "devDependencies": { | ||
"dependencies": { | ||
"@fluentui/react-utilities": "0.0.0-nightlyed2d7c8d6320211111.1", | ||
"@fluentui/react-utilities": "0.0.0-nightlyf1be0a972820211214.1", | ||
"scheduler": "^0.20.1", | ||
@@ -50,3 +51,2 @@ "tslib": "^2.1.0" | ||
"beachball": { | ||
"tag": "beta", | ||
"disallowedChangeTypes": [ | ||
@@ -53,0 +53,0 @@ "major", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94525
1508
+ Added@fluentui/keyboard-keys@0.0.0-nightlyf1be0a972820211214.1(transitive)
+ Added@fluentui/react-utilities@0.0.0-nightlyf1be0a972820211214.1(transitive)
- Removed@fluentui/keyboard-keys@0.0.0-nightlyed2d7c8d6320211111.1(transitive)
- Removed@fluentui/react-utilities@0.0.0-nightlyed2d7c8d6320211111.1(transitive)
Updated@fluentui/react-utilities@0.0.0-nightlyf1be0a972820211214.1