Skip to content

Commit

Permalink
[BUGFIX beta] join runloop in Helper#recompute
Browse files Browse the repository at this point in the history
#14774
(cherry picked from commit 9f66f13)
  • Loading branch information
buschtoens authored and rwjblue committed Jun 18, 2019
1 parent a1645c0 commit a1f5523
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/@ember/-internals/glimmer/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Factory } from '@ember/-internals/owner';
import { FrameworkObject, setFrameworkClass } from '@ember/-internals/runtime';
import { symbol } from '@ember/-internals/utils';
import { EMBER_FRAMEWORK_OBJECT_OWNER_ARGUMENT } from '@ember/canary-features';
import { join } from '@ember/runloop';
import { Dict, Opaque } from '@glimmer/interfaces';
import { DirtyableTag } from '@glimmer/reference';

Expand Down Expand Up @@ -116,7 +117,7 @@ let Helper = FrameworkObject.extend({
@since 1.13.0
*/
recompute() {
this[RECOMPUTE_TAG].inner.dirty();
join(() => this[RECOMPUTE_TAG].inner.dirty());
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,43 @@ moduleFor(
assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation');
}

// https://github.com/emberjs/ember.js/issues/14774
['@test class-based helper with static arguments can recompute a new value without a runloop'](
assert
) {
let destroyCount = 0;
let computeCount = 0;
let helper;

this.registerHelper('hello-world', {
init() {
this._super(...arguments);
helper = this;
},
compute() {
return ++computeCount;
},
destroy() {
destroyCount++;
this._super();
},
});

this.render('{{hello-world "whut"}}');

this.assertText('1');

runTask(() => this.rerender());

this.assertText('1');

helper.recompute();

this.assertText('2');

assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation');
}

['@test helper params can be returned']() {
this.registerHelper('hello-world', values => {
return values;
Expand Down

0 comments on commit a1f5523

Please sign in to comment.