You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to start a discussion regarding imports, multiple distribution targets, and side-effects.
Consider a library of components that you want to include in your ember-cli project. These components would be used in your application in the templates. This alone is achievable.
Perfect. This will work. In fact we can go one step further and introduce a default initializer for people who want to quickly use everything the way we named it.
This way, when the file is imported in the Brocfile, it will automatically be initialized.
This is great for people using globals.
The problem comes when I want to support both named-amd and globals.
The globals method works by initializing on evaluation. This doesn't jive well with the import export nature of modules. The initialization then happens as a side-effect of importing. This is an issue since ember apps throw errors when the same initializer is initialized twice.
I have currently settled on an unhappy compromise favoring globals. It looks like this:
// Components are initialized as a side-effect of import// This is necessary for exporting components for both// Globals and named-amd supportwindow.console.log('HACK!',BooleanInputComponent);
The build will only pass if I use that which I am importing. However, I am actually using what I am importing simply by importing it.
So here are the questions:
Should initializing these components even be a part of what I am exporting?
Is this es6 module the correct place to facilitate the need for differences between named-amd, globals, etc. builds?
Is there a popular opinion regarding modules and side-effects?
The text was updated successfully, but these errors were encountered:
I wanted to start a discussion regarding imports, multiple distribution targets, and side-effects.
Consider a library of components that you want to include in your ember-cli project. These components would be used in your application in the templates. This alone is achievable.
Import the library in the Brocfile
Then it needs to be initialized in an initializer file.
Perfect. This will work. In fact we can go one step further and introduce a default initializer for people who want to quickly use everything the way we named it.
This is great for people using ember-cli and named-amd.
As the author of this library of components, I want to support people who are building ember apps with globals.
To do this, I would have to change the way I am authoring my main.js file.
This way, when the file is imported in the Brocfile, it will automatically be initialized.
This is great for people using globals.
The problem comes when I want to support both named-amd and globals.
The globals method works by initializing on evaluation. This doesn't jive well with the import export nature of modules. The initialization then happens as a side-effect of importing. This is an issue since ember apps throw errors when the same initializer is initialized twice.
I have currently settled on an unhappy compromise favoring globals. It looks like this:
The build will only pass if I use that which I am importing. However, I am actually using what I am importing simply by importing it.
So here are the questions:
The text was updated successfully, but these errors were encountered: