Closed softwarerero closed 7 years ago
It is a bug. It's not firing the change event for shared (probably mixed too) dependencies that change inside an autorun. I'll fix it.
Trying to fix this I'm a little stuck. When I change https://github.com/ManuelDeLeon/viewmodel-react/blob/master/src/viewmodel.js#L96 to ViewModel.shared[key][prop] = ViewModel.prop(content, obj);
the property is updated to the new value but I get an error TypeError: c.vmChange is not a function. (In 'c.vmChange()', 'c.vmChange' is undefined)
.
When I now try to fix this and change https://github.com/ManuelDeLeon/viewmodel-react/blob/master/src/viewmodel.js#L110 to if (c.vmChange !== undefined) c.vmChange();
the property is not updated anymore.
Alright, here's what's happening... ViewModel.share
creates the shared properties immediately using whatever Tracker
it has at the time. In your case you're adding the share before calling ViewModel.Tracker = Tracker;
. So in the end the shared properties are using one tracker while the rest of the app is using another.
Your options are:
1) Move ViewModel.Tracker = Tracker;
to the start of the shares.js
file.
2) Don't use Meteor's tracker. If you use VM for everything you don't need to call ViewModel.Tracker = Tracker;
.
Thanks Manuel for looking into this. Both methods seem to have their drwabacks.
I don't know what you mean. Can you create 2 branches in test-vm-share
showing both cases?
Thanks
I just found that a scenario that woked for me. If I set ViewModel.Tracker
to the Meteor tracker in main.js file and again in shares.js everything works as expected. So I think we can leave this ticekt closed.
When a shared object's property is reassigned reactivity is not triggered. A test repository is here: https://github.com/softwarerero/test-vm-share.