Last active
June 22, 2020 20:03
-
-
Save betocantu93/631456f4e867bd4ef73e296524485ba5 to your computer and use it in GitHub Desktop.
Revisions
-
betocantu93 revised this gist
Jun 20, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ //instance-initializers/globals.js export function initialize(application) { let { environment } = application.resolveRegistration('config:environment'); -
betocantu93 revised this gist
Jun 20, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,8 @@ import config from "ember-get-config"; //ember-get-config addon export function initialize(application) { let { environment } = application.resolveRegistration('config:environment'); if (environment !== "production") { /** This basically exposes the application, pretty useful because -
betocantu93 created this gist
Jun 20, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ //instance-initializers/globals.js import config from "ember-get-config"; //ember-get-config addon export function initialize(application) { if (config.environment !== "production") { /** This basically exposes the application, pretty useful because you can use stuff like this from the console. App.lookup('route:some-route').actions.doSomething(); */ window.App = application; /* This will gives us access to the store easily, to make fast queries or checks! Fast and easy: var s = App.store.peekRecord('some-model', 1); App.store.createRecord('some-model', {name: 'Alberto'}) */ window.App.store = application.__container__.lookup("service:store"); //shortcuts for every emberjs base type lookup //App.controller('auth.some') let objects = [ 'service', 'controller', 'route', 'model' ]; objects.forEach(type => { window.App[type] = function(name) { return application.lookup(`${type}:${name}`) } }) /* Use a class for ergonimics with getters, grab the current model, route or controller based on the current active route! */ class CurrentContext { get model() { return application.lookup( `controller:${application.lookup("service:router").currentRouteName}` ).model; } get controller() { return application.lookup( `controller:${application.lookup("service:router").currentRouteName}` ); } get route() { return application.lookup( `route:${application.lookup("service:router").currentRouteName}` ); } } window.App.ctx = new CurrentContext(); } }