Skip to content

Instantly share code, notes, and snippets.

@allthesignals
Last active September 21, 2017 02:31
Show Gist options
  • Select an option

  • Save allthesignals/2c57bf2e4fc9f6341862aad3ca0ae325 to your computer and use it in GitHub Desktop.

Select an option

Save allthesignals/2c57bf2e4fc9f6341862aad3ca0ae325 to your computer and use it in GitHub Desktop.
Weird Attr Binding Issue
import Ember from 'ember';
export default Ember.Component.extend({
didUpdateAttrs() {
alert('did receive attributes on child component')
},
});
import Ember from 'ember';
export default Ember.Component.extend({
config: {},
arbitraryString: 'peanut butter',
anotherProperty: true,
isReady: Ember.computed('config', 'anotherProperty', 'arbitraryString', function() {
return !!(this.get('anotherProperty') && this.get('arbitraryString'))
}),
actions: {
toggleDependentKey() {
const config = this.get('config');
const layers = Ember.get(config, 'layers');
const targetLayerIndex = 0;
const targetLayer = layers.objectAt(targetLayerIndex);
Ember.set(targetLayer, 'layer',{ config: { color: 'purple' } });
},
},
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
weirdObject: {
layers: [
{
layer: {
id: 'test',
config: {
color: 'blue'
},
}
},
{
layer: {
id: 'test2',
config: {
color: 'green'
},
}
}
]
}
});
<h1>Welcome to {{appName}}</h1>
<br/>
Each element in the below array is a component. That component's didUpdateAttrs never fires (although the template changes).
<br/>
<br/>
{{#test-component config=weirdObject as |api|}}
<button onclick={{action api.toggleDependentKey}}>Change deeply nested array property</button>
{{/test-component}}
{{outlet}}
<br/>
<br/>
{{layer.id}} - {{layer.config.color}}
{{yield}}
'isReady' computed is {{isReady}}
<br/><br/>
Array that iterates:
{{#if isReady}}
<ul>
{{#each config.layers as |layer|}}
<li>{{child-component layer=layer.layer}}</li>
{{/each}}
</ul>
{{/if}}
<br/>
{{yield (hash toggleDependentKey=(action 'toggleDependentKey'))}}
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment