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 canary] Ensure @tracked setter triggers a revalidation. #17682

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
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