From afcdfa54c8d23182cf302e3cc3d8456a4f74f7b9 Mon Sep 17 00:00:00 2001 From: Glandos Date: Thu, 18 Mar 2021 15:49:13 +0100 Subject: [PATCH 1/2] Fix local watcher example If the `$watch` is not static, then it is part of the object constructor in TypeScript and not part of the object prototype, so it can't be accessed from [`createLocalWatchers`](https://github.com/michaelolof/vuex-class-component/blob/master/src/proxy.ts#L222). --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54f3dca..47d977a 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,7 @@ export class UserStore extends VuexModule.With({ namespaced: "user" }) { return this.firstname + " " + this.lastname; } - $watch = { + static $watch = { fullname( newValue ) { console.log( `Fullname has changed ${newValue}` }, } From 3ee4604cd59b201db012fb836dcee1b730755e1b Mon Sep 17 00:00:00 2001 From: Glandos Date: Thu, 18 Mar 2021 15:54:49 +0100 Subject: [PATCH 2/2] Type this to be able to use it Since the watcher is called with the class instance as `this`, tell TypeScript to use it. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47d977a..dafb7de 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ export class UserStore extends VuexModule.With({ namespaced: "user" }) { } static $watch = { - fullname( newValue ) { console.log( `Fullname has changed ${newValue}` }, + fullname( this: UserStore, newValue ) { console.log( `Fullname has changed ${newValue}` }, } $subscribe = {