Skip to content

Instantly share code, notes, and snippets.

@thiagofesta
Last active August 5, 2021 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagofesta/f3997ea6e5178fd787a4368414b2fa3a to your computer and use it in GitHub Desktop.
Save thiagofesta/f3997ea6e5178fd787a4368414b2fa3a to your computer and use it in GitHub Desktop.
James
import Controller from '@ember/controller';
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { A } from '@ember/array';
import {
TrackedArray,
} from 'tracked-built-ins';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
get arrayA() {
return [1, 2, 3];
}
@action
addToArrayA() {
alert('added to array a');
// this.arrayA.insertAt(1, 'aaaa');
this.arrayA.push('bbb');
}
@tracked
arrayB = new TrackedArray([1, 2, 3]);
constructor() {
super(...arguments);
this.initColumns();
}
initColumns() {
const b = this.arrayB;
b.push('a');
}
@action
addToArrayB() {
alert('added to array b');
// this.arrayB.push('bbb');
this.arrayB.insertAt(1, 'aaaa');
// this.arrayB.clear();
// this._arrayB = new TrackedArray([3, 4, 5]);
}
_arrayC = A([1, 2, 3]);
get arrayC() {
return this._arrayC;
}
@action
addToArrayC() {
alert('added to array C');
// this.arrayC.insertAt(1, 'aaaa');
this.arrayC.pushObject('bbb');
}
}
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<h1>Array A</h1>
{{this.arrayA}}
{{#each this.arrayA as |a|}}
{{a}},
{{/each}}
<button {{on "click" this.addToArrayA}}>Add to arrayA</button>
<hr>
<h1>Array B</h1>
{{this.arrayB}}
{{#each this.arrayB as |b|}}
{{b}},
{{/each}}
<button {{on "click" this.addToArrayB}}>Add to arrayB</button>
<hr>
<h1>Array C</h1>
{{this.arrayC}}
{{#each this.arrayC as |c|}}
{{c}},
{{/each}}
<button {{on "click" this.addToArrayC}}>Add to arrayC</button>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1",
"tracked-built-ins": "1.1.1"
},
"addons": {
"@glimmer/component": "1.0.0",
"tracked-built-ins": "1.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment