Last active
September 21, 2020 18:14
-
-
Save ankushdharkar/bfdfe4da3231671da3082a536e456197 to your computer and use it in GitHub Desktop.
Using Array in Ember Octane
This file contains hidden or 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 { tracked } from '@glimmer/tracking'; | |
import { action } from '@ember/object'; | |
import { A } from '@ember/array'; | |
import { set } from '@ember/object'; | |
class Age { | |
@tracked value; | |
constructor(val) { | |
this.value = val; | |
} | |
} | |
export default class ApplicationController extends Controller { | |
usersListData = A([ | |
{ | |
firstName: 'Ankush', | |
lastName: 'Dharkar', | |
age: new Age(30) | |
}, | |
{ | |
firstName: 'Sindbad', | |
lastName: 'the Sailor', | |
age: new Age(40) | |
} | |
]) | |
@action | |
addNewUser () { | |
this.usersListData.pushObject({ | |
firstName: 'David', | |
lastName: 'Kopp', | |
age: new Age(45) | |
}); | |
} | |
@action | |
changeFirstname () { | |
const obj = this.usersListData.objectAt(0); | |
// [1.] | |
obj.age.value = 22; | |
// [2.] | |
set(obj, 'firstName', 'Taksh'); | |
set(obj, 'lastName', 'Channa'); | |
/* | |
In order to make sure the context updates properly, you must invalidate the property when updating it. | |
1. You can mark the property as `@tracked`, or | |
2. Use `@ember/object#set`: https://api.emberjs.com/ember/3.21/functions/@ember%2Fobject/set | |
*/ | |
} | |
} |
This file contains hidden or 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