MCPcopy
hub / github.com/directus/directus / hydrate

Function hydrate

app/src/hydrate.ts:49–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47}
48
49export async function hydrate(): Promise<void> {
50 const stores = useStores();
51
52 const appStore = useAppStore();
53 const userStore = useUserStore();
54 const permissionsStore = usePermissionsStore();
55 const fieldsStore = useFieldsStore();
56
57 if (appStore.hydrated) return;
58 if (appStore.hydrating) return;
59
60 appStore.hydrating = true;
61
62 try {
63 /**
64 * @NOTE
65 * Multiple stores rely on the userStore to be set, so they can fetch user specific data. The
66 * following makes sure that the user store is always fetched first, before we hydrate anything
67 * else.
68 */
69 await userStore.hydrate();
70
71 const currentUser = userStore.currentUser;
72
73 if (currentUser?.app_access) {
74 await Promise.all([permissionsStore.hydrate(), fieldsStore.hydrate({ skipTranslation: true })]);
75
76 const hydratedStores = ['userStore', 'permissionsStore', 'fieldsStore', 'serverStore'];
77 await Promise.all(stores.filter(({ $id }) => !hydratedStores.includes($id)).map((store) => store.hydrate?.()));
78
79 await onHydrateExtensions();
80 }
81
82 await setLanguage(userStore.language);
83
84 appStore.basemap = getBasemapSources()[0].name;
85 } catch (error: any) {
86 appStore.error = error;
87 } finally {
88 appStore.hydrating = false;
89 }
90
91 appStore.hydrated = true;
92}
93
94export async function dehydrate(stores = useStores()): Promise<void> {
95 const appStore = useAppStore();

Callers 3

hydrate.test.tsFile · 0.90
onBeforeEachFunction · 0.90
loginFunction · 0.90

Calls 4

onHydrateExtensionsFunction · 0.90
setLanguageFunction · 0.90
getBasemapSourcesFunction · 0.90
useStoresFunction · 0.70

Tested by

no test coverage detected