@beinformed/ui 1.57.1 → 1.57.2

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
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [1.57.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.57.1...v1.57.2) (2024-10-25)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **usemodularui:** avoid throwing of exception when wrong model ([9e258a9](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/9e258a96bd12593a46a53b6043b78c01f05bb978))
11
+ * **usemodularui:** force load of model when it is removed from the store ([2dc4f12](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/2dc4f124ae0777cea5a9e54201127400f4b4cd0d))
12
+
5
13
  ## [1.57.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.57.0...v1.57.1) (2024-10-23)
6
14
 
7
15
 
@@ -24,29 +24,31 @@ export const useModularUI = function (modelKey, url) {
24
24
  const dispatch = useDispatch();
25
25
  const href = useMemo(() => url?.toString() || "", [url]);
26
26
  const key = useKeyForHook(modelKey, href);
27
+ const modelSelector = useMemo(() => state => state.modularui[key], [key]);
28
+ const model = useSelector(modelSelector);
27
29
  if (url instanceof Href) {
28
30
  options.origin = options.origin ?? url.origin;
29
31
  options.contextPath = options.contextPath ?? url.contextPath;
30
32
  }
31
33
  const location = useLocation();
32
34
  const redirectLocation = location.state?.redirectLocation;
33
- const forceReload = redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;
35
+ const forceLoad = model == null || (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);
34
36
  const prevOptions = useRef(options);
35
37
  const prevHref = useRef(href);
36
- const prevForceReload = useRef(forceReload);
38
+ const prevForceLoad = useRef(forceLoad);
37
39
 
38
40
  // dispatch loadModularUI
39
41
  useDeepCompareEffect(() => {
40
42
  // prevent reloads when previous option had the isReload, but the new options not
41
43
  const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
42
- const doForceReload = forceReload && !prevForceReload.current;
43
- if (href !== "" && (doForceReload || !isOldReload)) {
44
+ const doForceLoad = forceLoad && !prevForceLoad.current;
45
+ if (href !== "" && (doForceLoad || !isOldReload)) {
44
46
  dispatch(loadModularUI(key, href, options));
45
47
  }
46
48
  prevOptions.current = options;
47
49
  prevHref.current = href;
48
- prevForceReload.current = forceReload;
49
- }, [key, href, options, forceReload]);
50
+ prevForceLoad.current = forceLoad;
51
+ }, [key, href, options, forceLoad]);
50
52
  useEffect(() => {
51
53
  if (options.removeOnUnmount) {
52
54
  return () => {
@@ -54,7 +56,6 @@ export const useModularUI = function (modelKey, url) {
54
56
  };
55
57
  }
56
58
  }, [dispatch, key, options.removeOnUnmount]);
57
- const selector = useMemo(() => state => state.modularui[key], [key]);
58
- return useSelector(selector);
59
+ return model;
59
60
  };
60
61
  //# sourceMappingURL=useModularUI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUI.js","names":["useEffect","useRef","useMemo","useDispatch","useSelector","useLocation","HTTP_METHODS","loadModularUI","removeModelByKey","useDeepCompareEffect","useLocale","Href","useKeyForHook","modelKey","url","locale","split","useModularUI","options","arguments","length","undefined","method","GET","removeOnUnmount","dispatch","href","toString","key","origin","contextPath","location","redirectLocation","state","forceReload","equals","prevOptions","prevHref","prevForceReload","isOldReload","current","isReload","doForceReload","selector","modularui"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceReload =\n redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceReload = useRef(forceReload);\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n // prevent reloads when previous option had the isReload, but the new options not\n const isOldReload =\n prevHref.current === href &&\n prevOptions.current.isReload &&\n !options.isReload;\n\n const doForceReload = forceReload && !prevForceReload.current;\n\n if (href !== \"\" && (doForceReload || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceReload.current = forceReload;\n }, [key, href, options, forceReload]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, options.removeOnUnmount]);\n\n const selector = useMemo(() => (state) => state.modularui[key], [key]);\n return useSelector(selector);\n};\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAO;AAClD,SAASC,WAAW,EAAEC,WAAW,QAAQ,aAAa;AACtD,SAASC,WAAW,QAAQ,cA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,IAAKA,KAAK,CAACW,SAAS,CAAChB,GAAG,CAAC,EAAE,CAACA,GAAG,CAAC,CAAC;EACtE,OAAOxB,WAAW,CAACuC,QAAQ,CAAC;AAC9B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModularUI.js","names":["useEffect","useRef","useMemo","useDispatch","useSelector","useLocation","HTTP_METHODS","loadModularUI","removeModelByKey","useDeepCompareEffect","useLocale","Href","useKeyForHook","modelKey","url","locale","split","useModularUI","options","arguments","length","undefined","method","GET","removeOnUnmount","dispatch","href","toString","key","modelSelector","state","modularui","model","origin","contextPath","location","redirectLocation","forceLoad","equals","prevOptions","prevHref","prevForceLoad","isOldReload","current","isReload","doForceLoad"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);\n const model = useSelector(modelSelector);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceLoad =\n model == null ||\n (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceLoad = useRef(forceLoad);\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n // prevent reloads when previous option had the isReload, but the new options not\n const isOldReload =\n prevHref.current === href &&\n prevOptions.current.isReload &&\n !options.isReload;\n\n const doForceLoad = forceLoad && !prevForceLoad.current;\n\n if (href !== \"\" && (doForceLoad || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceLoad.current = forceLoad;\n }, [key, href, options, forceLoad]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, options.removeOnUnmount]);\n\n return model;\n};\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAO;AAClD,SAASC,WAAW,EAAEC,WAAW,QAAQ,aAAa;AACtD,SAASC,WAAW,QAAQ,cAAc;AAE1C,SAASC,YAAY,QAAQ,cAAc;AAC3C,SACEC,aAAa,EACbC,gBAAgB,QACX,sCAAsC;AAE7C,OAAOC,oBAAoB,MAAM,wBAAwB;AAEzD,SAASC,SAAS,QAAQ,WAAW;AACrC,OAAOC,IAAI,MAAM,qBAAqB;AAItC;AACA;AACA,MAAMC,aAAa,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAK;EACvD,MAAMC,MAAM,GAAGL,SAAS,CAAC,CAAC;EAC1B,OAAOR,OAAO,CACZ,MAAM,GAAGW,QAAQ,IAAIC,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAKD,MAAM,GAAG,EACpD,CAACF,QAAQ,EAAEC,GAAG,EAAEC,MAAM,CACxB,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA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AMe,aAAa,GAAGxC,MAAM,CAACoC,SAAS,CAAC;;EAEvC;EACA5B,oBAAoB,CAAC,MAAM;IACzB;IACA,MAAMiC,WAAW,GACfF,QAAQ,CAACG,OAAO,KAAKjB,IAAI,IACzBa,WAAW,CAACI,OAAO,CAACC,QAAQ,IAC5B,CAAC1B,OAAO,CAAC0B,QAAQ;IAEnB,MAAMC,WAAW,GAAGR,SAAS,IAAI,CAACI,aAAa,CAACE,OAAO;IAEvD,IAAIjB,IAAI,KAAK,EAAE,KAAKmB,WAAW,IAAI,CAACH,WAAW,CAAC,EAAE;MAChDjB,QAAQ,CAAClB,aAAa,CAACqB,GAAG,EAAEF,IAAI,EAAER,OAAO,CAAC,CAAC;IAC7C;IAEAqB,WAAW,CAACI,OAAO,GAAGzB,OAAO;IAC7BsB,QAAQ,CAACG,OAAO,GAAGjB,IAAI;IACvBe,aAAa,CAACE,OAAO,GAAGN,SAAS;EACnC,CAAC,EAAE,CAACT,GAAG,EAAEF,IAAI,EAAER,OAAO,EAAEmB,SAAS,CAAC,CAAC;EAEnCrC,SAAS,CAAC,MAAM;IACd,IAAIkB,OAAO,CAACM,eAAe,EAAE;MAC3B,OAAO,MAAM;QACXC,QAAQ,CAACjB,gBAAgB,CAACoB,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACH,QAAQ,EAAEG,GAAG,EAAEV,OAAO,CAACM,eAAe,CAAC,CAAC;EAE5C,OAAOQ,KAAK;AACd,CAAC","ignoreList":[]}
@@ -2,7 +2,6 @@ import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/i
2
2
  import { useMemo } from "react";
3
3
  import { useModularUI } from "./useModularUI";
4
4
  import { useLocation } from "./useRouter";
5
- import { IllegalStateException } from "../exceptions";
6
5
  // Helper to create useModularUI options
7
6
  const createUseModularUIOptions = (options, href, location) => {
8
7
  var _context;
@@ -42,8 +41,7 @@ const validateModel = (model, expectedModels) => {
42
41
  if (expectedModels.length > 0) {
43
42
  const isCorrectModel = expectedModels.some(expectedModel => model.type === expectedModel);
44
43
  if (!isCorrectModel) {
45
- console.error(model, "is not of instance", expectedModels);
46
- throw new IllegalStateException("Resolved model has incorrect type");
44
+ console.warn(model, "is not of instance", expectedModels);
47
45
  }
48
46
  }
49
47
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIBasic.js","names":["useMemo","useModularUI","useLocation","IllegalStateException","createUseModularUIOptions","options","href","location","_context","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","state","reload","_startsWithInstanceProperty","pathname","call","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","error","useModularUIBasic","key","arguments","memoizedHref","toString","useModularUIOptions","modularUI"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\nimport { useLocation } from \"./useRouter\";\nimport { IllegalStateException } from \"../exceptions\";\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n location: any,\n): Object => {\n const baseOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n };\n\n // Handle targetModel and forceTargetModel\n if (options.targetModel) {\n baseOptions.targetModel = options.targetModel;\n baseOptions.forceTargetModel = options.forceTargetModel;\n }\n\n // Handle cache option\n if (options.cache) {\n baseOptions.cache = options.cache;\n }\n\n // Check for reload if location matches href\n if (location.state?.reload && location.pathname.startsWith(href)) {\n baseOptions.isReload = true;\n }\n\n // Handle origin and contextPath options\n baseOptions.origin = options.origin ?? baseOptions.origin;\n baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\n );\n if (!isCorrectModel) {\n console.error(model, \"is not of instance\", expectedModels);\n throw new IllegalStateException(\"Resolved model has incorrect type\");\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n },\n): T | null => {\n const location = useLocation();\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const useModularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, location),\n [options, memoizedHref, location],\n );\n\n const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n"],"mappings":";AACA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,WAAW,QAAQ,aAAa;AACzC,SAASC,qBAAqB,QAAQ,eAAe;AAYrD;AACA,MAAMC,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,QAAa,KACF;EAAA,IAAAC,QAAA;EACX,MAAMC,WAAW,GAAG;IAClBC,WAAW,EAAEC,SAAS;IACtBC,gBAAgB,EAAED,SAAS;IAC3BE,QAAQ,EAAE,KAAK;IACfC,MAAM,EAAEH,SAAS;IACjBI,WAAW,EAAEJ,SAAS;IACtBK,KAAK,EAAE;EACT,CAAC;;EAED;EACA,IAAIX,OAAO,CAACK,WAAW,EAAE;IACvBD,W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,gBAAgB,EAAE,KAAK;IACvBE,MAAM,EAAEH,SAAS;IACjBI,WAAW,EAAEJ;EACf,CAAC;EAED,MAAMJ,QAAQ,GAAGL,WAAW,CAAC,CAAC;EAC9B,MAAMiC,YAAY,GAAGnC,OAAO,CAAC,MAAMM,IAAI,CAAC8B,QAAQ,CAAC,CAAC,EAAE,CAAC9B,IAAI,CAAC,CAAC;EAC3D,MAAM+B,mBAAmB,GAAGrC,OAAO,CACjC,MAAMI,yBAAyB,CAACC,OAAO,EAAE8B,YAAY,EAAE5B,QAAQ,CAAC,EAChE,CAACF,OAAO,EAAE8B,YAAY,EAAE5B,QAAQ,CAClC,CAAC;EAED,MAAM+B,SAAS,GAAGrC,YAAY,CAACgC,GAAG,EAAEE,YAAY,EAAEE,mBAAmB,CAAC;EACtE,MAAMb,cAAc,GAAGxB,OAAO,CAC5B,MAAMK,OAAO,CAACmB,cAAc,IAAI,EAAE,EAClC,CAACnB,OAAO,CAACmB,cAAc,CACzB,CAAC;EAED,OAAOxB,OAAO,CAAC,MAAgB;IAC7B,IAAIsC,SAAS,EAAEf,KAAK,EAAE;MACpBD,aAAa,CAACgB,SAAS,CAACf,KAAK,EAAEC,cAAc,CAAC;MAC9C,OAAOc,SAAS,CAACf,KAAK;IACxB;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CAACC,cAAc,EAAEc,SAAS,CAAC,CAAC;AACjC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIBasic.js","names":["useMemo","useModularUI","useLocation","createUseModularUIOptions","options","href","location","_context","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","state","reload","_startsWithInstanceProperty","pathname","call","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","warn","useModularUIBasic","key","arguments","memoizedHref","toString","useModularUIOptions","modularUI"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\nimport { useLocation } from \"./useRouter\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n location: any,\n): Object => {\n const baseOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n };\n\n // Handle targetModel and forceTargetModel\n if (options.targetModel) {\n baseOptions.targetModel = options.targetModel;\n baseOptions.forceTargetModel = options.forceTargetModel;\n }\n\n // Handle cache option\n if (options.cache) {\n baseOptions.cache = options.cache;\n }\n\n // Check for reload if location matches href\n if (location.state?.reload && location.pathname.startsWith(href)) {\n baseOptions.isReload = true;\n }\n\n // Handle origin and contextPath options\n baseOptions.origin = options.origin ?? baseOptions.origin;\n baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\n );\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n },\n): T | null => {\n const location = useLocation();\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const useModularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, location),\n [options, memoizedHref, location],\n );\n\n const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n"],"mappings":";AACA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,WAAW,QAAQ,aAAa;AAazC;AACA,MAAMC,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,QAAa,KACF;EAAA,IAAAC,QAAA;EACX,MAAMC,WAAW,GAAG;IAClBC,WAAW,EAAEC,SAAS;IACtBC,gBAAgB,EAAED,SAAS;IAC3BE,QAAQ,EAAE,KAAK;IACfC,MAAM,EAAEH,SAAS;IACjBI,WAAW,EAAEJ,SAAS;IACtBK,KAAK,EAAE;EACT,CAAC;;EAED;EACA,IAAIX,OAAO,CAACK,WAAW,EAAE;IACvBD,WAAW,CAACC,WAAW,GAAGL,OAAO,CAACK,WAAW;IAC7CD,WAAW,CAACG,gBAAgB,GAAGP,OAAO,CAACO,gBAAgB;EACzD;;EAEA;EACA,IAAIP,OAAO,CAACW,KAAK,EAAE;IACjBP,WAAW,CAACO,KAAK,GAAGX,OAAO,CAACW,KAAK;EACnC;;EAEA;EACA,IAAIT,QAAQ,CAACU,KAAK,EAAEC,MAAM,IAAIC,2BAAA,CAAAX,QAAA,GAAAD,QAAQ,CAACa,QAAQ,EAAAC,IAAA,CAAAb,QAAA,EAAYF,IAAI,CAAC,EAAE;IAChEG,WAAW,CAACI,QAAQ,GAAG,IAAI;EAC7B;;EAEA;EACAJ,WAAW,CAACK,MAAM,GAAGT,OAAO,CAACS,MAAM,IAAIL,WAAW,CAACK,MAAM;EACzDL,WAAW,CAACM,WAAW,GAAGV,OAAO,CAACU,WAAW,IAAIN,WAAW,CAACM,WAAW;EAExE,OAAON,WAAW;AACpB,CAAC;;AAED;AACA,MAAMa,aAAa,GAAGA,CAACC,KAAU,EAAEC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D,aAAa,CAACgB,SAAS,CAACf,KAAK,EAAEC,cAAc,CAAC;MAC9C,OAAOc,SAAS,CAACf,KAAK;IACxB;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CAACC,cAAc,EAAEc,SAAS,CAAC,CAAC;AACjC,CAAC","ignoreList":[]}
@@ -31,29 +31,31 @@ const useModularUI = function (modelKey, url) {
31
31
  const dispatch = (0, _reactRedux.useDispatch)();
32
32
  const href = (0, _react.useMemo)(() => url?.toString() || "", [url]);
33
33
  const key = useKeyForHook(modelKey, href);
34
+ const modelSelector = (0, _react.useMemo)(() => state => state.modularui[key], [key]);
35
+ const model = (0, _reactRedux.useSelector)(modelSelector);
34
36
  if (url instanceof _Href.default) {
35
37
  options.origin = options.origin ?? url.origin;
36
38
  options.contextPath = options.contextPath ?? url.contextPath;
37
39
  }
38
40
  const location = (0, _reactRouter.useLocation)();
39
41
  const redirectLocation = location.state?.redirectLocation;
40
- const forceReload = redirectLocation instanceof _Href.default ? redirectLocation?.equals(href) : false;
42
+ const forceLoad = model == null || (redirectLocation instanceof _Href.default ? redirectLocation?.equals(href) : false);
41
43
  const prevOptions = (0, _react.useRef)(options);
42
44
  const prevHref = (0, _react.useRef)(href);
43
- const prevForceReload = (0, _react.useRef)(forceReload);
45
+ const prevForceLoad = (0, _react.useRef)(forceLoad);
44
46
 
45
47
  // dispatch loadModularUI
46
48
  (0, _useDeepCompareEffect.default)(() => {
47
49
  // prevent reloads when previous option had the isReload, but the new options not
48
50
  const isOldReload = prevHref.current === href && prevOptions.current.isReload && !options.isReload;
49
- const doForceReload = forceReload && !prevForceReload.current;
50
- if (href !== "" && (doForceReload || !isOldReload)) {
51
+ const doForceLoad = forceLoad && !prevForceLoad.current;
52
+ if (href !== "" && (doForceLoad || !isOldReload)) {
51
53
  dispatch((0, _ModularUIActions.loadModularUI)(key, href, options));
52
54
  }
53
55
  prevOptions.current = options;
54
56
  prevHref.current = href;
55
- prevForceReload.current = forceReload;
56
- }, [key, href, options, forceReload]);
57
+ prevForceLoad.current = forceLoad;
58
+ }, [key, href, options, forceLoad]);
57
59
  (0, _react.useEffect)(() => {
58
60
  if (options.removeOnUnmount) {
59
61
  return () => {
@@ -61,8 +63,7 @@ const useModularUI = function (modelKey, url) {
61
63
  };
62
64
  }
63
65
  }, [dispatch, key, options.removeOnUnmount]);
64
- const selector = (0, _react.useMemo)(() => state => state.modularui[key], [key]);
65
- return (0, _reactRedux.useSelector)(selector);
66
+ return model;
66
67
  };
67
68
  exports.useModularUI = useModularUI;
68
69
  //# sourceMappingURL=useModularUI.js.map
@@ -41,6 +41,9 @@ export const useModularUI = (
41
41
  const href = useMemo(() => url?.toString() || "", [url]);
42
42
  const key = useKeyForHook(modelKey, href);
43
43
 
44
+ const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);
45
+ const model = useSelector(modelSelector);
46
+
44
47
  if (url instanceof Href) {
45
48
  options.origin = options.origin ?? url.origin;
46
49
  options.contextPath = options.contextPath ?? url.contextPath;
@@ -48,12 +51,13 @@ export const useModularUI = (
48
51
 
49
52
  const location = useLocation();
50
53
  const redirectLocation = location.state?.redirectLocation;
51
- const forceReload =
52
- redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;
54
+ const forceLoad =
55
+ model == null ||
56
+ (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);
53
57
 
54
58
  const prevOptions = useRef(options);
55
59
  const prevHref = useRef(href);
56
- const prevForceReload = useRef(forceReload);
60
+ const prevForceLoad = useRef(forceLoad);
57
61
 
58
62
  // dispatch loadModularUI
59
63
  useDeepCompareEffect(() => {
@@ -63,16 +67,16 @@ export const useModularUI = (
63
67
  prevOptions.current.isReload &&
64
68
  !options.isReload;
65
69
 
66
- const doForceReload = forceReload && !prevForceReload.current;
70
+ const doForceLoad = forceLoad && !prevForceLoad.current;
67
71
 
68
- if (href !== "" && (doForceReload || !isOldReload)) {
72
+ if (href !== "" && (doForceLoad || !isOldReload)) {
69
73
  dispatch(loadModularUI(key, href, options));
70
74
  }
71
75
 
72
76
  prevOptions.current = options;
73
77
  prevHref.current = href;
74
- prevForceReload.current = forceReload;
75
- }, [key, href, options, forceReload]);
78
+ prevForceLoad.current = forceLoad;
79
+ }, [key, href, options, forceLoad]);
76
80
 
77
81
  useEffect(() => {
78
82
  if (options.removeOnUnmount) {
@@ -82,6 +86,5 @@ export const useModularUI = (
82
86
  }
83
87
  }, [dispatch, key, options.removeOnUnmount]);
84
88
 
85
- const selector = useMemo(() => (state) => state.modularui[key], [key]);
86
- return useSelector(selector);
89
+ return model;
87
90
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useI18n","_Href","useKeyForHook","modelKey","url","locale","useLocale","useMemo","split","useModularUI","options","arguments","length","undefined","method","HTTP_METHODS","GET","removeOnUnmount","dispatch","useDispatch","href","toString","key","Href","origin","contextPath","location","useLocation","redirectLocation","state","forceReload","equals","prevOptions","useRef","prevHref","prevForceReload","useDeepCompareEffect","isOldReload","current","isReload","doForceReload","loadModularUI","useEffect","removeModelByKey","selector","modularui","useSelector","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceReload =\n redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceReload = useRef(forceReload);\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n // prevent reloads when previous option had the isReload, but the new options not\n const isOldReload =\n prevHref.current === href &&\n prevOptions.current.isReload &&\n !options.isReload;\n\n const doForceReload = forceReload && !prevForceReload.current;\n\n if (href !== \"\" && (doForceReload || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceReload.current = forceReload;\n }, [key, href, options, forceReload]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, options.removeOnUnmount]);\n\n const selector = useMemo(() => (state) => state.modularui[key], [key]);\n return useSelector(selector);\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAKA,IAAAK,qBAAA,GAAAC,sBAAA,CAAAN,OAAA;AAEA,IAAAO,QAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAIA;AACA;AACA,MAAMS,aAAa,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAK;EACvD,MAAMC,MAAM,GAAG,IAAAC,kBAAS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UI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useI18n","_Href","useKeyForHook","modelKey","url","locale","useLocale","useMemo","split","useModularUI","options","arguments","length","undefined","method","HTTP_METHODS","GET","removeOnUnmount","dispatch","useDispatch","href","toString","key","modelSelector","state","modularui","model","useSelector","Href","origin","contextPath","location","useLocation","redirectLocation","forceLoad","equals","prevOptions","useRef","prevHref","prevForceLoad","useDeepCompareEffect","isOldReload","current","isReload","doForceLoad","loadModularUI","useEffect","removeModelByKey","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\n\nimport { useLocale } from \"./useI18n\";\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n */\nconst useKeyForHook = (modelKey: string, url: string) => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n\n/**\n * Use redux action and selector to retrieve the correct modular ui service model\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useKeyForHook(modelKey, href);\n\n const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);\n const model = useSelector(modelSelector);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceLoad =\n model == null ||\n (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceLoad = useRef(forceLoad);\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n // prevent reloads when previous option had the isReload, but the new options not\n const isOldReload =\n prevHref.current === href &&\n prevOptions.current.isReload &&\n !options.isReload;\n\n const doForceLoad = forceLoad && !prevForceLoad.current;\n\n if (href !== \"\" && (doForceLoad || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceLoad.current = forceLoad;\n }, [key, href, options, forceLoad]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, options.removeOnUnmount]);\n\n return model;\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAKA,IAAAK,qBAAA,GAAAC,sBAAA,CAAAN,OAAA;AAEA,IAAAO,QAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAIA;AACA;AACA,MAAMS,aAAa,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAK;EACvD,MAAMC,MAAM,GAAG,IAAAC,kBAAS,EAAC,CAAC;EAC1B,OAAO,IAAAC,cAAO,EACZ,MAAM,GAAGJ,QAAQ,IAAIC,GAAG,CAACI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAKH,MAAM,GAAG,EACpD,CAACF,QAAQ,EAAEC,GAAG,EAAEC,MAAM,CACxB,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACO,MAAMI,YAAY,GAAG,SAAAA,CAC1BN,QAAgB,EAChBC,GAAkB,EAKV;EAAA,IAJRM,OAAgC,GAA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;;EAEvC;EACA,IAAAM,6BAAoB,EAAC,MAAM;IACzB;IACA,MAAMC,WAAW,GACfH,QAAQ,CAACI,OAAO,KAAKtB,IAAI,IACzBgB,WAAW,CAACM,OAAO,CAACC,QAAQ,IAC5B,CAACjC,OAAO,CAACiC,QAAQ;IAEnB,MAAMC,WAAW,GAAGV,SAAS,IAAI,CAACK,aAAa,CAACG,OAAO;IAEvD,IAAItB,IAAI,KAAK,EAAE,KAAKwB,WAAW,IAAI,CAACH,WAAW,CAAC,EAAE;MAChDvB,QAAQ,CAAC,IAAA2B,+BAAa,EAACvB,GAAG,EAAEF,IAAI,EAAEV,OAAO,CAAC,CAAC;IAC7C;IAEA0B,WAAW,CAACM,OAAO,GAAGhC,OAAO;IAC7B4B,QAAQ,CAACI,OAAO,GAAGtB,IAAI;IACvBmB,aAAa,CAACG,OAAO,GAAGR,SAAS;EACnC,CAAC,EAAE,CAACZ,GAAG,EAAEF,IAAI,EAAEV,OAAO,EAAEwB,SAAS,CAAC,CAAC;EAEnC,IAAAY,gBAAS,EAAC,MAAM;IACd,IAAIpC,OAAO,CAACO,eAAe,EAAE;MAC3B,OAAO,MAAM;QACXC,QAAQ,CAAC,IAAA6B,kCAAgB,EAACzB,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACJ,QAAQ,EAAEI,GAAG,EAAEZ,OAAO,CAACO,eAAe,CAAC,CAAC;EAE5C,OAAOS,KAAK;AACd,CAAC;AAACsB,OAAA,CAAAvC,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -9,7 +9,6 @@ var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js
9
9
  var _react = require("react");
10
10
  var _useModularUI = require("./useModularUI");
11
11
  var _useRouter = require("./useRouter");
12
- var _exceptions = require("../exceptions");
13
12
  // Helper to create useModularUI options
14
13
  const createUseModularUIOptions = (options, href, location) => {
15
14
  var _context;
@@ -49,8 +48,7 @@ const validateModel = (model, expectedModels) => {
49
48
  if (expectedModels.length > 0) {
50
49
  const isCorrectModel = expectedModels.some(expectedModel => model.type === expectedModel);
51
50
  if (!isCorrectModel) {
52
- console.error(model, "is not of instance", expectedModels);
53
- throw new _exceptions.IllegalStateException("Resolved model has incorrect type");
51
+ console.warn(model, "is not of instance", expectedModels);
54
52
  }
55
53
  }
56
54
  };
@@ -2,7 +2,7 @@
2
2
  import { useMemo } from "react";
3
3
  import { useModularUI } from "./useModularUI";
4
4
  import { useLocation } from "./useRouter";
5
- import { IllegalStateException } from "../exceptions";
5
+
6
6
  import type { ModularUIModel, Href } from "../models";
7
7
 
8
8
  export type UseModularUIBasicOptions<T: ModularUIModel> = {
@@ -59,8 +59,7 @@ const validateModel = (model: any, expectedModels: Array<string>) => {
59
59
  (expectedModel) => model.type === expectedModel,
60
60
  );
61
61
  if (!isCorrectModel) {
62
- console.error(model, "is not of instance", expectedModels);
63
- throw new IllegalStateException("Resolved model has incorrect type");
62
+ console.warn(model, "is not of instance", expectedModels);
64
63
  }
65
64
  }
66
65
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIBasic.js","names":["_react","require","_useModularUI","_useRouter","_exceptions","createUseModularUIOptions","options","href","location","_context","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","state","reload","_startsWith","default","pathname","call","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","error","IllegalStateException","useModularUIBasic","key","arguments","useLocation","memoizedHref","useMemo","toString","useModularUIOptions","modularUI","useModularUI","exports"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\nimport { useLocation } from \"./useRouter\";\nimport { IllegalStateException } from \"../exceptions\";\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n location: any,\n): Object => {\n const baseOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n };\n\n // Handle targetModel and forceTargetModel\n if (options.targetModel) {\n baseOptions.targetModel = options.targetModel;\n baseOptions.forceTargetModel = options.forceTargetModel;\n }\n\n // Handle cache option\n if (options.cache) {\n baseOptions.cache = options.cache;\n }\n\n // Check for reload if location matches href\n if (location.state?.reload && location.pathname.startsWith(href)) {\n baseOptions.isReload = true;\n }\n\n // Handle origin and contextPath options\n baseOptions.origin = options.origin ?? baseOptions.origin;\n baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\n );\n if (!isCorrectModel) {\n console.error(model, \"is not of instance\", expectedModels);\n throw new IllegalStateException(\"Resolved model has incorrect type\");\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n },\n): T | null => {\n const location = useLocation();\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const useModularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, location),\n [options, memoizedHref, location],\n );\n\n const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n"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,SAAS,CAAClB,KAAK,EAAEC,cAAc,CAAC;MAC9C,OAAOiB,SAAS,CAAClB,KAAK;IACxB;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CAACC,cAAc,EAAEiB,SAAS,CAAC,CAAC;AACjC,CAAC;AAACE,OAAA,CAAAV,iBAAA,GAAAA,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIBasic.js","names":["_react","require","_useModularUI","_useRouter","createUseModularUIOptions","options","href","location","_context","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","state","reload","_startsWith","default","pathname","call","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","warn","useModularUIBasic","key","arguments","useLocation","memoizedHref","useMemo","toString","useModularUIOptions","modularUI","useModularUI","exports"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\nimport { useLocation } from \"./useRouter\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n location: any,\n): Object => {\n const baseOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n };\n\n // Handle targetModel and forceTargetModel\n if (options.targetModel) {\n baseOptions.targetModel = options.targetModel;\n baseOptions.forceTargetModel = options.forceTargetModel;\n }\n\n // Handle cache option\n if (options.cache) {\n baseOptions.cache = options.cache;\n }\n\n // Check for reload if location matches href\n if (location.state?.reload && location.pathname.startsWith(href)) {\n baseOptions.isReload = true;\n }\n\n // Handle origin and contextPath options\n baseOptions.origin = options.origin ?? baseOptions.origin;\n baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\n );\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n },\n): T | null => {\n const location = useLocation();\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const useModularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, location),\n [options, memoizedHref, location],\n );\n\n const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAaA;AACA,MAAMG,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,QAAa,KACF;EAAA,IAAAC,QAAA;EACX,MAAMC,WAAW,GAAG;IAClBC,WAAW,EAAEC,SAAS;IACtBC,gBAAgB,EAAED,SAAS;IAC3BE,QAAQ,EAAE,KAAK;IACfC,MAAM,EAAEH,SAAS;IACjBI,WAAW,EAAEJ,SAAS;IACtBK,KAAK,EAAE;EACT,CAAC;;EAED;EACA,IAAIX,OAAO,CAACK,WAAW,EAAE;IACvBD,WAAW,CAACC,WAAW,GAAGL,OAAO,CAACK,WAAW;IAC7CD,WAA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J,QAAQ,GAAG,IAAA6B,sBAAW,EAAC,CAAC;EAC9B,MAAMC,YAAY,GAAG,IAAAC,cAAO,EAAC,MAAMhC,IAAI,CAACiC,QAAQ,CAAC,CAAC,EAAE,CAACjC,IAAI,CAAC,CAAC;EAC3D,MAAMkC,mBAAmB,GAAG,IAAAF,cAAO,EACjC,MAAMlC,yBAAyB,CAACC,OAAO,EAAEgC,YAAY,EAAE9B,QAAQ,CAAC,EAChE,CAACF,OAAO,EAAEgC,YAAY,EAAE9B,QAAQ,CAClC,CAAC;EAED,MAAMkC,SAAS,GAAG,IAAAC,0BAAY,EAACR,GAAG,EAAEG,YAAY,EAAEG,mBAAmB,CAAC;EACtE,MAAMf,cAAc,GAAG,IAAAa,cAAO,EAC5B,MAAMjC,OAAO,CAACoB,cAAc,IAAI,EAAE,EAClC,CAACpB,OAAO,CAACoB,cAAc,CACzB,CAAC;EAED,OAAO,IAAAa,cAAO,EAAC,MAAgB;IAC7B,IAAIG,SAAS,EAAEjB,KAAK,EAAE;MACpBD,aAAa,CAACkB,SAAS,CAACjB,KAAK,EAAEC,cAAc,CAAC;MAC9C,OAAOgB,SAAS,CAACjB,KAAK;IACxB;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CAACC,cAAc,EAAEgB,SAAS,CAAC,CAAC;AACjC,CAAC;AAACE,OAAA,CAAAV,iBAAA,GAAAA,iBAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.57.1",
3
+ "version": "1.57.2",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -41,6 +41,9 @@ export const useModularUI = (
41
41
  const href = useMemo(() => url?.toString() || "", [url]);
42
42
  const key = useKeyForHook(modelKey, href);
43
43
 
44
+ const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);
45
+ const model = useSelector(modelSelector);
46
+
44
47
  if (url instanceof Href) {
45
48
  options.origin = options.origin ?? url.origin;
46
49
  options.contextPath = options.contextPath ?? url.contextPath;
@@ -48,12 +51,13 @@ export const useModularUI = (
48
51
 
49
52
  const location = useLocation();
50
53
  const redirectLocation = location.state?.redirectLocation;
51
- const forceReload =
52
- redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;
54
+ const forceLoad =
55
+ model == null ||
56
+ (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);
53
57
 
54
58
  const prevOptions = useRef(options);
55
59
  const prevHref = useRef(href);
56
- const prevForceReload = useRef(forceReload);
60
+ const prevForceLoad = useRef(forceLoad);
57
61
 
58
62
  // dispatch loadModularUI
59
63
  useDeepCompareEffect(() => {
@@ -63,16 +67,16 @@ export const useModularUI = (
63
67
  prevOptions.current.isReload &&
64
68
  !options.isReload;
65
69
 
66
- const doForceReload = forceReload && !prevForceReload.current;
70
+ const doForceLoad = forceLoad && !prevForceLoad.current;
67
71
 
68
- if (href !== "" && (doForceReload || !isOldReload)) {
72
+ if (href !== "" && (doForceLoad || !isOldReload)) {
69
73
  dispatch(loadModularUI(key, href, options));
70
74
  }
71
75
 
72
76
  prevOptions.current = options;
73
77
  prevHref.current = href;
74
- prevForceReload.current = forceReload;
75
- }, [key, href, options, forceReload]);
78
+ prevForceLoad.current = forceLoad;
79
+ }, [key, href, options, forceLoad]);
76
80
 
77
81
  useEffect(() => {
78
82
  if (options.removeOnUnmount) {
@@ -82,6 +86,5 @@ export const useModularUI = (
82
86
  }
83
87
  }, [dispatch, key, options.removeOnUnmount]);
84
88
 
85
- const selector = useMemo(() => (state) => state.modularui[key], [key]);
86
- return useSelector(selector);
89
+ return model;
87
90
  };
@@ -2,7 +2,7 @@
2
2
  import { useMemo } from "react";
3
3
  import { useModularUI } from "./useModularUI";
4
4
  import { useLocation } from "./useRouter";
5
- import { IllegalStateException } from "../exceptions";
5
+
6
6
  import type { ModularUIModel, Href } from "../models";
7
7
 
8
8
  export type UseModularUIBasicOptions<T: ModularUIModel> = {
@@ -59,8 +59,7 @@ const validateModel = (model: any, expectedModels: Array<string>) => {
59
59
  (expectedModel) => model.type === expectedModel,
60
60
  );
61
61
  if (!isCorrectModel) {
62
- console.error(model, "is not of instance", expectedModels);
63
- throw new IllegalStateException("Resolved model has incorrect type");
62
+ console.warn(model, "is not of instance", expectedModels);
64
63
  }
65
64
  }
66
65
  };