Skip to content

Instantly share code, notes, and snippets.

@sukima
sukima / components.my-component\.js
Last active Feb 24, 2021
How to trap known errors
View components.my-component\.js
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
function handleError(error) {
if (!error.isExpected) {
throw error;
}
}
View components.bs-tab.tab-pane\.js
import Component from '@glimmer/component';
import { guidFor } from '@ember/object/internals';
export default class extends Component {
willDestroy() {
console.log(`willDestroy on BsTab::TabPane ${guidFor(this)}`);
super.willDestroy(...arguments);
}
}
View helpers.add-page-title-segment\.js
import Helper from '@ember/component/helper';
class TitleSegments {
constructor(segments = []) {
this.replace(segments);
}
replace(segments) {
this.segments = [...segments];
}
*[Symbol.iterator]() {
View components.dog-api-manager\.js
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
export default class extends Component {
@service dogObserver;
@tracked isLoading;
@tracked error;
@tracked randomDog;
@sukima
sukima / components.my-form\.js
Last active Jan 9, 2021
Validity with changeset
View components.my-form\.js
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { validate } from '../utils/validate';
export default class extends Component {
@action
validatedSubmit(event) {
event.preventDefault();
let { target: form } = event;
@sukima
sukima / components.my-form\.js
Last active Jan 8, 2021
Form validation (modifiers)
View components.my-form\.js
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { validate } from '../utils/validate';
export default class extends Component {
@action
validatedSubmit(event) {
event.preventDefault();
let { target: form } = event;
View components.my-form\.js
import Component from '@glimmer/component';
import { action } from '@ember/object';
export default class extends Component {
@action
validatedSubmit(event) {
event.preventDefault();
let { target: form } = event;
let validateEvent = new CustomEvent('validate');
View controllers.application\.js
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
class Thing {
@tracked foobar = 'Foobar';
constructor(label) {
this.label = label;
}
toJSON() {
View components.my-component\.js
import Component from '@glimmer/component';
import { action } from '@ember/object';
export default class extends Component {
@action
doSomething() {
this.args.foobar();
}
}
@sukima
sukima / countries.json
Last active Dec 8, 2020 — forked from keeguon/countries.json
A list of countries in JSON
View countries.json
[
{"name": "Afghanistan", "code": "AF"},
{"name": "Åland Islands", "code": "AX"},
{"name": "Albania", "code": "AL"},
{"name": "Algeria", "code": "DZ"},
{"name": "American Samoa", "code": "AS"},
{"name": "AndorrA", "code": "AD"},
{"name": "Angola", "code": "AO"},
{"name": "Anguilla", "code": "AI"},
{"name": "Antarctica", "code": "AQ"},