@wener/console
Version:
Base console UI toolkit
31 lines (30 loc) • 1.04 kB
JavaScript
import { createBoundedUseStore } from '@wener/reaction/zustand';
import { computeIfAbsent, getGlobalStates } from '@wener/utils';
import { merge } from 'es-toolkit';
import { createStore } from 'zustand';
import { mutative } from 'zustand-mutative';
function createSiteStore() {
return createStore(mutative(function(setState, getState, store) {
return {
title: '',
baseUrl: typeof window === 'undefined' ? 'http://localhost:3000' : window.location.origin,
metadata: {},
features: [],
load: function load(init) {
if (!init) {
return;
}
setState(function(s) {
merge(s, init);
});
}
};
}));
}
export function getSiteState() {
return getSiteStore().getState();
}
export function getSiteStore() {
return computeIfAbsent(getGlobalStates(), 'SiteStore', createSiteStore);
}
export var useSiteStore = createBoundedUseStore(getSiteStore);