Skip to content

Instantly share code, notes, and snippets.

@vikramsoni2
Created May 12, 2024 01:16
Show Gist options
  • Select an option

  • Save vikramsoni2/6cddcf99587d538182c3e13c21848f7b to your computer and use it in GitHub Desktop.

Select an option

Save vikramsoni2/6cddcf99587d538182c3e13c21848f7b to your computer and use it in GitHub Desktop.

Revisions

  1. vikramsoni2 created this gist May 12, 2024.
    34 changes: 34 additions & 0 deletions uppyStore.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import { defineStore } from 'pinia';

    export const useUppyStore = defineStore({
    id: 'uppyStore',
    state: () => ({
    state: {}
    }),

    actions: {

    getState() {
    return this.state;
    },

    setState(patch) {
    const prevState = this.state;
    const nextState = { ...prevState, ...patch };

    this.state = nextState;

    this.$patch({
    state: nextState
    });
    },
    subscribe(listener) {
    const unsubscribe = this.$subscribe((mutation, state) => {
    const patch = mutation.payload;
    listener(mutation.oldState, state, patch);
    }, { immediate: true });

    return unsubscribe;
    }
    }
    });