I'd like to reopen Ember or Ember Data framework classes. Using Ember CLI, where is the right place to put these so that they get initialized property? Here's an example of something I'd like to do:
import DS from 'ember-data'; DS.Model.reopen({ rollback: function() { this._super(); // do some additional stuff } });
For example, you can use it to create components, routes, services, models, and more. For a full list, type ember generate --help. The CLI's generate command will ensure that new files contain the necessary boilerplate, that they go in the right directories, and that file naming conventions are followed.
The CLI is backwards-compatible with older Ember apps and maintains a 6-week release schedule. The CLI was also built with the idea that a developer should be able to focus on building great apps, not re-engineering how to fit pieces together throughout an app's lifecycle.
For a full list, type ember generate --help. The CLI's generate command will ensure that new files contain the necessary boilerplate, that they go in the right directories, and that file naming conventions are followed. To avoid mistakes that are hard to debug, always use the CLI to create files instead of creating the files by hand.
The Ember CLI (command line interface) is the official way to create, build, test, and serve the files that make up an Ember.js app or addon. Many things have to happen before any web app is ready for the browser, and the Ember CLI helps you get there with zero configuration. npm install -g ember-cli
I think the best way to execute modules that have side effects would be to create an initializer. Something like this:
// app/initializers/modify-model.js import DS from 'ember-data'; let alreadyRun = false; export default { name: 'modify-model', initialize() { if (alreadyRun) { return; } else { alreadyRun = true; } DS.Model.reopen({ // ... }); } };
Initializers are automatically run by Ember-CLI, so there's no need to call them yourself.
EDIT: As Karim Baaba pointed out, it's possible for initializers to run more than once. For an easy way around that, I've included an alreadyRun
flag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With