yukatan / commangular

Command framework for AngularJS
MIT License
83 stars 8 forks source link

Commangular command initialization on dynamic module loading #11

Open tstankevicius opened 9 years ago

tstankevicius commented 9 years ago

Hello, our angular application loads modules dynamically on demand using ocLazyLoad library. First module is loaded on index.html render dynamically. Then that module loads another module on button click.

Module A:

Module B:

moduleBcommand flow has both commands configured to run:

$commangularProvider.mapTo('Event') .asSequence() .add('CommandA') .add('CommandB');

The issue is that this flow does not see CommandA on runtime when ModuleB is loaded and command flow is launched.

Could you please explain what is the lifecycle of commangular command registration and would it be possible to let ModuleB know about Command A loaded before.

Same issue happens with Aspects. If I define aspect in Module A, then aspect gets executed only to commands loaded together with ModuleA, but never for commands in ModuleB. It looks like the Aspect initializes on commangular module load and only intercepts commands registered on the same moment. But it is not capable to intercept commands on runtime which gets created later.

Thank you.

yukatan commented 9 years ago

Commangular wasn't developed with dynamic module load in mind, but it should work. Use the last release 0.9.0. I added a new method in the commangular namespace "commangular.build()" Just add a run block to the module that is loaded dynamically and execute commangular.build() inside.

Be sure you are not loading commangular.js again or something like that.

All the command descriptor are added to the commangular namespace so it should add new commands without problems. If this not work for you, just let me know and it would be perfect if you send me the example to check it out.

tstankevicius commented 9 years ago

With new version commands gets executed ok from different modules even without calling commangular.build() function.

But not for aspects. I did suggested changes. Unfortunately, it then executes aspect twice for CommandA instead of once, but still does not execute it for CommandB of dynamically loaded module.

I still need to prepare code sample for aspect issue. Once I have it, I will post it here.

yukatan commented 9 years ago

Ok perfect. I'll check the code and I'll develop a test with dynamic load to fix the problem. I understand why it is executed twice... I know where is the problem now. I'm waiting the code sample. Thanks

tstankevicius commented 9 years ago

Hello,

I created a sample project for this issue. Could you please:

1) Unzip 2) npm install 3) bower install 4) gulp serve

The app with main module will be loaded on screen with button. The main module also executes Commangular aspect with Hello World command from main module. You can see that in Console.

Click the button to load another module "One". It loads module "One" files and executes command "OneCommand" WITHOUT aspect to be executed first. You can see that in Console as well.

Please let me know if you have any issues.

Thank you for your help.

On Tue, Mar 17, 2015 at 10:42 AM, Jesús Barquín Cheda < notifications@github.com> wrote:

Ok perfect. I'll check the code and I'll develop a test with dynamic load to fix the problem. I understand why it is executed twice... I know where is the problem now. I'm waiting the code sample. Thanks

— Reply to this email directly or view it on GitHub https://github.com/yukatan/commangular/issues/11#issuecomment-82246758.

Pagarbiai Tomas Stankevičius +37065641051

yukatan commented 9 years ago

Thanks, I've the sample. I'm trying to fix the issue

yukatan commented 9 years ago

I've been trying with more simple modules and more experiments with dinamic module loading and commangular still works as expected.

I suppose there is an async execution related issue, very hard to reproduce, so if you find some way to do it, just let me know and I will do my best to fix it.

tstankevicius commented 9 years ago

thank you Jesus.

On Thu, Apr 9, 2015 at 3:24 PM, Jesús Barquín Cheda < notifications@github.com> wrote:

I've been trying with more simple modules and more experiments with dinamic module loading and commangular still works as expected.

I suppose there is an async execution related issue, very hard to reproduce, so if you find some way to do it, just let me know and I will do my best to fix it.

— Reply to this email directly or view it on GitHub https://github.com/yukatan/commangular/issues/11#issuecomment-91230719.

Pagarbiai Tomas Stankevičius +37065641051