Skip to content

Instantly share code, notes, and snippets.

@peterjmag
Forked from ianbale/components.test-component.js
Last active February 8, 2017 14:50
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 peterjmag/9d5c429919fe5d52ac1b214d08f8d35f to your computer and use it in GitHub Desktop.
Save peterjmag/9d5c429919fe5d52ac1b214d08f8d35f to your computer and use it in GitHub Desktop.
testing DOM
import Ember from 'ember';
export default Ember.Component.extend({
someComputedProperty: Ember.computed('item.label', function() {
const item = this.get('item');
Ember.Logger.log('someComputedProperty', item.label);
return `${item.label} ${new Date}`;
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
data: Ember.A([]),
actions: {
addData: function() {
const data = this.get('data');
data.pushObject({ label: data.length });
},
changeData: function() {
this.set('data.0.label', this.get('data.0.label') + 1);
},
}
});
<button {{action 'addData'}}>Add</button>
<button {{action 'changeData'}}>Change</button>
{{#each data as |item|}}
{{test-component item=item}}
{{/each}}
<span style="color:red">{{item.label}}</span>
<span style="color:blue">doesn't change</span>
{{someComputedProperty}}
{
"version": "0.4.7",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.2",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment