Skip to content

Instantly share code, notes, and snippets.

Avatar

NullVoxPopuli

View GitHub Profile
View controllers.application\.js
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
View components.info\.hbs
Routing Info:
<dl>
<dt>currentURL</dt>
<dd>{{this.router.currentURL}}</dd>
<dt>currentRoute</dt>
<dd>{{this.router.currentRouteName}}</dd>
</dl>
View components.my-component\.js
import Component from '@glimmer/component';
import {tracked} from "@glimmer/tracking";
export default class extends Component {
@tracked name;
constructor (...args){
super(...args);
this.name = "foo";
View controllers.application\.js
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from 'tracked-built-ins';
export default class ApplicationController extends Controller {
@tracked myArray = tracked([]);
@action pushNum() {
let num = Math.random();
View controllers.application\.js
import Controller from '@ember/controller';
import { task } from 'ember-concurrency-decorators';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
constructor() {
super(...arguments);
this.myTask.perform(0);
View controllers.application\.js
import Controller from '@ember/controller';
import EmberObject from '@ember/object';
function logged(target, key, descriptor) {
let { initializer } = descriptor;
let get = function() {
console.log(`Get ${key}`); // DOES NOT LOG!
return initializer();
};
View controllers.application\.js
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
transitionToQp = () => {
this.router.transitionTo({ queryParams: { foo: 123 } });
this.router.transitionTo('foo');
this.router.transitionTo({ queryParams: { foo: 1234 } });
@NullVoxPopuli
NullVoxPopuli / components.message\.hbs
Last active Jun 28, 2020
Vertical Collection - Mixed Sizes
View components.message\.hbs
<div class='message'>
{{@message}}
</div>
@NullVoxPopuli
NullVoxPopuli / components.demo\.hbs
Last active Jun 21, 2020
StackOverflow 60055682 but with tracked everything
View components.demo\.hbs
<section>
<h2>items in the component</h2>
<ul>
{{#each this.items as |item|}}
<li>
{{item.quantity}} x {{item.name}}
<button class='button-sm' {{on 'click' (fn this.add item)}}>
Add Item
</button>
@NullVoxPopuli
NullVoxPopuli / components.demo\.hbs
Last active Jun 21, 2020
StackOverflow 60055682 but with tracked-built-ins
View components.demo\.hbs
<section>
<h2>items in the component</h2>
<ul>
{{#each this.items as |item|}}
<li>
{{item.quantity}} x {{item.name}}
<button class='button-sm' {{on 'click' (fn this.add item)}}>
Add Item
</button>
You can’t perform that action at this time.