The popular open-source contract for web professionals by Stuff & Nonsense
- Originally published: 23rd December 2008
- Revised date: March 15th 2016
- Original post
| // an alternative approach to my gist below | |
| import Ember from 'ember'; | |
| const get = Ember.get; | |
| const set = Ember.set; | |
| const later = Ember.run.later; | |
| const cancel = Ember.run.cancel; |
| // addon/services/ajax.js | |
| // ensure custom ajax requests have the appropriate authorization headers when signed in | |
| import Ember from 'ember'; | |
| import AjaxService from 'ember-ajax/services/ajax'; | |
| const { | |
| computed, | |
| inject, | |
| get | |
| } = Ember; |
| // DS.Model | |
| import Model from 'ember-data/model'; | |
| // DS.RESTSerializer | |
| import RESTSerializer from 'ember-data/serializers/rest'; | |
| // DS.JSONSerializer | |
| import JSONSerializer from 'ember-data/serializers/json'; | |
| // DS.JSONAPISerializer |
| headers: computed('session.isAuthenticated', { | |
| get() { | |
| const headers = {}; | |
| const session = get(this, 'session'); | |
| if (get(session, 'isAuthenticated')) { | |
| session.authorize('authorizer:oauth', (headerName, headerValue) => { | |
| headers[headerName] = headerValue; | |
| }); | |
| } |
| class Companies::CompanyUsersQuery | |
| def initialize() | |
| @scope = CompanyUser | |
| end | |
| def add_includes | |
| scope = scope.include([:credentials, :company]) | |
| self | |
| end |
| import Helper from '@ember/component/helper'; | |
| import { inject as service } from '@ember-decorators/service'; | |
| import { bind } from '@ember/runloop'; | |
| import { getOwner } from '@ember/application'; | |
| function findHandler(owner, currentRouteInfo, action) { | |
| const route = owner.lookup(`route:${currentRouteInfo.name}`); | |
| const handler = route.actions ? route.actions[action] : route[action]; | |
| if (!handler && currentRouteInfo.parent) { | |
| return findHandler(owner, currentRouteInfo.parent, action); |
| { | |
| "compilerOptions": { | |
| "target": "es2017", | |
| "allowJs": true, | |
| "moduleResolution": "node", | |
| "allowSyntheticDefaultImports": true, | |
| "noImplicitThis": true, | |
| "alwaysStrict": true, | |
| "strictNullChecks": true, | |
| "strictPropertyInitialization": false, |
| import Controller from '@ember/controller'; | |
| import { EmberChangeset, Changeset } from 'ember-changeset'; | |
| class MyChangeset extends EmberChangeset { | |
| // NOTE using the default safeSet for only type boolean fixes the issue | |
| safeSet(obj, key, value) { | |
| if (typeof value.value === 'boolean') (obj[key] = value); | |
| return super.safeSet(obj, key, value); | |
| } |