Skip to content

Instantly share code, notes, and snippets.

@vikramsoni2
Created May 12, 2024 01:16
Show Gist options
  • Save vikramsoni2/6cddcf99587d538182c3e13c21848f7b to your computer and use it in GitHub Desktop.
Save vikramsoni2/6cddcf99587d538182c3e13c21848f7b to your computer and use it in GitHub Desktop.
Pinia Store for uppy js for keeping track of file upload state
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;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment