noppa / ng-hot-reload

Hot reloading for AngularJS apps.
MIT License
43 stars 8 forks source link

Defining directives with ES6 classes have issues #26

Closed martonbrunner closed 4 years ago

martonbrunner commented 4 years ago

Hi,

First of all thanks for all your work, this tool is amazing.

I have one issue though regarding directives. More specifically in cases where the directive is defined with an ES6 class. Something similar to the example here: https://www.michaelbromley.co.uk/blog/exploring-es6-classes-in-angularjs-1.x/#directives

When defining a directive this way the compile and link functions will be properties on the prototype of the directive object rather than its own properties. In the case of compile I don't think it is problematic as you are copying it to a new property here. But in the case of the link function, it will be lost as the result object will not have the prototype of the original directive. I suggest a small change to copy the prototype of the original directive to the new one too. This way the link will be available on the result directive too.

In my case, the suggested change resolved the issue and I don't think it should cause any problems elsewhere. I hope you can accept this change or improve it to solve my issue.

Thanks!

noppa commented 4 years ago

Hi! Thanks a lot for the PR! The fix looks good. Unfortunately I'm away from my desk right now for the weekend, so probably won't be able to merge/publish until Monday, but I'll take a look then.

noppa commented 4 years ago

@martonbrunner This was published in version 3.2.1.

martonbrunner commented 4 years ago

@noppa That is great. Thank you for the quick resolution.