Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4830

Ember.computed task.isRunning == "You modified isRunning twice in a single render"

$
0
0

@dlindquist-egistix wrote:

I’m encountering a “You’ve modified xxx twice in a single render” error when using ember-concurrency tasks inside computed properties.

Here’s an extremely minimal example of a component that demonstrates the problem:

double-render-bug.js:

import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';

export default Ember.Component.extend({
	task: task(function * () {
		yield timeout(1000);
		return 'done';
	}),
	taskInstance: Ember.computed(function() {
		return this.get('task').perform();
	}),
	resultValue: Ember.computed.alias('taskInstance.value'),
	isRunning: Ember.computed.alias('task.isRunning'),
});

double-render-bug.hbs:

{{isRunning}} / {{resultValue}}

The main purpose behind the real version of this is to use computed properties to have my data automatically loaded (and then transformed and rendered) when parameters (for example ‘month’ or something) are changed. The methodology works beautifully, except when I try to use the ‘isRunning’ value to determine whether my data is currently loading or not.

It appears that what happens is:

  1. The getter for isRunning is fired, and ember-concurrency returns ‘false’, since no task instance has yet been created.
  2. Then the getter for resultValue is fired, which in turn causes the task to be performed. Internally, ember-concurrency then sets the ‘isRunning’ value to true, which in turn causes my Ember.computed.alias to be re-evaluated.
  3. Everything blows up, since the isRunning is being “modified twice”.

Is this a bug in ember? Is this a bug in ember-concurrency? Do I have any practical recourse, other than some complicated ‘debounce’ on the isRunning flag?

(NOTE - to see this work successfully, simply change the isRunning to a hard-coded value, like false.)

Thanks in advance!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4830

Trending Articles