-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constructor not entirely suitable as created hook (has wrong this
)
#26
Comments
Looking at your If not, here's a suggestion from a colleague: export default function VueStore<T extends C> (constructor: T): T {
function construct (...args: any[]) {
const instance = new (constructor as C)(...args)
const vue = makeVue(instance)
if (typeof vue['created'] === 'function') vue.created()
return vue
}
return (construct as unknown) as T
} If it exists, call |
Hey there, Thanks for trying the lib and I'm glad you're enjoying it so much! Good catch here. I'm really restricted on time for OSS right now, but would like to give this some attention. I also have a bunch of utilities I want to add to the library, so hopefully it won't be too long until I get to this. Will you OK with the workarounds in the meantime? |
Hi, thanks for your reply. Still experimenting with your lib and really liking its direction. I feel that this issue #26 & issue #14 (object replacement reactivity) are stumbling blocks to adopting this more widely, because they break from the patterns of typical Vue components, and would likely introduce mistakes in use. The workarounds are awkward at best. Fully understand your time constraints. If I learn a bit more about Vue's internals, I may be able to offer a PR (but not very soon). Do you think the Thanks for any advice! |
No idea right now! Would have to refamiliarize myself with the code! :P |
Experimenting with
vue-class-store
as a replacement for Vuex and loving it so far. However...The following example does not work as expected. Setting local properties in the constructor does work, but calling methods that reference
this
will have a bad reference.Workaround (somewhat awkward):
Decorator workaround (still awkward):
Maybe this can be fixed in a more elegant way? Any advice is most welcome. Thanks for your work on this project!
The text was updated successfully, but these errors were encountered: