Forked from acknudson/controllers.application\.js
Last active
April 19, 2021 23:33
-
-
Save danevans/13d1d7e0a175fc5b89f90b9edce3c9a1 to your computer and use it in GitHub Desktop.
arrays are dumb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import { action, computed } from '@ember/object'; | |
import { tracked } from '@glimmer/tracking'; | |
import { A } from '@ember/array'; | |
const PREFILL_DATA = [{name: 'bill'}, {name: 'aubrey'}, {name: 'danston'}]; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
_nameArray = A(PREFILL_DATA); | |
numberSelected = this._nameArray.length; | |
@computed('numberSelected', '_nameArray.[]') | |
get nameArray() { | |
const diff = this.numberSelected - this._nameArray.length; | |
if (diff > 0) { | |
console.log('longer', diff); | |
for (let i = 0; i < diff; i++) { | |
this._nameArray.push({name: ''}); | |
} | |
} else if (diff < 0) { | |
const shorter = this._nameArray.slice(0, this.numberSelected); | |
this.set('_nameArray', shorter); | |
} | |
return this._nameArray; | |
} | |
@action | |
selected(event) { | |
this.set('numberSelected', Number.parseInt(event.target.value, 10)); | |
} | |
@action | |
updateName(index, event) { | |
console.log(this._nameArray); | |
this.set(`_nameArray.${index}.name`, event.target.value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment