Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] join runloop in Helper#recompute #18110

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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