From a1f5523cda5f12e4046b367744276de842cf1e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Buscht=C3=B6ns?= Date: Tue, 18 Jun 2019 09:49:17 +0200 Subject: [PATCH] [BUGFIX beta] join runloop in `Helper#recompute` https://github.com/emberjs/ember.js/issues/14774 (cherry picked from commit 9f66f138d1938e0871bc269585ff247a24b2f986) --- .../@ember/-internals/glimmer/lib/helper.ts | 3 +- .../integration/helpers/custom-helper-test.js | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/@ember/-internals/glimmer/lib/helper.ts b/packages/@ember/-internals/glimmer/lib/helper.ts index dcbd65a9a7c..b23b79bd3ff 100644 --- a/packages/@ember/-internals/glimmer/lib/helper.ts +++ b/packages/@ember/-internals/glimmer/lib/helper.ts @@ -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'; @@ -116,7 +117,7 @@ let Helper = FrameworkObject.extend({ @since 1.13.0 */ recompute() { - this[RECOMPUTE_TAG].inner.dirty(); + join(() => this[RECOMPUTE_TAG].inner.dirty()); }, /** diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js index b68dcee9e57..236424ac7da 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js @@ -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;