gumball12 / pinia-plugin-watch Goto Github PK
View Code? Open in Web Editor NEW[WIP] ๐ The easiest way to watch for your Pinia State.
Home Page: https://www.npmjs.com/package/pinia-plugin-watch
License: MIT License
[WIP] ๐ The easiest way to watch for your Pinia State.
Home Page: https://www.npmjs.com/package/pinia-plugin-watch
License: MIT License
I am watching a Boolean in the state and if it is false I want to update the value of another state variable but this is not defined. How would i access the current stores state from a watcher?
i've tried the following:
watch: {
showOptions(showOptions) {
if (!showOptions) {
this.sendEmail = false
}
}
}
and
watch: {
showOptions: (showOptions) => {
if (!showOptions) {
this.sendEmail = false
}
}
}
const useStore = defineStore('store', {
state: () => ({
countA: 1,
countB: 1,
}),
watch: {
countA: () => {
console.log('changed');
},
},
});
const store = useStore();
store.countA = 2; // "changed"
store.$watch.countA(); // clear watch.countA
store.countA = 3; // nothing
The actual defined Watch structure and the type inference structure when accessing the $watch property are different.
const useStore = defineStore('store', {
state: () => ({
countA: 1,
countB: 1,
}),
watch: {
countA: () => {},
},
});
const store = useStore();
store.$watch.countA; // inferred type: `Watcher<number> | undefined`, but actually `Watcher<number>`
store.$watch.countB; // inferred type: `Watcher<number> | undefined`, but actually `undefined`
This module needs to be able to use the WatchOptions
provided by Vue watch.
{
watch: {
handler: Function;
// Vue `WatchOptions`
immediate?: boolean // default: false
deep?: boolean // default: false
flush?: 'pre' | 'post' | 'sync' // default: 'pre'
onTrack?: (event: DebuggerEvent) => void
onTrigger?: (event: DebuggerEvent) => void
once?: boolean // default: false (3.4+)
},
}
Also, make sure to set the WatchOptions defaults to the same as Vue. Currently, the default value for the deep option is true
, but Vue uses false
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.