Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Code it!

Alex Kanunnikov lifeart

🤓
Code it!
View GitHub Profile
View abilities.user\.js
import { alias } from '@ember/object/computed';
import { Ability } from 'ember-can';
export default Ability.extend({
model: null,
canCreate: alias('model.isAdmin')
});
View controllers.application\.js
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
items = [ { name: 1 }, undefined, { name: 2} ]
}
View controllers.application\.js
import Controller from '@ember/controller';
import EmberObject, { computed, defineProperty, get, action } from '@ember/object';
import { alias } from '@ember/object/computed';
import { camelize } from '@ember/string';
import { A } from '@ember/array';
const ATTR_MODEL_PREFIX = '_model_';
function computedAttrs() {
const attrsList = EmberObject.create({});
const data = this.metaAttributes.reduce(
View controllers.application\.js
import Controller from '@ember/controller';
import { alias } from '@ember/object/computed';
import EmberObject, { computed } from '@ember/object';
import { A } from '@ember/array';
const AttributeModel = EmberObject.extend({
countAdditives: alias('additives.length'),
additives: A()
});
View controllers.application\.js
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@service('store') store;
constructor() {
super(...arguments);
this.setup();
View controllers.application\.js
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@service('store') store;
constructor() {
super(...arguments);
this.setup();
@lifeart
lifeart / Lazy.ts
Last active Nov 12, 2020
Lazy glimmer 2 components
View Lazy.ts
import { createTemplate, setComponentTemplate, templateOnlyComponent } from '@glimmer/core';
export default setComponentTemplate(
createTemplate(`<h1 ...attributes>AMA LAZY [{{@name}}]</h1>`),
templateOnlyComponent()
);
View controllers.application\.js
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
@tracked
fragment = null;
@tracked
items = new Array(1000).fill(null).map((el,index)=>{
return {
time: Date.now(),
View controllers.application\.js
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
constructor() {
super(...arguments);
class TempObject {
@tracked foo;
}
const instance = new TempObject();
const { get } = Object.getOwnPropertyDescriptor(instance.__proto__, 'foo');
@lifeart
lifeart / components.my-component\.js
Last active Oct 11, 2020
Glimmer Composition API
View components.my-component\.js
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { tracked as trackedAny } from 'tracked-built-ins';
const IS_REF = Symbol("IS_REF");
class TrackedRef {
[IS_REF] = true;
constructor(initialValue) {
this.value = initialValue;
}
@tracked value;
You can’t perform that action at this time.