How to use the vuex.createStore function in vuex

To help you get started, we’ve selected a few vuex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facette / facette / ui / src / store.ts View on Github external
public pendingNotification: Notification | null = null;

    public prevRoute: RouteLocationNormalized | null = null;

    public sidebar = true;

    public theme: string | null = null;

    public timeRange: TimeRange | null = null;

    public timezoneUTC = false;
}

const state = new State();

const store = createStore({
    state,
    mutations: Object.getOwnPropertyNames(state).reduce((tree: MutationTree, name: string) => {
        tree[name] = (state: State, value: unknown): void => {
            (state as any)[name] = value;
        };
        return tree;
    }, {}),
    plugins: [persist()],
});

function persist() {
    const save = (state: State): void => {
        localStorage.setItem(
            persistKey,
            JSON.stringify({
                autoPropagate: state.autoPropagate,