Last active
May 23, 2020 13:05
-
-
Save nightire/884f0a6a3b29cf1a2efbe5dc14e17265 to your computer and use it in GitHub Desktop.
Recreate vs Rerender
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 { action, set } from '@ember/object'; | |
import { tracked } from 'tracked-built-ins'; | |
export default class ApplicationController extends Controller { | |
@tracked items = [ | |
{ id: 1, value: 1 }, | |
{ id: 2, value: 2 }, | |
{ id: 3, value: 3 }, | |
]; | |
@action updateItems(item) { | |
// 1. replace the whole this.items array | |
// this.items = this.items.map((_item) => { | |
// const value = item.id === _item.id ? _item.value + 1 : _item.value; | |
// return { ..._item, value } | |
// }); | |
// 2. replace the specified item in this.items | |
// const index = this.items.indexOf(item); | |
// this.items.replace(index, 1, [{ ...item, value: item.value + 1 }]); | |
// 3. update the specified property in the specified item | |
// set(item, 'value', item.value + 1); | |
// 4. same as 3. but using tracked property | |
// item.value = item.value + 1; | |
} | |
} |
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 Application from '../app'; | |
import config from '../config/environment'; | |
import { setApplication } from '@ember/test-helpers'; | |
import { assign } from '@ember/polyfills'; | |
import { start } from 'ember-qunit'; | |
let attributes = { | |
rootElement: '#test-root', | |
autoboot: false | |
}; | |
attributes = assign(attributes, config.APP); | |
let application = Application.create(attributes); | |
setApplication(application); | |
start(); |
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": true, | |
"_APPLICATION_TEMPLATE_WRAPPER": false, | |
"_JQUERY_INTEGRATION": false | |
}, | |
"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", | |
"tracked-built-ins": "1.0.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment