Skip to content

Instantly share code, notes, and snippets.

View jordpo's full-sized avatar

Jordan Morano jordpo

  • Burlington, VT
View GitHub Profile
import Controller from '@ember/controller';
import { action, computed, set } from '@ember/object';
export default class ApplicationController extends Controller {
get nonComputedMessage() {
return this.model.message;
}
@computed('model.message')
get computedMessage() {
@jordpo
jordpo / href-to.ts
Last active July 28, 2020 19:55
Ember href-to helper with service:router logic
import Helper from '@ember/component/helper';
import { getOwner } from '@ember/application';
interface QueryParams {
isQueryParams: boolean;
values: object;
}
type Param = number | string | QueryParams | object;
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
queryParams = ['q'];
q = '';
}
@jordpo
jordpo / controllers.application\.js
Last active July 13, 2020 20:19
Changeset Boolean Bug
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);
}
{
"compilerOptions": {
"target": "es2017",
"allowJs": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noImplicitThis": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictPropertyInitialization": false,
@jordpo
jordpo / route-action.js
Last active February 1, 2019 05:42
A route-action helper to expose current route handling
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);
@jordpo
jordpo / action-dropdown.hbs
Last active August 29, 2017 20:55
Filtering
{{#basic-dropdown as |dropdown|}}
{{#dropdown.trigger
class='c-button'
}}
Filters
{{/dropdown.trigger}}
{{#dropdown.content}}
<div>
<h2>
Bidders
@jordpo
jordpo / query.rb
Created August 25, 2017 15:33
company bidder query
class Companies::CompanyUsersQuery
def initialize()
@scope = CompanyUser
end
def add_includes
scope = scope.include([:credentials, :company])
self
end
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;
});
}
@jordpo
jordpo / ember-data-imports.js
Created October 19, 2016 16:13
New imports for ember data
// 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