Skip to content

Commit

Permalink
Merge pull request #17682 from rwjblue/failing-test-for-tracked-set-o…
Browse files Browse the repository at this point in the history
…utside-runloop

[BUGFIX canary] Ensure @Tracked setter triggers a revalidation.
  • Loading branch information
rwjblue committed Feb 28, 2019
2 parents 8dd4a4f + 028799f commit d333313
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@ if (EMBER_METAL_TRACKED_PROPERTIES) {
this.assertText('1');
}

'@test tracked properties rerender when updated outside of a runloop'(assert) {
let done = assert.async();

let CountComponent = Component.extend({
count: tracked({ value: 0 }),

increment() {
setTimeout(() => {
this.count++;
}, 100);
},
});

this.registerComponent('counter', {
ComponentClass: CountComponent,
template: '<button {{action this.increment}}>{{this.count}}</button>',
});

this.render('<Counter />');

this.assertText('0');

// intentionally outside of a runTask
this.$('button').click();

setTimeout(() => {
this.assertText('1');
done();
}, 200);
}

'@test nested tracked properties rerender when updated'() {
let Counter = EmberObject.extend({
count: tracked({ value: 0 }),
Expand Down
2 changes: 1 addition & 1 deletion packages/@ember/-internals/metal/lib/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function markObjectAsDirty(obj: object, propertyKey: string, meta: Meta):
}
}

function ensureRunloop(): void {
export function ensureRunloop(): void {
if (hasViews()) {
backburner.ensureInstance();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/metal/lib/tracked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DEBUG } from '@glimmer/env';
import { combine, CONSTANT_TAG, Tag } from '@glimmer/reference';
import { Decorator, ElementDescriptor } from './decorator';
import { setComputedDecorator } from './descriptor_map';
import { dirty, tagFor, tagForProperty } from './tags';
import { dirty, ensureRunloop, tagFor, tagForProperty } from './tags';

type Option<T> = T | null;

Expand Down Expand Up @@ -255,7 +255,7 @@ export interface Interceptors {
[key: string]: boolean;
}

let propertyDidChange = function(): void {};
let propertyDidChange = ensureRunloop;

export function setPropertyDidChange(cb: () => void): void {
propertyDidChange = cb;
Expand Down

0 comments on commit d333313

Please sign in to comment.