@mittwald/flow-react-components 0.2.0-experimental.751 → 0.2.0-experimental.752
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.
|
@@ -12,23 +12,24 @@ const useSettings = () => useContext(context);
|
|
|
12
12
|
const SettingsProvider = (props) => {
|
|
13
13
|
const { children, middleware, id, ...storeShape } = props;
|
|
14
14
|
const backend = settingsBackendFactory(storeShape);
|
|
15
|
-
const
|
|
15
|
+
const settingsResource = getAsyncResource(() => backend.load(), [], {
|
|
16
16
|
loaderId: id
|
|
17
17
|
});
|
|
18
|
-
const
|
|
18
|
+
const settings = settingsResource.use();
|
|
19
19
|
const storingPromise = useRef(Promise.resolve());
|
|
20
20
|
const parentStore = useSettings();
|
|
21
21
|
const settingsStore = useMemo(
|
|
22
|
-
() => SettingsStore.fromJson(
|
|
23
|
-
[
|
|
22
|
+
() => SettingsStore.fromJson(settings, { middleware, parentStore }),
|
|
23
|
+
[id]
|
|
24
24
|
);
|
|
25
25
|
const watchAndStoreSettings = () => {
|
|
26
26
|
const json = settingsStore.asJson;
|
|
27
27
|
storingPromise.current = storingPromise.current.then(async () => {
|
|
28
28
|
await backend.store(json);
|
|
29
|
+
settingsResource.refresh();
|
|
29
30
|
});
|
|
30
31
|
};
|
|
31
|
-
useEffect(() => autorun(watchAndStoreSettings), [
|
|
32
|
+
useEffect(() => autorun(watchAndStoreSettings), [id]);
|
|
32
33
|
return /* @__PURE__ */ jsx(context.Provider, { value: settingsStore, children });
|
|
33
34
|
};
|
|
34
35
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettingsProvider.mjs","sources":["../../../../../../src/components/SettingsProvider/SettingsProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { createContext, useContext, useEffect, useMemo, useRef } from \"react\";\nimport type { SupportedSettingsBackend } from \"@/components/SettingsProvider/backends/types\";\nimport { autorun } from \"mobx\";\nimport { getAsyncResource } from \"@mittwald/react-use-promise\";\nimport {\n SettingsStore,\n type SettingsStoreOptions,\n} from \"@/components/SettingsProvider/models/SettingsStore\";\nimport { settingsBackendFactory } from \"@/components/SettingsProvider/backends/settingsBackendFactory\";\n\ntype Props = PropsWithChildren &\n SupportedSettingsBackend & {\n id?: string;\n } & Pick<SettingsStoreOptions, \"middleware\">;\n\nconst context = createContext<SettingsStore | undefined>(undefined);\n\nexport const useSettings = () => useContext(context);\n\nexport const SettingsProvider: FC<Props> = (props) => {\n const { children, middleware, id, ...storeShape } = props;\n const backend = settingsBackendFactory(storeShape);\n\n const
|
|
1
|
+
{"version":3,"file":"SettingsProvider.mjs","sources":["../../../../../../src/components/SettingsProvider/SettingsProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { createContext, useContext, useEffect, useMemo, useRef } from \"react\";\nimport type { SupportedSettingsBackend } from \"@/components/SettingsProvider/backends/types\";\nimport { autorun } from \"mobx\";\nimport { getAsyncResource } from \"@mittwald/react-use-promise\";\nimport {\n SettingsStore,\n type SettingsStoreOptions,\n} from \"@/components/SettingsProvider/models/SettingsStore\";\nimport { settingsBackendFactory } from \"@/components/SettingsProvider/backends/settingsBackendFactory\";\n\ntype Props = PropsWithChildren &\n SupportedSettingsBackend & {\n id?: string;\n } & Pick<SettingsStoreOptions, \"middleware\">;\n\nconst context = createContext<SettingsStore | undefined>(undefined);\n\nexport const useSettings = () => useContext(context);\n\nexport const SettingsProvider: FC<Props> = (props) => {\n const { children, middleware, id, ...storeShape } = props;\n const backend = settingsBackendFactory(storeShape);\n\n const settingsResource = getAsyncResource(() => backend.load(), [], {\n loaderId: id,\n });\n const settings = settingsResource.use();\n\n const storingPromise = useRef(Promise.resolve());\n const parentStore = useSettings();\n\n const settingsStore = useMemo(\n () => SettingsStore.fromJson(settings, { middleware, parentStore }),\n [id],\n );\n\n const watchAndStoreSettings = () => {\n const json = settingsStore.asJson;\n storingPromise.current = storingPromise.current.then(async () => {\n await backend.store(json);\n settingsResource.refresh();\n });\n };\n\n useEffect(() => autorun(watchAndStoreSettings), [id]);\n\n return <context.Provider value={settingsStore}>{children}</context.Provider>;\n};\n\nexport default SettingsProvider;\n"],"names":[],"mappings":";;;;;;;AAgBA,MAAM,OAAA,GAAU,cAAyC,MAAS,CAAA;AAE3D,MAAM,WAAA,GAAc,MAAM,UAAA,CAAW,OAAO;AAE5C,MAAM,gBAAA,GAA8B,CAAC,KAAA,KAAU;AACpD,EAAA,MAAM,EAAE,QAAA,EAAU,UAAA,EAAY,EAAA,EAAI,GAAG,YAAW,GAAI,KAAA;AACpD,EAAA,MAAM,OAAA,GAAU,uBAAuB,UAAU,CAAA;AAEjD,EAAA,MAAM,mBAAmB,gBAAA,CAAiB,MAAM,QAAQ,IAAA,EAAK,EAAG,EAAC,EAAG;AAAA,IAClE,QAAA,EAAU;AAAA,GACX,CAAA;AACD,EAAA,MAAM,QAAA,GAAW,iBAAiB,GAAA,EAAI;AAEtC,EAAA,MAAM,cAAA,GAAiB,MAAA,CAAO,OAAA,CAAQ,OAAA,EAAS,CAAA;AAC/C,EAAA,MAAM,cAAc,WAAA,EAAY;AAEhC,EAAA,MAAM,aAAA,GAAgB,OAAA;AAAA,IACpB,MAAM,aAAA,CAAc,QAAA,CAAS,UAAU,EAAE,UAAA,EAAY,aAAa,CAAA;AAAA,IAClE,CAAC,EAAE;AAAA,GACL;AAEA,EAAA,MAAM,wBAAwB,MAAM;AAClC,IAAA,MAAM,OAAO,aAAA,CAAc,MAAA;AAC3B,IAAA,cAAA,CAAe,OAAA,GAAU,cAAA,CAAe,OAAA,CAAQ,IAAA,CAAK,YAAY;AAC/D,MAAA,MAAM,OAAA,CAAQ,MAAM,IAAI,CAAA;AACxB,MAAA,gBAAA,CAAiB,OAAA,EAAQ;AAAA,IAC3B,CAAC,CAAA;AAAA,EACH,CAAA;AAEA,EAAA,SAAA,CAAU,MAAM,OAAA,CAAQ,qBAAqB,CAAA,EAAG,CAAC,EAAE,CAAC,CAAA;AAEpD,EAAA,2BAAQ,OAAA,CAAQ,QAAA,EAAR,EAAiB,KAAA,EAAO,eAAgB,QAAA,EAAS,CAAA;AAC3D;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/flow-react-components",
|
|
3
|
-
"version": "0.2.0-experimental.
|
|
3
|
+
"version": "0.2.0-experimental.752",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A React implementation of Flow, mittwald’s design system",
|
|
6
6
|
"homepage": "https://mittwald.github.io/flow",
|