0

I have a javascript library bundled using SystemJs. It contains a self invoking anonymous function. When I import it in on of my viewmodels (I don't want this code to run at the app level) it runs once and then when I leave and re-enter my view the module is already imported so the anonymous function does not run again.

The library I am trying to integrate is Bootstrap-Toc and I am trying to get it to work with Aurelia (using typescript and jspm).

Is there any way to either unload/remove a module that has been imported and then re-import it or somehow force the module to 'refresh' and thereby re-run the code?

Bitfiddler
  • 3,942
  • 7
  • 36
  • 51
  • Having instructions producing a certain logic other than function and variable definitions in a module is a serious code smell. I believe you should find another way to trigger the relating event and have that logic in a function as part of the module's API. – E_net4 Jun 24 '17 at 00:13
  • This library is built on Bootstrap.js which in turn relies on jquery and (I am new to web dev) it seems these self-running things seem to be standard for these types of libraries. Is your suggestion that I should re-architect the library? – Bitfiddler Jun 24 '17 at 00:17
  • Sure those libraries might contain variable initializations, but they were not designed to be "re-included". I actually thought the module at hand was part of the project's source. Can you specify that further in the question? – E_net4 Jun 24 '17 at 00:21
  • Thanks for the replies, I have added the library and the project type I'm using. Let me know what further details are needed. – Bitfiddler Jun 24 '17 at 01:09

1 Answers1

0

I have abandoned this approach. For details about how I worked around needing this see here.

Bitfiddler
  • 3,942
  • 7
  • 36
  • 51