@contember/react-binding 2.0.0-alpha.10 → 2.0.0-alpha.12

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.
Files changed (34) hide show
  1. package/dist/development/src/accessorPropagation/EnvironmentContext.cjs +6 -5
  2. package/dist/development/src/accessorPropagation/EnvironmentContext.cjs.map +1 -1
  3. package/dist/development/src/accessorPropagation/EnvironmentContext.js +7 -6
  4. package/dist/development/src/accessorPropagation/EnvironmentContext.js.map +1 -1
  5. package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.cjs +35 -11
  6. package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.cjs.map +1 -1
  7. package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.js +36 -12
  8. package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.js.map +1 -1
  9. package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.cjs +32 -11
  10. package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.cjs.map +1 -1
  11. package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.js +33 -12
  12. package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.js.map +1 -1
  13. package/dist/production/src/accessorPropagation/EnvironmentContext.cjs +2 -1
  14. package/dist/production/src/accessorPropagation/EnvironmentContext.cjs.map +1 -1
  15. package/dist/production/src/accessorPropagation/EnvironmentContext.js +3 -2
  16. package/dist/production/src/accessorPropagation/EnvironmentContext.js.map +1 -1
  17. package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.cjs +35 -11
  18. package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.cjs.map +1 -1
  19. package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.js +36 -12
  20. package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.js.map +1 -1
  21. package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.cjs +32 -11
  22. package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.cjs.map +1 -1
  23. package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.js +33 -12
  24. package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.js.map +1 -1
  25. package/dist/types/accessorPropagation/EnvironmentContext.d.ts.map +1 -1
  26. package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts +31 -5
  27. package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts.map +1 -1
  28. package/dist/types/accessorPropagation/useEntitySubTreeLoader.d.ts +32 -5
  29. package/dist/types/accessorPropagation/useEntitySubTreeLoader.d.ts.map +1 -1
  30. package/dist/types/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +7 -7
  32. package/src/accessorPropagation/EnvironmentContext.tsx +4 -2
  33. package/src/accessorPropagation/useEntityListSubTreeLoader.ts +78 -24
  34. package/src/accessorPropagation/useEntitySubTreeLoader.ts +76 -24
@@ -10,9 +10,10 @@ EnvironmentContext.displayName = "EnvironmentContext";
10
10
  const EnvironmentMiddleware = Component.Component(
11
11
  ({ children, create }) => {
12
12
  const env = useEnvironment.useEnvironment();
13
- return /* @__PURE__ */ jsxDevRuntime.jsxDEV(EnvironmentContext.Provider, { value: create(env), children }, void 0, false, {
13
+ const envWithExtension = React.useMemo(() => create(env), [env, create]);
14
+ return /* @__PURE__ */ jsxDevRuntime.jsxDEV(EnvironmentContext.Provider, { value: envWithExtension, children }, void 0, false, {
14
15
  fileName: "/home/runner/work/contember/contember/packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx",
15
- lineNumber: 17,
16
+ lineNumber: 19,
16
17
  columnNumber: 10
17
18
  }, void 0);
18
19
  },
@@ -20,7 +21,7 @@ const EnvironmentMiddleware = Component.Component(
20
21
  staticRender: ({ children }) => {
21
22
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children }, void 0, false, {
22
23
  fileName: "/home/runner/work/contember/contember/packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx",
23
- lineNumber: 21,
24
+ lineNumber: 23,
24
25
  columnNumber: 11
25
26
  }, void 0);
26
27
  },
@@ -34,7 +35,7 @@ const EnvironmentExtensionProvider = Component.Component(
34
35
  const create = React.useCallback((env) => env.withExtension(extension, state), [extension, state]);
35
36
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(EnvironmentMiddleware, { create, children }, void 0, false, {
36
37
  fileName: "/home/runner/work/contember/contember/packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx",
37
- lineNumber: 38,
38
+ lineNumber: 40,
38
39
  columnNumber: 10
39
40
  }, void 0);
40
41
  },
@@ -42,7 +43,7 @@ const EnvironmentExtensionProvider = Component.Component(
42
43
  const create = (env) => env.withExtension(extension, state);
43
44
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(EnvironmentMiddleware, { create, children }, void 0, false, {
44
45
  fileName: "/home/runner/work/contember/contember/packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx",
45
- lineNumber: 42,
46
+ lineNumber: 44,
46
47
  columnNumber: 10
47
48
  }, void 0);
48
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentContext.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }: EnvironmentMiddlewareProps) => {\n\t\tconst env = useEnvironment()\n\t\treturn <EnvironmentContext.Provider value={create(env)}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create }, env) => {\n\t\t\treturn create(env)\n\t\t},\n\t},\n)\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":["createContext","Environment","Component","useEnvironment","jsxDEV","this","useCallback"],"mappings":";;;;;;;AAKO,MAAM,qBAAqBA,MAAA,cAA2BC,oBAAY,QAAQ;AACjF,mBAAmB,cAAc;AAO1B,MAAM,wBAAwBC,UAAA;AAAA,EACpC,CAAC,EAAE,UAAU,aAAyC;AACrD,UAAM,MAAMC,eAAAA;AACL,WAAAC,qCAAC,mBAAmB,UAAnB,EAA4B,OAAO,OAAO,GAAG,GAAI,SAAlD,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAA2D,GAAAC,MAAA;AAAA,EACnE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,4EAAU,SAAH,GAAA,QAAA,OAAA;AAAA,QAAA,UAAA;AAAA,QAAA,YAAA;AAAA,QAAA,cAAA;AAAA,MAAY,GAAAA,MAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,UAAU,QAAQ;AACzC,aAAO,OAAO,GAAG;AAAA,IAClB;AAAA,EACD;AACD;AAQO,MAAM,+BAAgGH,UAAA;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAASI,MAAAA,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAAF,8BAAAA,OAAC,uBAAsB,EAAA,QAAiB,YAAxC,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAiD,GAAAC,MAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAAD,8BAAAA,OAAC,uBAAsB,EAAA,QAAiB,YAAxC,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAiD,GAAAC,MAAA;AAAA,EACzD;AACD;;;;"}
1
+ {"version":3,"file":"EnvironmentContext.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback, useMemo } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }: EnvironmentMiddlewareProps) => {\n\t\tconst env = useEnvironment()\n\t\tconst envWithExtension = useMemo(() => create(env), [env, create])\n\n\t\treturn <EnvironmentContext.Provider value={envWithExtension}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create }, env) => {\n\t\t\treturn create(env)\n\t\t},\n\t},\n)\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":["createContext","Environment","Component","useEnvironment","useMemo","this","useCallback","jsxDEV"],"mappings":";;;;;;;AAKO,MAAM,qBAAqBA,MAAA,cAA2BC,oBAAY,QAAQ;AACjF,mBAAmB,cAAc;AAO1B,MAAM,wBAAwBC,UAAA;AAAA,EACpC,CAAC,EAAE,UAAU,aAAyC;AACrD,UAAM,MAAMC,eAAAA;AACN,UAAA,mBAAmBC,cAAQ,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,MAAM,CAAC;AAEjE,gDAAQ,mBAAmB,UAAnB,EAA4B,OAAO,kBAAmB,SAAvD,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAgE,GAAAC,MAAA;AAAA,EACxE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,4EAAU,SAAH,GAAA,QAAA,OAAA;AAAA,QAAA,UAAA;AAAA,QAAA,YAAA;AAAA,QAAA,cAAA;AAAA,MAAY,GAAAA,MAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,UAAU,QAAQ;AACzC,aAAO,OAAO,GAAG;AAAA,IAClB;AAAA,EACD;AACD;AAQO,MAAM,+BAAgGH,UAAA;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAASI,MAAAA,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAAC,8BAAAA,OAAC,uBAAsB,EAAA,QAAiB,YAAxC,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAiD,GAAAF,MAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAAE,8BAAAA,OAAC,uBAAsB,EAAA,QAAiB,YAAxC,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAiD,GAAAF,MAAA;AAAA,EACzD;AACD;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
2
- import { createContext, useCallback } from "react";
2
+ import { createContext, useMemo, useCallback } from "react";
3
3
  import { Environment } from "@contember/binding";
4
4
  import { useEnvironment } from "./useEnvironment.js";
5
5
  import { Component } from "../coreComponents/Component.js";
@@ -8,9 +8,10 @@ EnvironmentContext.displayName = "EnvironmentContext";
8
8
  const EnvironmentMiddleware = Component(
9
9
  ({ children, create }) => {
10
10
  const env = useEnvironment();
11
- return /* @__PURE__ */ jsxDEV(EnvironmentContext.Provider, { value: create(env), children }, void 0, false, {
11
+ const envWithExtension = useMemo(() => create(env), [env, create]);
12
+ return /* @__PURE__ */ jsxDEV(EnvironmentContext.Provider, { value: envWithExtension, children }, void 0, false, {
12
13
  fileName: "/home/runner/work/contember/contember/packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx",
13
- lineNumber: 17,
14
+ lineNumber: 19,
14
15
  columnNumber: 10
15
16
  }, void 0);
16
17
  },
@@ -18,7 +19,7 @@ const EnvironmentMiddleware = Component(
18
19
  staticRender: ({ children }) => {
19
20
  return /* @__PURE__ */ jsxDEV(Fragment, { children }, void 0, false, {
20
21
  fileName: "/home/runner/work/contember/contember/packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx",
21
- lineNumber: 21,
22
+ lineNumber: 23,
22
23
  columnNumber: 11
23
24
  }, void 0);
24
25
  },
@@ -32,7 +33,7 @@ const EnvironmentExtensionProvider = Component(
32
33
  const create = useCallback((env) => env.withExtension(extension, state), [extension, state]);
33
34
  return /* @__PURE__ */ jsxDEV(EnvironmentMiddleware, { create, children }, void 0, false, {
34
35
  fileName: "/home/runner/work/contember/contember/packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx",
35
- lineNumber: 38,
36
+ lineNumber: 40,
36
37
  columnNumber: 10
37
38
  }, void 0);
38
39
  },
@@ -40,7 +41,7 @@ const EnvironmentExtensionProvider = Component(
40
41
  const create = (env) => env.withExtension(extension, state);
41
42
  return /* @__PURE__ */ jsxDEV(EnvironmentMiddleware, { create, children }, void 0, false, {
42
43
  fileName: "/home/runner/work/contember/contember/packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx",
43
- lineNumber: 42,
44
+ lineNumber: 44,
44
45
  columnNumber: 10
45
46
  }, void 0);
46
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentContext.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }: EnvironmentMiddlewareProps) => {\n\t\tconst env = useEnvironment()\n\t\treturn <EnvironmentContext.Provider value={create(env)}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create }, env) => {\n\t\t\treturn create(env)\n\t\t},\n\t},\n)\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":["this"],"mappings":";;;;;AAKO,MAAM,qBAAqB,cAA2B,YAAY,QAAQ;AACjF,mBAAmB,cAAc;AAO1B,MAAM,wBAAwB;AAAA,EACpC,CAAC,EAAE,UAAU,aAAyC;AACrD,UAAM,MAAM;AACL,WAAA,uBAAC,mBAAmB,UAAnB,EAA4B,OAAO,OAAO,GAAG,GAAI,SAAlD,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAA2D,GAAAA,MAAA;AAAA,EACnE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,gDAAU,SAAH,GAAA,QAAA,OAAA;AAAA,QAAA,UAAA;AAAA,QAAA,YAAA;AAAA,QAAA,cAAA;AAAA,MAAY,GAAAA,MAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,UAAU,QAAQ;AACzC,aAAO,OAAO,GAAG;AAAA,IAClB;AAAA,EACD;AACD;AAQO,MAAM,+BAAgG;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAA,uBAAC,uBAAsB,EAAA,QAAiB,YAAxC,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAiD,GAAAA,MAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAA,uBAAC,uBAAsB,EAAA,QAAiB,YAAxC,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAiD,GAAAA,MAAA;AAAA,EACzD;AACD;"}
1
+ {"version":3,"file":"EnvironmentContext.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback, useMemo } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }: EnvironmentMiddlewareProps) => {\n\t\tconst env = useEnvironment()\n\t\tconst envWithExtension = useMemo(() => create(env), [env, create])\n\n\t\treturn <EnvironmentContext.Provider value={envWithExtension}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create }, env) => {\n\t\t\treturn create(env)\n\t\t},\n\t},\n)\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":["this"],"mappings":";;;;;AAKO,MAAM,qBAAqB,cAA2B,YAAY,QAAQ;AACjF,mBAAmB,cAAc;AAO1B,MAAM,wBAAwB;AAAA,EACpC,CAAC,EAAE,UAAU,aAAyC;AACrD,UAAM,MAAM;AACN,UAAA,mBAAmB,QAAQ,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,MAAM,CAAC;AAEjE,kCAAQ,mBAAmB,UAAnB,EAA4B,OAAO,kBAAmB,SAAvD,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAgE,GAAAA,MAAA;AAAA,EACxE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,gDAAU,SAAH,GAAA,QAAA,OAAA;AAAA,QAAA,UAAA;AAAA,QAAA,YAAA;AAAA,QAAA,cAAA;AAAA,MAAY,GAAAA,MAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,UAAU,QAAQ;AACzC,aAAO,OAAO,GAAG;AAAA,IAClB;AAAA,EACD;AACD;AAQO,MAAM,+BAAgG;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAA,uBAAC,uBAAsB,EAAA,QAAiB,YAAxC,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAiD,GAAAA,MAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAA,uBAAC,uBAAsB,EAAA,QAAiB,YAAxC,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAiD,GAAAA,MAAA;AAAA,EACzD;AACD;"}
@@ -5,43 +5,67 @@ const useExtendTree = require("./useExtendTree.cjs");
5
5
  const EntityListSubTree = require("../coreComponents/EntityListSubTree.cjs");
6
6
  const useEntityListSubTreeLoader = (entities, children, state) => {
7
7
  const [displayedState, setDisplayedState] = React.useState({
8
+ state: "initial",
9
+ isLoading: false,
8
10
  entities: void 0,
9
11
  treeRootId: void 0,
10
- state: void 0
12
+ customState: void 0
11
13
  });
12
14
  const currentlyLoading = React.useRef();
13
- const [loadingState, setLoadingState] = React.useState("initial");
14
15
  const extendTree = useExtendTree.useExtendTree();
16
+ const [reloadTrigger, setReloadTrigger] = React.useState(null);
15
17
  React.useEffect(() => {
16
18
  (async () => {
17
- if (!entities || displayedState.state === state && displayedState.entities === entities || currentlyLoading.current?.entities === entities && currentlyLoading.current?.state === state) {
19
+ if (!entities) {
18
20
  return;
19
21
  }
20
22
  currentlyLoading.current = {
21
23
  entities,
22
24
  state
23
25
  };
24
- if (displayedState.entities) {
25
- setLoadingState("refreshing");
26
- }
26
+ setDisplayedState((it) => {
27
+ if (it.state === "initial" || it.state === "loading") {
28
+ return {
29
+ ...it,
30
+ isLoading: true,
31
+ state: "loading"
32
+ };
33
+ } else {
34
+ return {
35
+ ...it,
36
+ isLoading: true,
37
+ state: "refreshing"
38
+ };
39
+ }
40
+ });
27
41
  const newTreeRootId = await extendTree(
28
42
  React.createElement(EntityListSubTree.EntityListSubTree, {
29
43
  ...entities,
30
44
  children
31
- })
45
+ }),
46
+ { force: reloadTrigger !== null }
32
47
  );
48
+ if (currentlyLoading.current?.entities !== entities || currentlyLoading.current?.state !== state) {
49
+ return;
50
+ }
33
51
  currentlyLoading.current = void 0;
34
52
  if (newTreeRootId) {
35
53
  setDisplayedState({
36
54
  entities,
37
55
  treeRootId: newTreeRootId,
38
- state
56
+ state: "loaded",
57
+ customState: state,
58
+ isLoading: false
39
59
  });
40
- setLoadingState("loaded");
41
60
  }
42
61
  })();
43
- }, [displayedState, extendTree, entities, children, state]);
44
- return [displayedState, loadingState];
62
+ }, [extendTree, entities, children, state, reloadTrigger]);
63
+ return [
64
+ displayedState,
65
+ {
66
+ reload: React.useCallback(() => setReloadTrigger({}), [])
67
+ }
68
+ ];
45
69
  };
46
70
  exports.useEntityListSubTreeLoader = useEntityListSubTreeLoader;
47
71
  //# sourceMappingURL=useEntityListSubTreeLoader.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useEntityListSubTreeLoader.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityListSubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedEntityList, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntityListSubTree } from '../coreComponents'\n\nexport type UseEntityListSubTreeLoaderResult<State> = {\n\tentities: SugaredQualifiedEntityList | undefined\n\ttreeRootId: TreeRootId | undefined\n\tstate: State | undefined\n}\n\nexport type EntityListSubTreeLoaderState =\n\t| 'initial'\n\t| 'refreshing'\n\t| 'loaded'\n\nexport const useEntityListSubTreeLoader = <State>(entities: SugaredQualifiedEntityList | undefined, children: ReactNode, state?: State): [UseEntityListSubTreeLoaderResult<State>, EntityListSubTreeLoaderState] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntityListSubTreeLoaderResult<State>>({\n\t\tentities: undefined,\n\t\ttreeRootId: undefined,\n\t\tstate: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentities: SugaredQualifiedEntityList\n\t\tstate?: State\n\t}>()\n\n\tconst [loadingState, setLoadingState] = useState<EntityListSubTreeLoaderState>('initial')\n\tconst extendTree = useExtendTree()\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (\n\t\t\t\t!entities\n\t\t\t\t|| displayedState.state === state && displayedState.entities === entities\n\t\t\t\t|| currentlyLoading.current?.entities === entities && currentlyLoading.current?.state === state\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentities,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tif (displayedState.entities) {\n\t\t\t\tsetLoadingState('refreshing')\n\t\t\t}\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntityListSubTree, {\n\t\t\t\t\t...entities,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentities: entities,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: state,\n\t\t\t\t})\n\t\t\t\tsetLoadingState('loaded')\n\t\t\t}\n\t\t})()\n\t}, [displayedState, extendTree, entities, children, state])\n\n\treturn [displayedState, loadingState]\n}\n"],"names":["useState","useRef","useExtendTree","useEffect","createElement","EntityListSubTree"],"mappings":";;;;;AAgBO,MAAM,6BAA6B,CAAQ,UAAkD,UAAqB,UAA2F;AACnN,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,eAAkD;AAAA,IAC7F,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,OAAO;AAAA,EAAA,CACP;AACD,QAAM,mBAAmBC,MAAAA;AAKzB,QAAM,CAAC,cAAc,eAAe,IAAID,eAAuC,SAAS;AACxF,QAAM,aAAaE,cAAAA;AAEnBC,QAAAA,UAAU,MAAM;AACf,KAAC,YAAY;AACZ,UACC,CAAC,YACE,eAAe,UAAU,SAAS,eAAe,aAAa,YAC9D,iBAAiB,SAAS,aAAa,YAAY,iBAAiB,SAAS,UAAU,OACzF;AACD;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,UAAI,eAAe,UAAU;AAC5B,wBAAgB,YAAY;AAAA,MAC7B;AAEA,YAAM,gBAAgB,MAAM;AAAA,QAC3BC,MAAAA,cAAcC,kBAAAA,mBAAmB;AAAA,UAChC,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,MAAA;AAEF,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ;AAAA,QAAA,CACA;AACD,wBAAgB,QAAQ;AAAA,MACzB;AAAA,IAAA;EACE,GACD,CAAC,gBAAgB,YAAY,UAAU,UAAU,KAAK,CAAC;AAEnD,SAAA,CAAC,gBAAgB,YAAY;AACrC;;"}
1
+ {"version":3,"file":"useEntityListSubTreeLoader.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityListSubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedEntityList, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntityListSubTree } from '../coreComponents'\nimport { useEnvironment } from './useEnvironment'\n\nexport type UseEntityListSubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntityListSubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntityListSubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentities: SugaredQualifiedEntityList\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntityListSubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentities: SugaredQualifiedEntityList\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\n\nexport type UseEntityListSubTreeLoaderState<State> =\n\t| UseEntityListSubTreeLoaderStateInitial\n\t| UseEntityListSubTreeLoaderStateLoading\n\t| UseEntityListSubTreeLoaderStateRefreshing<State>\n\t| UseEntityListSubTreeLoaderStateLoaded<State>\n\nexport type UseEntityListSubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nexport const useEntityListSubTreeLoader = <State>(entities: SugaredQualifiedEntityList | undefined, children: ReactNode, state?: State): [UseEntityListSubTreeLoaderState<State>, UseEntityListSubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntityListSubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentities: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentities: SugaredQualifiedEntityList\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!entities) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentities,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntityListSubTree, {\n\t\t\t\t\t...entities,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{ force: reloadTrigger !== null },\n\t\t\t)\n\t\t\tif (currentlyLoading.current?.entities !== entities || currentlyLoading.current?.state !== state) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentities: entities,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, entities, children, state, reloadTrigger])\n\n\treturn [\n\t\tdisplayedState,\n\t\t{\n\t\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t\t},\n\t]\n}\n"],"names":["useState","useRef","useExtendTree","useEffect","createElement","EntityListSubTree","useCallback"],"mappings":";;;;;AAkDO,MAAM,6BAA6B,CAAQ,UAAkD,UAAqB,UAAoG;AAC5N,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,eAAiD;AAAA,IAC5F,OAAO;AAAA,IACP,WAAW;AAAA,IACX,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmBC,MAAAA;AAKzB,QAAM,aAAaC,cAAAA;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAIF,eAAwB,IAAI;AAEtEG,QAAAA,UAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,UAAU;AACd;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACvB,YAAI,GAAG,UAAU,aAAa,GAAG,UAAU,WAAW;AAC9C,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3BC,MAAAA,cAAcC,kBAAAA,mBAAmB;AAAA,UAChC,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD,EAAE,OAAO,kBAAkB,KAAK;AAAA,MAAA;AAEjC,UAAI,iBAAiB,SAAS,aAAa,YAAY,iBAAiB,SAAS,UAAU,OAAO;AACjG;AAAA,MACD;AACA,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,UAAU,UAAU,OAAO,aAAa,CAAC;AAElD,SAAA;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQC,MAAAA,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,IACnD;AAAA,EAAA;AAEF;;"}
@@ -1,45 +1,69 @@
1
- import { useState, useRef, useEffect, createElement } from "react";
1
+ import { useState, useRef, useEffect, createElement, useCallback } from "react";
2
2
  import { useExtendTree } from "./useExtendTree.js";
3
3
  import { EntityListSubTree } from "../coreComponents/EntityListSubTree.js";
4
4
  const useEntityListSubTreeLoader = (entities, children, state) => {
5
5
  const [displayedState, setDisplayedState] = useState({
6
+ state: "initial",
7
+ isLoading: false,
6
8
  entities: void 0,
7
9
  treeRootId: void 0,
8
- state: void 0
10
+ customState: void 0
9
11
  });
10
12
  const currentlyLoading = useRef();
11
- const [loadingState, setLoadingState] = useState("initial");
12
13
  const extendTree = useExtendTree();
14
+ const [reloadTrigger, setReloadTrigger] = useState(null);
13
15
  useEffect(() => {
14
16
  (async () => {
15
- if (!entities || displayedState.state === state && displayedState.entities === entities || currentlyLoading.current?.entities === entities && currentlyLoading.current?.state === state) {
17
+ if (!entities) {
16
18
  return;
17
19
  }
18
20
  currentlyLoading.current = {
19
21
  entities,
20
22
  state
21
23
  };
22
- if (displayedState.entities) {
23
- setLoadingState("refreshing");
24
- }
24
+ setDisplayedState((it) => {
25
+ if (it.state === "initial" || it.state === "loading") {
26
+ return {
27
+ ...it,
28
+ isLoading: true,
29
+ state: "loading"
30
+ };
31
+ } else {
32
+ return {
33
+ ...it,
34
+ isLoading: true,
35
+ state: "refreshing"
36
+ };
37
+ }
38
+ });
25
39
  const newTreeRootId = await extendTree(
26
40
  createElement(EntityListSubTree, {
27
41
  ...entities,
28
42
  children
29
- })
43
+ }),
44
+ { force: reloadTrigger !== null }
30
45
  );
46
+ if (currentlyLoading.current?.entities !== entities || currentlyLoading.current?.state !== state) {
47
+ return;
48
+ }
31
49
  currentlyLoading.current = void 0;
32
50
  if (newTreeRootId) {
33
51
  setDisplayedState({
34
52
  entities,
35
53
  treeRootId: newTreeRootId,
36
- state
54
+ state: "loaded",
55
+ customState: state,
56
+ isLoading: false
37
57
  });
38
- setLoadingState("loaded");
39
58
  }
40
59
  })();
41
- }, [displayedState, extendTree, entities, children, state]);
42
- return [displayedState, loadingState];
60
+ }, [extendTree, entities, children, state, reloadTrigger]);
61
+ return [
62
+ displayedState,
63
+ {
64
+ reload: useCallback(() => setReloadTrigger({}), [])
65
+ }
66
+ ];
43
67
  };
44
68
  export {
45
69
  useEntityListSubTreeLoader
@@ -1 +1 @@
1
- {"version":3,"file":"useEntityListSubTreeLoader.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityListSubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedEntityList, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntityListSubTree } from '../coreComponents'\n\nexport type UseEntityListSubTreeLoaderResult<State> = {\n\tentities: SugaredQualifiedEntityList | undefined\n\ttreeRootId: TreeRootId | undefined\n\tstate: State | undefined\n}\n\nexport type EntityListSubTreeLoaderState =\n\t| 'initial'\n\t| 'refreshing'\n\t| 'loaded'\n\nexport const useEntityListSubTreeLoader = <State>(entities: SugaredQualifiedEntityList | undefined, children: ReactNode, state?: State): [UseEntityListSubTreeLoaderResult<State>, EntityListSubTreeLoaderState] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntityListSubTreeLoaderResult<State>>({\n\t\tentities: undefined,\n\t\ttreeRootId: undefined,\n\t\tstate: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentities: SugaredQualifiedEntityList\n\t\tstate?: State\n\t}>()\n\n\tconst [loadingState, setLoadingState] = useState<EntityListSubTreeLoaderState>('initial')\n\tconst extendTree = useExtendTree()\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (\n\t\t\t\t!entities\n\t\t\t\t|| displayedState.state === state && displayedState.entities === entities\n\t\t\t\t|| currentlyLoading.current?.entities === entities && currentlyLoading.current?.state === state\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentities,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tif (displayedState.entities) {\n\t\t\t\tsetLoadingState('refreshing')\n\t\t\t}\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntityListSubTree, {\n\t\t\t\t\t...entities,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentities: entities,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: state,\n\t\t\t\t})\n\t\t\t\tsetLoadingState('loaded')\n\t\t\t}\n\t\t})()\n\t}, [displayedState, extendTree, entities, children, state])\n\n\treturn [displayedState, loadingState]\n}\n"],"names":[],"mappings":";;;AAgBO,MAAM,6BAA6B,CAAQ,UAAkD,UAAqB,UAA2F;AACnN,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAkD;AAAA,IAC7F,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,OAAO;AAAA,EAAA,CACP;AACD,QAAM,mBAAmB;AAKzB,QAAM,CAAC,cAAc,eAAe,IAAI,SAAuC,SAAS;AACxF,QAAM,aAAa;AAEnB,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,UACC,CAAC,YACE,eAAe,UAAU,SAAS,eAAe,aAAa,YAC9D,iBAAiB,SAAS,aAAa,YAAY,iBAAiB,SAAS,UAAU,OACzF;AACD;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,UAAI,eAAe,UAAU;AAC5B,wBAAgB,YAAY;AAAA,MAC7B;AAEA,YAAM,gBAAgB,MAAM;AAAA,QAC3B,cAAc,mBAAmB;AAAA,UAChC,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,MAAA;AAEF,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ;AAAA,QAAA,CACA;AACD,wBAAgB,QAAQ;AAAA,MACzB;AAAA,IAAA;EACE,GACD,CAAC,gBAAgB,YAAY,UAAU,UAAU,KAAK,CAAC;AAEnD,SAAA,CAAC,gBAAgB,YAAY;AACrC;"}
1
+ {"version":3,"file":"useEntityListSubTreeLoader.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityListSubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedEntityList, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntityListSubTree } from '../coreComponents'\nimport { useEnvironment } from './useEnvironment'\n\nexport type UseEntityListSubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntityListSubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntityListSubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentities: SugaredQualifiedEntityList\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntityListSubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentities: SugaredQualifiedEntityList\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\n\nexport type UseEntityListSubTreeLoaderState<State> =\n\t| UseEntityListSubTreeLoaderStateInitial\n\t| UseEntityListSubTreeLoaderStateLoading\n\t| UseEntityListSubTreeLoaderStateRefreshing<State>\n\t| UseEntityListSubTreeLoaderStateLoaded<State>\n\nexport type UseEntityListSubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nexport const useEntityListSubTreeLoader = <State>(entities: SugaredQualifiedEntityList | undefined, children: ReactNode, state?: State): [UseEntityListSubTreeLoaderState<State>, UseEntityListSubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntityListSubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentities: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentities: SugaredQualifiedEntityList\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!entities) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentities,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntityListSubTree, {\n\t\t\t\t\t...entities,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{ force: reloadTrigger !== null },\n\t\t\t)\n\t\t\tif (currentlyLoading.current?.entities !== entities || currentlyLoading.current?.state !== state) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentities: entities,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, entities, children, state, reloadTrigger])\n\n\treturn [\n\t\tdisplayedState,\n\t\t{\n\t\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t\t},\n\t]\n}\n"],"names":[],"mappings":";;;AAkDO,MAAM,6BAA6B,CAAQ,UAAkD,UAAqB,UAAoG;AAC5N,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAiD;AAAA,IAC5F,OAAO;AAAA,IACP,WAAW;AAAA,IACX,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmB;AAKzB,QAAM,aAAa;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,IAAI;AAEtE,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,UAAU;AACd;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACvB,YAAI,GAAG,UAAU,aAAa,GAAG,UAAU,WAAW;AAC9C,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3B,cAAc,mBAAmB;AAAA,UAChC,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD,EAAE,OAAO,kBAAkB,KAAK;AAAA,MAAA;AAEjC,UAAI,iBAAiB,SAAS,aAAa,YAAY,iBAAiB,SAAS,UAAU,OAAO;AACjG;AAAA,MACD;AACA,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,UAAU,UAAU,OAAO,aAAa,CAAC;AAElD,SAAA;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQ,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,IACnD;AAAA,EAAA;AAEF;"}
@@ -5,43 +5,64 @@ const useExtendTree = require("./useExtendTree.cjs");
5
5
  const EntitySubTree = require("../coreComponents/EntitySubTree.cjs");
6
6
  const useEntitySubTreeLoader = (entity, children, state) => {
7
7
  const [displayedState, setDisplayedState] = React.useState({
8
+ state: "initial",
9
+ isLoading: false,
8
10
  entity: void 0,
9
11
  treeRootId: void 0,
10
- state: void 0
12
+ customState: void 0
11
13
  });
12
14
  const currentlyLoading = React.useRef();
13
- const [loadingState, setLoadingState] = React.useState("initial");
14
15
  const extendTree = useExtendTree.useExtendTree();
16
+ const [reloadTrigger, setReloadTrigger] = React.useState(null);
15
17
  React.useEffect(() => {
16
18
  (async () => {
17
- if (!entity || displayedState.state === state && displayedState.entity === entity || currentlyLoading.current?.entity === entity && currentlyLoading.current?.state === state) {
19
+ if (!entity) {
18
20
  return;
19
21
  }
20
22
  currentlyLoading.current = {
21
23
  entity,
22
24
  state
23
25
  };
24
- if (displayedState.entity) {
25
- setLoadingState("refreshing");
26
- }
26
+ setDisplayedState((it) => {
27
+ if (it.state === "initial" || it.state === "loading") {
28
+ return {
29
+ ...it,
30
+ isLoading: true,
31
+ state: "loading"
32
+ };
33
+ } else {
34
+ return {
35
+ ...it,
36
+ isLoading: true,
37
+ state: "refreshing"
38
+ };
39
+ }
40
+ });
27
41
  const newTreeRootId = await extendTree(
28
42
  React.createElement(EntitySubTree.EntitySubTree, {
29
43
  ...entity,
30
44
  children
31
- })
45
+ }),
46
+ { force: reloadTrigger !== null }
32
47
  );
48
+ if (currentlyLoading.current?.entity !== entity || currentlyLoading.current?.state !== state) {
49
+ return;
50
+ }
33
51
  currentlyLoading.current = void 0;
34
52
  if (newTreeRootId) {
35
53
  setDisplayedState({
36
54
  entity,
37
55
  treeRootId: newTreeRootId,
38
- state
56
+ state: "loaded",
57
+ customState: state,
58
+ isLoading: false
39
59
  });
40
- setLoadingState("loaded");
41
60
  }
42
61
  })();
43
- }, [displayedState, extendTree, entity, children, state]);
44
- return [displayedState, loadingState];
62
+ }, [extendTree, entity, children, state, reloadTrigger]);
63
+ return [displayedState, {
64
+ reload: React.useCallback(() => setReloadTrigger({}), [])
65
+ }];
45
66
  };
46
67
  exports.useEntitySubTreeLoader = useEntitySubTreeLoader;
47
68
  //# sourceMappingURL=useEntitySubTreeLoader.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useEntitySubTreeLoader.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntitySubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedSingleEntity, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntitySubTree } from '../coreComponents'\n\nexport type UseEntitySubTreeLoaderResult<State> = {\n\tentity: SugaredQualifiedSingleEntity | undefined\n\ttreeRootId: TreeRootId | undefined\n\tstate: State | undefined\n}\n\nexport type EntitySubTreeLoaderState =\n\t| 'initial'\n\t| 'refreshing'\n\t| 'loaded'\n\nexport const useEntitySubTreeLoader = <State>(entity: SugaredQualifiedSingleEntity | undefined, children: ReactNode, state?: State): [UseEntitySubTreeLoaderResult<State>, EntitySubTreeLoaderState] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntitySubTreeLoaderResult<State>>({\n\t\tentity: undefined,\n\t\ttreeRootId: undefined,\n\t\tstate: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentity: SugaredQualifiedSingleEntity\n\t\tstate?: State\n\t}>()\n\n\tconst [loadingState, setLoadingState] = useState<EntitySubTreeLoaderState>('initial')\n\tconst extendTree = useExtendTree()\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (\n\t\t\t\t!entity\n\t\t\t\t|| displayedState.state === state && displayedState.entity === entity\n\t\t\t\t|| currentlyLoading.current?.entity === entity && currentlyLoading.current?.state === state\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentity,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tif (displayedState.entity) {\n\t\t\t\tsetLoadingState('refreshing')\n\t\t\t}\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntitySubTree, {\n\t\t\t\t\t...entity,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentity: entity,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: state,\n\t\t\t\t})\n\t\t\t\tsetLoadingState('loaded')\n\t\t\t}\n\t\t})()\n\t}, [displayedState, extendTree, entity, children, state])\n\n\treturn [displayedState, loadingState]\n}\n"],"names":["useState","useRef","useExtendTree","useEffect","createElement","EntitySubTree"],"mappings":";;;;;AAgBO,MAAM,yBAAyB,CAAQ,QAAkD,UAAqB,UAAmF;AACvM,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,eAA8C;AAAA,IACzF,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,OAAO;AAAA,EAAA,CACP;AACD,QAAM,mBAAmBC,MAAAA;AAKzB,QAAM,CAAC,cAAc,eAAe,IAAID,eAAmC,SAAS;AACpF,QAAM,aAAaE,cAAAA;AAEnBC,QAAAA,UAAU,MAAM;AACf,KAAC,YAAY;AACZ,UACC,CAAC,UACE,eAAe,UAAU,SAAS,eAAe,WAAW,UAC5D,iBAAiB,SAAS,WAAW,UAAU,iBAAiB,SAAS,UAAU,OACrF;AACD;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,UAAI,eAAe,QAAQ;AAC1B,wBAAgB,YAAY;AAAA,MAC7B;AAEA,YAAM,gBAAgB,MAAM;AAAA,QAC3BC,MAAAA,cAAcC,cAAAA,eAAe;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,MAAA;AAEF,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ;AAAA,QAAA,CACA;AACD,wBAAgB,QAAQ;AAAA,MACzB;AAAA,IAAA;EACE,GACD,CAAC,gBAAgB,YAAY,QAAQ,UAAU,KAAK,CAAC;AAEjD,SAAA,CAAC,gBAAgB,YAAY;AACrC;;"}
1
+ {"version":3,"file":"useEntitySubTreeLoader.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntitySubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedSingleEntity, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntitySubTree } from '../coreComponents'\n\nexport type UseEntitySubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntitySubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntitySubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntitySubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\n\nexport type UseEntitySubTreeLoaderState<State> =\n\t| UseEntitySubTreeLoaderStateInitial\n\t| UseEntitySubTreeLoaderStateLoading\n\t| UseEntitySubTreeLoaderStateRefreshing<State>\n\t| UseEntitySubTreeLoaderStateLoaded<State>\n\nexport type EntityListSubTreeLoaderState = UseEntitySubTreeLoaderState<any>['state']\n\nexport type UseEntitySubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nexport const useEntitySubTreeLoader = <State>(entity: SugaredQualifiedSingleEntity | undefined, children: ReactNode, state?: State): [UseEntitySubTreeLoaderState<State>, UseEntitySubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntitySubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentity: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentity: SugaredQualifiedSingleEntity\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!entity) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentity,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntitySubTree, {\n\t\t\t\t\t...entity,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{ force: reloadTrigger !== null },\n\t\t\t)\n\t\t\tif (currentlyLoading.current?.entity !== entity || currentlyLoading.current?.state !== state) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentity: entity,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, entity, children, state, reloadTrigger])\n\n\treturn [displayedState, {\n\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t}]\n}\n"],"names":["useState","useRef","useExtendTree","useEffect","createElement","EntitySubTree","useCallback"],"mappings":";;;;;AAmDO,MAAM,yBAAyB,CAAQ,QAAkD,UAAqB,UAA4F;AAChN,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,eAA6C;AAAA,IACxF,OAAO;AAAA,IACP,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmBC,MAAAA;AAKzB,QAAM,aAAaC,cAAAA;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAIF,eAAwB,IAAI;AAEtEG,QAAAA,UAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,QAAQ;AACZ;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACvB,YAAI,GAAG,UAAU,aAAa,GAAG,UAAU,WAAW;AAC9C,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3BC,MAAAA,cAAcC,cAAAA,eAAe;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD,EAAE,OAAO,kBAAkB,KAAK;AAAA,MAAA;AAEjC,UAAI,iBAAiB,SAAS,WAAW,UAAU,iBAAiB,SAAS,UAAU,OAAO;AAC7F;AAAA,MACD;AACA,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,QAAQ,UAAU,OAAO,aAAa,CAAC;AAEvD,SAAO,CAAC,gBAAgB;AAAA,IACvB,QAAQC,MAAAA,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,EAAA,CAClD;AACF;;"}
@@ -1,45 +1,66 @@
1
- import { useState, useRef, useEffect, createElement } from "react";
1
+ import { useState, useRef, useEffect, createElement, useCallback } from "react";
2
2
  import { useExtendTree } from "./useExtendTree.js";
3
3
  import { EntitySubTree } from "../coreComponents/EntitySubTree.js";
4
4
  const useEntitySubTreeLoader = (entity, children, state) => {
5
5
  const [displayedState, setDisplayedState] = useState({
6
+ state: "initial",
7
+ isLoading: false,
6
8
  entity: void 0,
7
9
  treeRootId: void 0,
8
- state: void 0
10
+ customState: void 0
9
11
  });
10
12
  const currentlyLoading = useRef();
11
- const [loadingState, setLoadingState] = useState("initial");
12
13
  const extendTree = useExtendTree();
14
+ const [reloadTrigger, setReloadTrigger] = useState(null);
13
15
  useEffect(() => {
14
16
  (async () => {
15
- if (!entity || displayedState.state === state && displayedState.entity === entity || currentlyLoading.current?.entity === entity && currentlyLoading.current?.state === state) {
17
+ if (!entity) {
16
18
  return;
17
19
  }
18
20
  currentlyLoading.current = {
19
21
  entity,
20
22
  state
21
23
  };
22
- if (displayedState.entity) {
23
- setLoadingState("refreshing");
24
- }
24
+ setDisplayedState((it) => {
25
+ if (it.state === "initial" || it.state === "loading") {
26
+ return {
27
+ ...it,
28
+ isLoading: true,
29
+ state: "loading"
30
+ };
31
+ } else {
32
+ return {
33
+ ...it,
34
+ isLoading: true,
35
+ state: "refreshing"
36
+ };
37
+ }
38
+ });
25
39
  const newTreeRootId = await extendTree(
26
40
  createElement(EntitySubTree, {
27
41
  ...entity,
28
42
  children
29
- })
43
+ }),
44
+ { force: reloadTrigger !== null }
30
45
  );
46
+ if (currentlyLoading.current?.entity !== entity || currentlyLoading.current?.state !== state) {
47
+ return;
48
+ }
31
49
  currentlyLoading.current = void 0;
32
50
  if (newTreeRootId) {
33
51
  setDisplayedState({
34
52
  entity,
35
53
  treeRootId: newTreeRootId,
36
- state
54
+ state: "loaded",
55
+ customState: state,
56
+ isLoading: false
37
57
  });
38
- setLoadingState("loaded");
39
58
  }
40
59
  })();
41
- }, [displayedState, extendTree, entity, children, state]);
42
- return [displayedState, loadingState];
60
+ }, [extendTree, entity, children, state, reloadTrigger]);
61
+ return [displayedState, {
62
+ reload: useCallback(() => setReloadTrigger({}), [])
63
+ }];
43
64
  };
44
65
  export {
45
66
  useEntitySubTreeLoader
@@ -1 +1 @@
1
- {"version":3,"file":"useEntitySubTreeLoader.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntitySubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedSingleEntity, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntitySubTree } from '../coreComponents'\n\nexport type UseEntitySubTreeLoaderResult<State> = {\n\tentity: SugaredQualifiedSingleEntity | undefined\n\ttreeRootId: TreeRootId | undefined\n\tstate: State | undefined\n}\n\nexport type EntitySubTreeLoaderState =\n\t| 'initial'\n\t| 'refreshing'\n\t| 'loaded'\n\nexport const useEntitySubTreeLoader = <State>(entity: SugaredQualifiedSingleEntity | undefined, children: ReactNode, state?: State): [UseEntitySubTreeLoaderResult<State>, EntitySubTreeLoaderState] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntitySubTreeLoaderResult<State>>({\n\t\tentity: undefined,\n\t\ttreeRootId: undefined,\n\t\tstate: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentity: SugaredQualifiedSingleEntity\n\t\tstate?: State\n\t}>()\n\n\tconst [loadingState, setLoadingState] = useState<EntitySubTreeLoaderState>('initial')\n\tconst extendTree = useExtendTree()\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (\n\t\t\t\t!entity\n\t\t\t\t|| displayedState.state === state && displayedState.entity === entity\n\t\t\t\t|| currentlyLoading.current?.entity === entity && currentlyLoading.current?.state === state\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentity,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tif (displayedState.entity) {\n\t\t\t\tsetLoadingState('refreshing')\n\t\t\t}\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntitySubTree, {\n\t\t\t\t\t...entity,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentity: entity,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: state,\n\t\t\t\t})\n\t\t\t\tsetLoadingState('loaded')\n\t\t\t}\n\t\t})()\n\t}, [displayedState, extendTree, entity, children, state])\n\n\treturn [displayedState, loadingState]\n}\n"],"names":[],"mappings":";;;AAgBO,MAAM,yBAAyB,CAAQ,QAAkD,UAAqB,UAAmF;AACvM,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAA8C;AAAA,IACzF,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,OAAO;AAAA,EAAA,CACP;AACD,QAAM,mBAAmB;AAKzB,QAAM,CAAC,cAAc,eAAe,IAAI,SAAmC,SAAS;AACpF,QAAM,aAAa;AAEnB,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,UACC,CAAC,UACE,eAAe,UAAU,SAAS,eAAe,WAAW,UAC5D,iBAAiB,SAAS,WAAW,UAAU,iBAAiB,SAAS,UAAU,OACrF;AACD;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,UAAI,eAAe,QAAQ;AAC1B,wBAAgB,YAAY;AAAA,MAC7B;AAEA,YAAM,gBAAgB,MAAM;AAAA,QAC3B,cAAc,eAAe;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,MAAA;AAEF,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ;AAAA,QAAA,CACA;AACD,wBAAgB,QAAQ;AAAA,MACzB;AAAA,IAAA;EACE,GACD,CAAC,gBAAgB,YAAY,QAAQ,UAAU,KAAK,CAAC;AAEjD,SAAA,CAAC,gBAAgB,YAAY;AACrC;"}
1
+ {"version":3,"file":"useEntitySubTreeLoader.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntitySubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedSingleEntity, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntitySubTree } from '../coreComponents'\n\nexport type UseEntitySubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntitySubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntitySubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntitySubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\n\nexport type UseEntitySubTreeLoaderState<State> =\n\t| UseEntitySubTreeLoaderStateInitial\n\t| UseEntitySubTreeLoaderStateLoading\n\t| UseEntitySubTreeLoaderStateRefreshing<State>\n\t| UseEntitySubTreeLoaderStateLoaded<State>\n\nexport type EntityListSubTreeLoaderState = UseEntitySubTreeLoaderState<any>['state']\n\nexport type UseEntitySubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nexport const useEntitySubTreeLoader = <State>(entity: SugaredQualifiedSingleEntity | undefined, children: ReactNode, state?: State): [UseEntitySubTreeLoaderState<State>, UseEntitySubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntitySubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentity: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentity: SugaredQualifiedSingleEntity\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!entity) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentity,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntitySubTree, {\n\t\t\t\t\t...entity,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{ force: reloadTrigger !== null },\n\t\t\t)\n\t\t\tif (currentlyLoading.current?.entity !== entity || currentlyLoading.current?.state !== state) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentity: entity,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, entity, children, state, reloadTrigger])\n\n\treturn [displayedState, {\n\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t}]\n}\n"],"names":[],"mappings":";;;AAmDO,MAAM,yBAAyB,CAAQ,QAAkD,UAAqB,UAA4F;AAChN,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAA6C;AAAA,IACxF,OAAO;AAAA,IACP,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmB;AAKzB,QAAM,aAAa;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,IAAI;AAEtE,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,QAAQ;AACZ;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACvB,YAAI,GAAG,UAAU,aAAa,GAAG,UAAU,WAAW;AAC9C,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3B,cAAc,eAAe;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD,EAAE,OAAO,kBAAkB,KAAK;AAAA,MAAA;AAEjC,UAAI,iBAAiB,SAAS,WAAW,UAAU,iBAAiB,SAAS,UAAU,OAAO;AAC7F;AAAA,MACD;AACA,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,QAAQ,UAAU,OAAO,aAAa,CAAC;AAEvD,SAAO,CAAC,gBAAgB;AAAA,IACvB,QAAQ,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,EAAA,CAClD;AACF;"}
@@ -10,7 +10,8 @@ EnvironmentContext.displayName = "EnvironmentContext";
10
10
  const EnvironmentMiddleware = Component.Component(
11
11
  ({ children, create }) => {
12
12
  const env = useEnvironment.useEnvironment();
13
- return /* @__PURE__ */ jsxRuntime.jsx(EnvironmentContext.Provider, { value: create(env), children });
13
+ const envWithExtension = React.useMemo(() => create(env), [env, create]);
14
+ return /* @__PURE__ */ jsxRuntime.jsx(EnvironmentContext.Provider, { value: envWithExtension, children });
14
15
  },
15
16
  {
16
17
  staticRender: ({ children }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentContext.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }: EnvironmentMiddlewareProps) => {\n\t\tconst env = useEnvironment()\n\t\treturn <EnvironmentContext.Provider value={create(env)}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create }, env) => {\n\t\t\treturn create(env)\n\t\t},\n\t},\n)\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":["createContext","Environment","Component","useEnvironment","jsx","useCallback"],"mappings":";;;;;;;AAKO,MAAM,qBAAqBA,MAAA,cAA2BC,oBAAY,QAAQ;AACjF,mBAAmB,cAAc;AAO1B,MAAM,wBAAwBC,UAAA;AAAA,EACpC,CAAC,EAAE,UAAU,aAAyC;AACrD,UAAM,MAAMC,eAAAA;AACL,WAAAC,2BAAA,IAAC,mBAAmB,UAAnB,EAA4B,OAAO,OAAO,GAAG,GAAI,SAAS,CAAA;AAAA,EACnE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,mEAAU,SAAS,CAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,UAAU,QAAQ;AACzC,aAAO,OAAO,GAAG;AAAA,IAClB;AAAA,EACD;AACD;AAQO,MAAM,+BAAgGF,UAAA;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAASG,MAAAA,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAAD,2BAAA,IAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAAA,2BAAA,IAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AACD;;;;"}
1
+ {"version":3,"file":"EnvironmentContext.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback, useMemo } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }: EnvironmentMiddlewareProps) => {\n\t\tconst env = useEnvironment()\n\t\tconst envWithExtension = useMemo(() => create(env), [env, create])\n\n\t\treturn <EnvironmentContext.Provider value={envWithExtension}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create }, env) => {\n\t\t\treturn create(env)\n\t\t},\n\t},\n)\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":["createContext","Environment","Component","useEnvironment","useMemo","useCallback","jsx"],"mappings":";;;;;;;AAKO,MAAM,qBAAqBA,MAAA,cAA2BC,oBAAY,QAAQ;AACjF,mBAAmB,cAAc;AAO1B,MAAM,wBAAwBC,UAAA;AAAA,EACpC,CAAC,EAAE,UAAU,aAAyC;AACrD,UAAM,MAAMC,eAAAA;AACN,UAAA,mBAAmBC,cAAQ,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,MAAM,CAAC;AAEjE,0CAAQ,mBAAmB,UAAnB,EAA4B,OAAO,kBAAmB,SAAS,CAAA;AAAA,EACxE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,mEAAU,SAAS,CAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,UAAU,QAAQ;AACzC,aAAO,OAAO,GAAG;AAAA,IAClB;AAAA,EACD;AACD;AAQO,MAAM,+BAAgGF,UAAA;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAASG,MAAAA,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAAC,2BAAA,IAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAAA,2BAAA,IAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AACD;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { jsx, Fragment } from "react/jsx-runtime";
2
- import { createContext, useCallback } from "react";
2
+ import { createContext, useMemo, useCallback } from "react";
3
3
  import { Environment } from "@contember/binding";
4
4
  import { useEnvironment } from "./useEnvironment.js";
5
5
  import { Component } from "../coreComponents/Component.js";
@@ -8,7 +8,8 @@ EnvironmentContext.displayName = "EnvironmentContext";
8
8
  const EnvironmentMiddleware = Component(
9
9
  ({ children, create }) => {
10
10
  const env = useEnvironment();
11
- return /* @__PURE__ */ jsx(EnvironmentContext.Provider, { value: create(env), children });
11
+ const envWithExtension = useMemo(() => create(env), [env, create]);
12
+ return /* @__PURE__ */ jsx(EnvironmentContext.Provider, { value: envWithExtension, children });
12
13
  },
13
14
  {
14
15
  staticRender: ({ children }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentContext.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }: EnvironmentMiddlewareProps) => {\n\t\tconst env = useEnvironment()\n\t\treturn <EnvironmentContext.Provider value={create(env)}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create }, env) => {\n\t\t\treturn create(env)\n\t\t},\n\t},\n)\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":[],"mappings":";;;;;AAKO,MAAM,qBAAqB,cAA2B,YAAY,QAAQ;AACjF,mBAAmB,cAAc;AAO1B,MAAM,wBAAwB;AAAA,EACpC,CAAC,EAAE,UAAU,aAAyC;AACrD,UAAM,MAAM;AACL,WAAA,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,OAAO,GAAG,GAAI,SAAS,CAAA;AAAA,EACnE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,6CAAU,SAAS,CAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,UAAU,QAAQ;AACzC,aAAO,OAAO,GAAG;AAAA,IAClB;AAAA,EACD;AACD;AAQO,MAAM,+BAAgG;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAA,oBAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAA,oBAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AACD;"}
1
+ {"version":3,"file":"EnvironmentContext.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback, useMemo } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }: EnvironmentMiddlewareProps) => {\n\t\tconst env = useEnvironment()\n\t\tconst envWithExtension = useMemo(() => create(env), [env, create])\n\n\t\treturn <EnvironmentContext.Provider value={envWithExtension}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create }, env) => {\n\t\t\treturn create(env)\n\t\t},\n\t},\n)\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":[],"mappings":";;;;;AAKO,MAAM,qBAAqB,cAA2B,YAAY,QAAQ;AACjF,mBAAmB,cAAc;AAO1B,MAAM,wBAAwB;AAAA,EACpC,CAAC,EAAE,UAAU,aAAyC;AACrD,UAAM,MAAM;AACN,UAAA,mBAAmB,QAAQ,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,MAAM,CAAC;AAEjE,+BAAQ,mBAAmB,UAAnB,EAA4B,OAAO,kBAAmB,SAAS,CAAA;AAAA,EACxE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,6CAAU,SAAS,CAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,UAAU,QAAQ;AACzC,aAAO,OAAO,GAAG;AAAA,IAClB;AAAA,EACD;AACD;AAQO,MAAM,+BAAgG;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAA,oBAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAA,oBAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AACD;"}