shared.js exports an object, which will be required and mutated.
mutate-require.js imports the object from shared.js. This is the first import so it is loading the object that shared.js exports fresh and stores it in the cache. It then mutates that object, and exports null.
Finally index.js imports mutate-require.js, which triggers the require of shared.js, the imports shared.js directly, which results from a cache load. The comment at the bottom of index.js shows the output of when index.js is executed.
Is this the behavior you'd expect? I was surprised, when I saw this. I could imagine a more sane default being: having `require` copy the exported value to the cache and returning the clean copy on each require. But then what about modules that export objects that mutate themselves?? Thoughts?
No comments:
Post a Comment