@fluentui/react-context-selector 9.1.60 → 9.1.62

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.md CHANGED
@@ -1,12 +1,30 @@
1
1
  # Change Log - @fluentui/react-context-selector
2
2
 
3
- This log was last generated on Mon, 20 May 2024 12:36:45 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 17 Jun 2024 07:31:06 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.1.62](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.62)
8
+
9
+ Mon, 17 Jun 2024 07:31:06 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.61..@fluentui/react-context-selector_v9.1.62)
11
+
12
+ ### Patches
13
+
14
+ - fix: useContextSelector with React 18 ([PR #30951](https://github.com/microsoft/fluentui/pull/30951) by olfedias@microsoft.com)
15
+
16
+ ## [9.1.61](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.61)
17
+
18
+ Thu, 06 Jun 2024 15:26:32 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.60..@fluentui/react-context-selector_v9.1.61)
20
+
21
+ ### Patches
22
+
23
+ - Bump @fluentui/react-utilities to v9.18.10 ([PR #31586](https://github.com/microsoft/fluentui/pull/31586) by beachball)
24
+
7
25
  ## [9.1.60](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.60)
8
26
 
9
- Mon, 20 May 2024 12:36:45 GMT
27
+ Mon, 20 May 2024 12:45:09 GMT
10
28
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.59..@fluentui/react-context-selector_v9.1.60)
11
29
 
12
30
  ### Patches
@@ -1,4 +1,4 @@
1
- import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
1
+ import { useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
2
2
  import * as React from 'react';
3
3
  /**
4
4
  * @internal
@@ -9,72 +9,65 @@ import * as React from 'react';
9
9
  const contextValue = React.useContext(context);
10
10
  const { value: { current: value }, version: { current: version }, listeners } = contextValue;
11
11
  const selected = selector(value);
12
- const [state, dispatch] = React.useReducer((prevState, payload)=>{
13
- if (!payload) {
14
- // early bail out when is dispatched during render
15
- return [
16
- value,
17
- selected
18
- ];
19
- }
20
- if (payload[0] <= version) {
21
- if (objectIs(prevState[1], selected)) {
22
- return prevState; // bail out
12
+ const [state, setState] = React.useState([
13
+ value,
14
+ selected
15
+ ]);
16
+ const dispatch = (payload)=>{
17
+ setState((prevState)=>{
18
+ if (!payload) {
19
+ // early bail out when is dispatched during render
20
+ return [
21
+ value,
22
+ selected
23
+ ];
23
24
  }
24
- return [
25
- value,
26
- selected
27
- ];
28
- }
29
- try {
30
- if (objectIs(prevState[0], payload[1])) {
31
- return prevState; // do not update
25
+ if (payload[0] <= version) {
26
+ if (Object.is(prevState[1], selected)) {
27
+ return prevState; // bail out
28
+ }
29
+ return [
30
+ value,
31
+ selected
32
+ ];
32
33
  }
33
- const nextSelected = selector(payload[1]);
34
- if (objectIs(prevState[1], nextSelected)) {
35
- return prevState; // do not update
34
+ try {
35
+ if (Object.is(prevState[0], payload[1])) {
36
+ return prevState; // do not update
37
+ }
38
+ const nextSelected = selector(payload[1]);
39
+ if (Object.is(prevState[1], nextSelected)) {
40
+ return prevState; // do not update
41
+ }
42
+ return [
43
+ payload[1],
44
+ nextSelected
45
+ ];
46
+ } catch (e) {
47
+ // ignored (stale props or some other reason)
36
48
  }
49
+ // explicitly spread to enforce typing
37
50
  return [
38
- payload[1],
39
- nextSelected
40
- ];
41
- } catch (e) {
42
- // ignored (stale props or some other reason)
43
- }
44
- // explicitly spread to enforce typing
45
- return [
46
- prevState[0],
47
- prevState[1]
48
- ]; // schedule update
49
- }, [
50
- value,
51
- selected
52
- ]);
53
- if (!objectIs(state[1], selected)) {
51
+ prevState[0],
52
+ prevState[1]
53
+ ]; // schedule update
54
+ });
55
+ };
56
+ if (!Object.is(state[1], selected)) {
54
57
  // schedule re-render
55
58
  // this is safe because it's self contained
56
59
  dispatch(undefined);
57
60
  }
61
+ const stableDispatch = useEventCallback(dispatch);
58
62
  useIsomorphicLayoutEffect(()=>{
59
- listeners.push(dispatch);
63
+ listeners.push(stableDispatch);
60
64
  return ()=>{
61
- const index = listeners.indexOf(dispatch);
65
+ const index = listeners.indexOf(stableDispatch);
62
66
  listeners.splice(index, 1);
63
67
  };
64
68
  }, [
69
+ stableDispatch,
65
70
  listeners
66
71
  ]);
67
72
  return state[1];
68
73
  };
69
- /**
70
- * inlined Object.is polyfill to avoid requiring consumers ship their own
71
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
72
- */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- function is(x, y) {
74
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
75
- ;
76
- }
77
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
- const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment
79
- // @ts-ignore fallback to native if it exists (not in IE11)
80
- typeof Object.is === 'function' ? Object.is : is;
@@ -1 +1 @@
1
- {"version":3,"sources":["useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"],"names":["useIsomorphicLayoutEffect","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","push","index","indexOf","splice","is","x","y","Object"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,4BAA4B;AACtE,YAAYC,WAAW,QAAQ;AAa/B;;;;;CAKC,GACD,OAAO,MAAMC,qBAAqB,CAChCC,SACAC;IAEA,MAAMC,eAAeJ,MAAMK,UAAU,CAACH;IAEtC,MAAM,EACJI,OAAO,EAAEC,SAASD,KAAK,EAAE,EACzBE,SAAS,EAAED,SAASC,OAAO,EAAE,EAC7BC,SAAS,EACV,GAAGL;IACJ,MAAMM,WAAWP,SAASG;IAE1B,MAAM,CAACK,OAAOC,SAAS,GAAGZ,MAAMa,UAAU,CACxC,CACEC,WACAC;QAIA,IAAI,CAACA,SAAS;YACZ,kDAAkD;YAClD,OAAO;gBAACT;gBAAOI;aAAS;QAC1B;QAEA,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;YACzB,IAAIQ,SAASF,SAAS,CAAC,EAAE,EAAEJ,WAAW;gBACpC,OAAOI,WAAW,WAAW;YAC/B;YAEA,OAAO;gBAACR;gBAAOI;aAAS;QAC1B;QAEA,IAAI;YACF,IAAIM,SAASF,SAAS,CAAC,EAAE,EAAEC,OAAO,CAAC,EAAE,GAAG;gBACtC,OAAOD,WAAW,gBAAgB;YACpC;YAEA,MAAMG,eAAed,SAASY,OAAO,CAAC,EAAE;YAExC,IAAIC,SAASF,SAAS,CAAC,EAAE,EAAEG,eAAe;gBACxC,OAAOH,WAAW,gBAAgB;YACpC;YAEA,OAAO;gBAACC,OAAO,CAAC,EAAE;gBAAEE;aAAa;QACnC,EAAE,OAAOC,GAAG;QACV,6CAA6C;QAC/C;QAEA,sCAAsC;QACtC,OAAO;YAACJ,SAAS,CAAC,EAAE;YAAEA,SAAS,CAAC,EAAE;SAAC,EAAW,kBAAkB;IAClE,GACA;QAACR;QAAOI;KAAS;IAGnB,IAAI,CAACM,SAASL,KAAK,CAAC,EAAE,EAAED,WAAW;QACjC,qBAAqB;QACrB,2CAA2C;QAC3CE,SAASO;IACX;IAEApB,0BAA0B;QACxBU,UAAUW,IAAI,CAACR;QAEf,OAAO;YACL,MAAMS,QAAQZ,UAAUa,OAAO,CAACV;YAChCH,UAAUc,MAAM,CAACF,OAAO;QAC1B;IACF,GAAG;QAACZ;KAAU;IAEd,OAAOE,KAAK,CAAC,EAAE;AACjB,EAAE;AAEF;;;CAGC,GACD,8DAA8D;AAC9D,SAASa,GAAGC,CAAM,EAAEC,CAAM;IACxB,OACE,AAACD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAQD,MAAMA,KAAKC,MAAMA,EAAG,sCAAsC;;AAE5G;AAEA,8DAA8D;AAC9D,MAAMV,WACJ,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAOW,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA"}
1
+ {"version":3,"sources":["useContextSelector.ts"],"sourcesContent":["import { useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, setState] = React.useState<readonly [Value, SelectedValue]>([value, selected]);\n const dispatch = (\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ) => {\n setState(prevState => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (Object.is(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (Object.is(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (Object.is(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n });\n };\n\n if (!Object.is(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n const stableDispatch = useEventCallback(dispatch);\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(stableDispatch);\n\n return () => {\n const index = listeners.indexOf(stableDispatch);\n listeners.splice(index, 1);\n };\n }, [stableDispatch, listeners]);\n\n return state[1] as SelectedValue;\n};\n"],"names":["useEventCallback","useIsomorphicLayoutEffect","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","setState","useState","dispatch","payload","prevState","Object","is","nextSelected","e","undefined","stableDispatch","push","index","indexOf","splice"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,4BAA4B;AACxF,YAAYC,WAAW,QAAQ;AAI/B;;;;;CAKC,GACD,OAAO,MAAMC,qBAAqB,CAChCC,SACAC;IAEA,MAAMC,eAAeJ,MAAMK,UAAU,CAACH;IAEtC,MAAM,EACJI,OAAO,EAAEC,SAASD,KAAK,EAAE,EACzBE,SAAS,EAAED,SAASC,OAAO,EAAE,EAC7BC,SAAS,EACV,GAAGL;IACJ,MAAMM,WAAWP,SAASG;IAE1B,MAAM,CAACK,OAAOC,SAAS,GAAGZ,MAAMa,QAAQ,CAAkC;QAACP;QAAOI;KAAS;IAC3F,MAAMI,WAAW,CACfC;QAIAH,SAASI,CAAAA;YACP,IAAI,CAACD,SAAS;gBACZ,kDAAkD;gBAClD,OAAO;oBAACT;oBAAOI;iBAAS;YAC1B;YAEA,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;gBACzB,IAAIS,OAAOC,EAAE,CAACF,SAAS,CAAC,EAAE,EAAEN,WAAW;oBACrC,OAAOM,WAAW,WAAW;gBAC/B;gBAEA,OAAO;oBAACV;oBAAOI;iBAAS;YAC1B;YAEA,IAAI;gBACF,IAAIO,OAAOC,EAAE,CAACF,SAAS,CAAC,EAAE,EAAED,OAAO,CAAC,EAAE,GAAG;oBACvC,OAAOC,WAAW,gBAAgB;gBACpC;gBAEA,MAAMG,eAAehB,SAASY,OAAO,CAAC,EAAE;gBAExC,IAAIE,OAAOC,EAAE,CAACF,SAAS,CAAC,EAAE,EAAEG,eAAe;oBACzC,OAAOH,WAAW,gBAAgB;gBACpC;gBAEA,OAAO;oBAACD,OAAO,CAAC,EAAE;oBAAEI;iBAAa;YACnC,EAAE,OAAOC,GAAG;YACV,6CAA6C;YAC/C;YAEA,sCAAsC;YACtC,OAAO;gBAACJ,SAAS,CAAC,EAAE;gBAAEA,SAAS,CAAC,EAAE;aAAC,EAAW,kBAAkB;QAClE;IACF;IAEA,IAAI,CAACC,OAAOC,EAAE,CAACP,KAAK,CAAC,EAAE,EAAED,WAAW;QAClC,qBAAqB;QACrB,2CAA2C;QAC3CI,SAASO;IACX;IAEA,MAAMC,iBAAiBxB,iBAAiBgB;IAExCf,0BAA0B;QACxBU,UAAUc,IAAI,CAACD;QAEf,OAAO;YACL,MAAME,QAAQf,UAAUgB,OAAO,CAACH;YAChCb,UAAUiB,MAAM,CAACF,OAAO;QAC1B;IACF,GAAG;QAACF;QAAgBb;KAAU;IAE9B,OAAOE,KAAK,CAAC,EAAE;AACjB,EAAE"}
@@ -15,71 +15,65 @@ const useContextSelector = (context, selector)=>{
15
15
  const contextValue = _react.useContext(context);
16
16
  const { value: { current: value }, version: { current: version }, listeners } = contextValue;
17
17
  const selected = selector(value);
18
- const [state, dispatch] = _react.useReducer((prevState, payload)=>{
19
- if (!payload) {
20
- // early bail out when is dispatched during render
21
- return [
22
- value,
23
- selected
24
- ];
25
- }
26
- if (payload[0] <= version) {
27
- if (objectIs(prevState[1], selected)) {
28
- return prevState; // bail out
18
+ const [state, setState] = _react.useState([
19
+ value,
20
+ selected
21
+ ]);
22
+ const dispatch = (payload)=>{
23
+ setState((prevState)=>{
24
+ if (!payload) {
25
+ // early bail out when is dispatched during render
26
+ return [
27
+ value,
28
+ selected
29
+ ];
29
30
  }
30
- return [
31
- value,
32
- selected
33
- ];
34
- }
35
- try {
36
- if (objectIs(prevState[0], payload[1])) {
37
- return prevState; // do not update
31
+ if (payload[0] <= version) {
32
+ if (Object.is(prevState[1], selected)) {
33
+ return prevState; // bail out
34
+ }
35
+ return [
36
+ value,
37
+ selected
38
+ ];
38
39
  }
39
- const nextSelected = selector(payload[1]);
40
- if (objectIs(prevState[1], nextSelected)) {
41
- return prevState; // do not update
40
+ try {
41
+ if (Object.is(prevState[0], payload[1])) {
42
+ return prevState; // do not update
43
+ }
44
+ const nextSelected = selector(payload[1]);
45
+ if (Object.is(prevState[1], nextSelected)) {
46
+ return prevState; // do not update
47
+ }
48
+ return [
49
+ payload[1],
50
+ nextSelected
51
+ ];
52
+ } catch (e) {
53
+ // ignored (stale props or some other reason)
42
54
  }
55
+ // explicitly spread to enforce typing
43
56
  return [
44
- payload[1],
45
- nextSelected
46
- ];
47
- } catch (e) {
48
- // ignored (stale props or some other reason)
49
- }
50
- // explicitly spread to enforce typing
51
- return [
52
- prevState[0],
53
- prevState[1]
54
- ]; // schedule update
55
- }, [
56
- value,
57
- selected
58
- ]);
59
- if (!objectIs(state[1], selected)) {
57
+ prevState[0],
58
+ prevState[1]
59
+ ]; // schedule update
60
+ });
61
+ };
62
+ if (!Object.is(state[1], selected)) {
60
63
  // schedule re-render
61
64
  // this is safe because it's self contained
62
65
  dispatch(undefined);
63
66
  }
67
+ const stableDispatch = (0, _reactutilities.useEventCallback)(dispatch);
64
68
  (0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
65
- listeners.push(dispatch);
69
+ listeners.push(stableDispatch);
66
70
  return ()=>{
67
- const index = listeners.indexOf(dispatch);
71
+ const index = listeners.indexOf(stableDispatch);
68
72
  listeners.splice(index, 1);
69
73
  };
70
74
  }, [
75
+ stableDispatch,
71
76
  listeners
72
77
  ]);
73
78
  return state[1];
74
79
  };
75
- /**
76
- * inlined Object.is polyfill to avoid requiring consumers ship their own
77
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
78
- */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
- function is(x, y) {
80
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
81
- ;
82
- }
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- const objectIs = // @ts-ignore fallback to native if it exists (not in IE11)
85
- typeof Object.is === 'function' ? Object.is : is;
@@ -1 +1 @@
1
- {"version":3,"sources":["useContextSelector.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */ export const useContextSelector = (context, selector)=>{\n const contextValue = React.useContext(context);\n const { value: { current: value }, version: { current: version }, listeners } = contextValue;\n const selected = selector(value);\n const [state, dispatch] = React.useReducer((prevState, payload)=>{\n if (!payload) {\n // early bail out when is dispatched during render\n return [\n value,\n selected\n ];\n }\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n return [\n value,\n selected\n ];\n }\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n const nextSelected = selector(payload[1]);\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n return [\n payload[1],\n nextSelected\n ];\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n // explicitly spread to enforce typing\n return [\n prevState[0],\n prevState[1]\n ]; // schedule update\n }, [\n value,\n selected\n ]);\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n useIsomorphicLayoutEffect(()=>{\n listeners.push(dispatch);\n return ()=>{\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [\n listeners\n ]);\n return state[1];\n};\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */ // eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore fallback to native if it exists (not in IE11)\ntypeof Object.is === 'function' ? Object.is : is;\n"],"names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","is","x","y","Object"],"mappings":";;;;+BAOiBA;;;eAAAA;;;;gCAPyB;iEACnB;AAMZ,MAAMA,qBAAqB,CAACC,SAASC;IAC5C,MAAMC,eAAeC,OAAMC,UAAU,CAACJ;IACtC,MAAM,EAAEK,OAAO,EAAEC,SAASD,KAAK,EAAE,EAAEE,SAAS,EAAED,SAASC,OAAO,EAAE,EAAEC,SAAS,EAAE,GAAGN;IAChF,MAAMO,WAAWR,SAASI;IAC1B,MAAM,CAACK,OAAOC,SAAS,GAAGR,OAAMS,UAAU,CAAC,CAACC,WAAWC;QACnD,IAAI,CAACA,SAAS;YACV,kDAAkD;YAClD,OAAO;gBACHT;gBACAI;aACH;QACL;QACA,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;YACvB,IAAIQ,SAASF,SAAS,CAAC,EAAE,EAAEJ,WAAW;gBAClC,OAAOI,WAAW,WAAW;YACjC;YACA,OAAO;gBACHR;gBACAI;aACH;QACL;QACA,IAAI;YACA,IAAIM,SAASF,SAAS,CAAC,EAAE,EAAEC,OAAO,CAAC,EAAE,GAAG;gBACpC,OAAOD,WAAW,gBAAgB;YACtC;YACA,MAAMG,eAAef,SAASa,OAAO,CAAC,EAAE;YACxC,IAAIC,SAASF,SAAS,CAAC,EAAE,EAAEG,eAAe;gBACtC,OAAOH,WAAW,gBAAgB;YACtC;YACA,OAAO;gBACHC,OAAO,CAAC,EAAE;gBACVE;aACH;QACL,EAAE,OAAOC,GAAG;QACZ,6CAA6C;QAC7C;QACA,sCAAsC;QACtC,OAAO;YACHJ,SAAS,CAAC,EAAE;YACZA,SAAS,CAAC,EAAE;SACf,EAAE,kBAAkB;IACzB,GAAG;QACCR;QACAI;KACH;IACD,IAAI,CAACM,SAASL,KAAK,CAAC,EAAE,EAAED,WAAW;QAC/B,qBAAqB;QACrB,2CAA2C;QAC3CE,SAASO;IACb;IACAC,IAAAA,yCAAyB,EAAC;QACtBX,UAAUY,IAAI,CAACT;QACf,OAAO;YACH,MAAMU,QAAQb,UAAUc,OAAO,CAACX;YAChCH,UAAUe,MAAM,CAACF,OAAO;QAC5B;IACJ,GAAG;QACCb;KACH;IACD,OAAOE,KAAK,CAAC,EAAE;AACnB;AACA;;;CAGC,GAAG,8DAA8D;AAClE,SAASc,GAAGC,CAAC,EAAEC,CAAC;IACZ,OAAOD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAMD,MAAMA,KAAKC,MAAMA,EAAE,sCAAsC;;AAE/G;AACA,8DAA8D;AAC9D,MAAMX,WACN,2DAA2D;AAC3D,OAAOY,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA"}
1
+ {"version":3,"sources":["useContextSelector.js"],"sourcesContent":["import { useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */ export const useContextSelector = (context, selector)=>{\n const contextValue = React.useContext(context);\n const { value: { current: value }, version: { current: version }, listeners } = contextValue;\n const selected = selector(value);\n const [state, setState] = React.useState([\n value,\n selected\n ]);\n const dispatch = (payload)=>{\n setState((prevState)=>{\n if (!payload) {\n // early bail out when is dispatched during render\n return [\n value,\n selected\n ];\n }\n if (payload[0] <= version) {\n if (Object.is(prevState[1], selected)) {\n return prevState; // bail out\n }\n return [\n value,\n selected\n ];\n }\n try {\n if (Object.is(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n const nextSelected = selector(payload[1]);\n if (Object.is(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n return [\n payload[1],\n nextSelected\n ];\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n // explicitly spread to enforce typing\n return [\n prevState[0],\n prevState[1]\n ]; // schedule update\n });\n };\n if (!Object.is(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n const stableDispatch = useEventCallback(dispatch);\n useIsomorphicLayoutEffect(()=>{\n listeners.push(stableDispatch);\n return ()=>{\n const index = listeners.indexOf(stableDispatch);\n listeners.splice(index, 1);\n };\n }, [\n stableDispatch,\n listeners\n ]);\n return state[1];\n};\n"],"names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","setState","useState","dispatch","payload","prevState","Object","is","nextSelected","e","undefined","stableDispatch","useEventCallback","useIsomorphicLayoutEffect","push","index","indexOf","splice"],"mappings":";;;;+BAOiBA;;;eAAAA;;;;gCAP2C;iEACrC;AAMZ,MAAMA,qBAAqB,CAACC,SAASC;IAC5C,MAAMC,eAAeC,OAAMC,UAAU,CAACJ;IACtC,MAAM,EAAEK,OAAO,EAAEC,SAASD,KAAK,EAAE,EAAEE,SAAS,EAAED,SAASC,OAAO,EAAE,EAAEC,SAAS,EAAE,GAAGN;IAChF,MAAMO,WAAWR,SAASI;IAC1B,MAAM,CAACK,OAAOC,SAAS,GAAGR,OAAMS,QAAQ,CAAC;QACrCP;QACAI;KACH;IACD,MAAMI,WAAW,CAACC;QACdH,SAAS,CAACI;YACN,IAAI,CAACD,SAAS;gBACV,kDAAkD;gBAClD,OAAO;oBACHT;oBACAI;iBACH;YACL;YACA,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;gBACvB,IAAIS,OAAOC,EAAE,CAACF,SAAS,CAAC,EAAE,EAAEN,WAAW;oBACnC,OAAOM,WAAW,WAAW;gBACjC;gBACA,OAAO;oBACHV;oBACAI;iBACH;YACL;YACA,IAAI;gBACA,IAAIO,OAAOC,EAAE,CAACF,SAAS,CAAC,EAAE,EAAED,OAAO,CAAC,EAAE,GAAG;oBACrC,OAAOC,WAAW,gBAAgB;gBACtC;gBACA,MAAMG,eAAejB,SAASa,OAAO,CAAC,EAAE;gBACxC,IAAIE,OAAOC,EAAE,CAACF,SAAS,CAAC,EAAE,EAAEG,eAAe;oBACvC,OAAOH,WAAW,gBAAgB;gBACtC;gBACA,OAAO;oBACHD,OAAO,CAAC,EAAE;oBACVI;iBACH;YACL,EAAE,OAAOC,GAAG;YACZ,6CAA6C;YAC7C;YACA,sCAAsC;YACtC,OAAO;gBACHJ,SAAS,CAAC,EAAE;gBACZA,SAAS,CAAC,EAAE;aACf,EAAE,kBAAkB;QACzB;IACJ;IACA,IAAI,CAACC,OAAOC,EAAE,CAACP,KAAK,CAAC,EAAE,EAAED,WAAW;QAChC,qBAAqB;QACrB,2CAA2C;QAC3CI,SAASO;IACb;IACA,MAAMC,iBAAiBC,IAAAA,gCAAgB,EAACT;IACxCU,IAAAA,yCAAyB,EAAC;QACtBf,UAAUgB,IAAI,CAACH;QACf,OAAO;YACH,MAAMI,QAAQjB,UAAUkB,OAAO,CAACL;YAChCb,UAAUmB,MAAM,CAACF,OAAO;QAC5B;IACJ,GAAG;QACCJ;QACAb;KACH;IACD,OAAOE,KAAK,CAAC,EAAE;AACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-context-selector",
3
- "version": "9.1.60",
3
+ "version": "9.1.62",
4
4
  "description": "React useContextSelector hook in userland",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -18,7 +18,7 @@
18
18
  "just": "just-scripts",
19
19
  "lint": "just-scripts lint",
20
20
  "test": "jest --passWithNoTests",
21
- "type-check": "tsc -b tsconfig.json",
21
+ "type-check": "just-scripts type-check",
22
22
  "generate-api": "just-scripts generate-api",
23
23
  "test-ssr": "test-ssr \"./stories/**/*.stories.tsx\""
24
24
  },
@@ -28,7 +28,7 @@
28
28
  "@fluentui/scripts-tasks": "*"
29
29
  },
30
30
  "dependencies": {
31
- "@fluentui/react-utilities": "^9.18.9",
31
+ "@fluentui/react-utilities": "^9.18.10",
32
32
  "@swc/helpers": "^0.5.1"
33
33
  },
34
34
  "peerDependencies": {