Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukemelia/868fbd21b0532d3dfa583ca43790dde7 to your computer and use it in GitHub Desktop.
Save lukemelia/868fbd21b0532d3dfa583ca43790dde7 to your computer and use it in GitHub Desktop.
Repro readOnly CP issue II
import Ember from 'ember';
const { computed } = Ember;
const { readOnly } = computed;
export default Ember.Component.extend({
cost: readOnly('delayedCalculation.cost'),
tax: readOnly('delayedCalculation.tax'),
total: computed('cost', 'tax', function() {
return this.get('cost') + this.get('tax');
}),
delayedCalculation: computed(function() {
let promise = Ember.RSVP.resolve({
cost: 399.00,
tax: 32.93
});
return DS.PromiseObject.create({ promise });
})
});
import Ember from 'ember';
const { computed } = Ember;
const { readOnly } = computed;
export default Ember.Component.extend({
cost: readOnly('delayedCalculation.cost'),
tax: readOnly('delayedCalculation.tax'),
// One way to clear up the problem is to use the below CP definitions instead of the readOnly macros
// cost: computed('delayedCalculation.cost', function(){
// return this.get('delayedCalculation.cost');
// }),
// tax: computed('delayedCalculation.tax', function() {
// return this.get('delayedCalculation.tax') || 0;
// }),
total: computed('cost', 'tax', function() {
return this.get('cost') + this.get('tax');
}),
delayedCalculation: computed(function() {
let promise = Ember.RSVP.resolve({
cost: 399.00,
tax: 32.93
});
return DS.PromiseObject.create({ promise });
})
});
<h2>Doesn't update tax as expected</h2>
{{#yielding-comp as |total cost tax|}}
<div>cost: {{cost}}</div>
<div>tax: {{tax}}</div>
<div>total: {{total}}</div>
{{/yielding-comp}}
<div>~</div>
<h2>Doesn't Update cost as Expected</h2>
<p>Only difference with the above is the order of the properties in the template</p>
{{#yielding-comp as |total cost tax|}}
<div>tax: {{tax}}</div>
<div>cost: {{cost}}</div>
<div>total: {{total}}</div>
{{/yielding-comp}}
<div>~</div>
<p>The problem is also reproducible without a component that yields -- it seems to be about the order of consumption:</p>
{{non-yielding-component}}
<div>tax: {{tax}}</div>
<div>cost: {{cost}}</div>
<div>total: {{total}}</div>
{
"version": "0.10.6",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://s3.amazonaws.com/builds.emberjs.com/release/ember.prod.js",
"ember-data": "2.9.0",
"ember-template-compiler": "release",
"ember-testing": "release"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment