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

How to load modules dynamically? #16

Open
eyasman opened this issue Aug 6, 2020 · 2 comments
Open

How to load modules dynamically? #16

eyasman opened this issue Aug 6, 2020 · 2 comments

Comments

@eyasman
Copy link

eyasman commented Aug 6, 2020

editor.use(ModulePlugin.default, { engine, modules });

I'm looking for a way to tell the engine that modules have been updated.

@eyasman
Copy link
Author

eyasman commented Aug 6, 2020

After updating the modules:

	modules = JSON.parse(reader.result); //getting modules from JSON
	re_alight(); //redrawing the received modules in html modules menu

When trying to open the index editor view
I'm getting 'IO not found for node XXX', only the Module Nodes appear without any ports, all other Nodes are displayed properly.

When I open the Modules in editor view, they have properly named input and output Ports.

Same JSON file for Modules displays fine if provided to the ModulePlugin here: editor.use(ModulePlugin.default, { engine, modules });

@Photon-Engineer
Copy link

Photon-Engineer commented Dec 13, 2020

I just ran into this exact issue as well and found a solution. I'll try my best to explain what's going on, but be aware I'm 100% self taught so I may not know the right words to describe everything.

Here's what I think is happening. When you assign the modules object to the editor in the line:
editor.use(ModulePlugin.default, { engine, modules });
You are creating a reference to that object in your systems memory, that you and the rete program can use to make changes to modules as the software is used.
The problem is, the line:
modules = JSON.parse(reader.result); //getting modules from JSON
This line is not updating the original object that you and rete originally were using, it instead creates a new object in the systems memory and assigns it to that variable. Now, you have access to the new object, but you've lost your reference to the original object still in use by the rete code.

The solution is to modify your object without completely re-creating it. See the answer by georg in the following stack exchange question https://stackoverflow.com/questions/26957719/replace-object-value-without-replacing-reference. Copy that "modify" function into your script, then change the above line in your code to instead be:
modify(modules,JSON.parse(reader.result));

This is what worked for me. Hopefully that makes some sense.

Good luck!

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