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

[Pre-work] Prepare @tracked decorator #16903

Merged
merged 13 commits into from
Aug 28, 2018
Merged

[Pre-work] Prepare @tracked decorator #16903

merged 13 commits into from
Aug 28, 2018

Conversation

chadhietala
Copy link
Contributor

This is pre-work to expose tracked as a decorator. In this PR @smfoote moved the tests over from being a helper function that augmented the descriptors to an actual function that can be used as a decorator. This also updates all the tests to test @tracked in static form instead of property descriptor helpers.

/cc @wycats @tomdale

@@ -0,0 +1,3 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file shouldn't be commited.

Copy link
Member

@tomdale tomdale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for doing this. Just a few nitpicks, and I'd like to understand why in the tests we're initializing properties and then re-initializing them in the constructor to the same value. Unless I'm missing something, they're semantically identical.

): PropertyDescriptor {
if ('value' in descriptor) {
export function tracked(...dependencies: string[]): MethodDecorator;
export function tracked(target: any, key: any): any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these can be typed as unknown and PropertyKey, respectively.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

class Key {
@tracked value = 'value';
constructor() {
this.value = 'value';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to set this in the constructor if we're already initializing the property above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

'@tracked set',
class extends AbstractTestCase {
teardown() {
setHasViews(() => false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it's not. Deleted.

}
}

defineProperty(
EmberObject.prototype,
'full',
computed('name', function() {
let name = get(this, 'name');
let name = get(self, 'name');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're having to introduce the self local variable because TypeScript can't infer the type of this inside this computed property. If that's the case, a better way to do this would be to annotate the this type:

computed('name', function(this: EmberObject) { /*...*/ })

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Done.

@chadhietala chadhietala merged commit b502f9b into master Aug 28, 2018
@chadhietala chadhietala deleted the prep-tracked branch August 28, 2018 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants