Skip to content

Instantly share code, notes, and snippets.

@mjuniper
Last active September 21, 2018 14:10
Show Gist options
  • Save mjuniper/d944611b6468bb63945e214b029f8980 to your computer and use it in GitHub Desktop.
Save mjuniper/d944611b6468bb63945e214b029f8980 to your computer and use it in GitHub Desktop.
didUpdateAttrs
import Ember from 'ember';
export default Ember.Component.extend({
init() {
this._super(...arguments);
this.set('messages', []);
},
classNames: ['my-component' ],
didReceiveAttrs() {
this.get('messages').pushObject('didReceiveAttrs was hit!');
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
attr1: 'attr1',
attr2: 'attr2',
attr3: 'attr3',
actions: {
updateAttributes (howMany) {
if (howMany === 1) {
this.set('attr1', Date.now());
}
if (howMany === 2) {
this.setProperties({
attr1: Date.now(),
attr2: Date.now()
});
}
if (howMany === 3) {
this.setProperties({
attr1: Date.now(),
attr2: Date.now(),
attr3: Date.now()
});
}
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.my-component {
border: solid 2px gray;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<button {{action 'updateAttributes' 1}}>update 1 attribute</button>
<button {{action 'updateAttributes' 2}}>update 2 attributes</button>
<button {{action 'updateAttributes' 3}}>update 3 attributes</button>
<br>
{{my-component attr1=attr1 attr2=attr2 attr3=attr3}}
<ul>
<li>attr1: {{attr1}}</li>
<li>attr2: {{attr2}}</li>
<li>attr3: {{attr3}}</li>
</ul>
<ul>
{{#each messages as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment