Skip to content
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

Update instances when class definition changes after module reload #20

Closed
levjj opened this issue Jun 25, 2016 · 2 comments
Closed

Update instances when class definition changes after module reload #20

levjj opened this issue Jun 25, 2016 · 2 comments

Comments

@levjj
Copy link

levjj commented Jun 25, 2016

When using modules in workspaces such as in the example below, changes to the foo method are automatically applied to the instance a in the second workspace when evaluating the whole workspace content.

semantics1

However, this does not work when just working with modules. In particular, the combination of moduleWrite and reloadModule only reloads modules that depend on the updated module but instances of classes will still use the old method definition.

As a workaround, it is possible to simply re-evaluate the entire module with lively.vm but it seems this should happen automatically with reloadModule.

@rksm
Copy link
Member

rksm commented Jun 26, 2016

reloadModule can keep the identity of objects when you tell it to keep its environment via passing options. However we specifically do not need to reload modules when we save them. Particularly for the purpose of commiting a module change we have the moduleSourceChange method that should be used from within a tool via system. interactivelyChangeModule. This method uses a mechanism that ensures the identity of classes and exports and will properly update the instances of your classes.

@rksm rksm closed this as completed Jun 26, 2016
@levjj
Copy link
Author

levjj commented Jun 26, 2016

Okay, this would probably solve the issue. However, the method interactivelyChangeModule can only be used by the vmEditor (or tools with a method updateModuleList) due to this line:

await vmEditor.updateModuleList();

Instead, I would suggest to use notifications, so tools can subscribe to "moduleChange" and similar events. With the current implementation , other tools or multiple instances of the vmEditor are not supported (with multiple vmEditors only one will update, leading to an inconsistent state).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants