Created
May 12, 2024 01:16
-
-
Save vikramsoni2/6cddcf99587d538182c3e13c21848f7b to your computer and use it in GitHub Desktop.
Pinia Store for uppy js for keeping track of file upload state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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