question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using `tracked` without decorators

See original GitHub issue

It could be useful to have docs about using tracked in function form instead of decorator form. experimentalDecorators from TypeScript and decorators from ECMAScript proposal are not the same thing. Also it’ll be useful for people who prefer to use current version of JavaScript.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
rwjbluecommented, Oct 13, 2017

Well, AFAICT, it should be possible to do this without decorators (but using the exported decorator function) already:

import Component, { tracked } from '@glimmer/component';

class Foo extends Component { }

// to mark a property as tracked that we need to set internally
// and monitor for re-renders
tracked(Foo.prototype, 'name'); 

// to create a getter that is dependent on other properties
tracked('firstName', 'lastName')(Foo.prototype, 'name', {
  get() {
    return `${this.firstName} ${this.lastName}`;
  }
});

Am I missing something?

1reaction
tomdalecommented, Oct 13, 2017

@chicoxyzzy The approach used by MobX would not be a good fit for Glimmer, I don’t think. One cool thing about how tracked properties work right now is that the getter and setter are only configured one time per component, on the prototype. This makes instantiating a new component instance very cheap because there’s almost no work to do.

In the extendObservable API, there’s a non-trivial cost at class construction time.

I’m definitely not opposed to offering a non-decorator API for configuring tracked properties, but we would need to come up with something that is both ergonomic and maintains the semantics and performance characteristics of the decorator API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@track Decorator Is No Longer Required for Lightning Web ...
There is a piece of good news, we do not need to guess about whether to use @track to make a field reactive....
Read more >
The @track Decorator Is No Longer Required for Lightning ...
We have removed the @track decorator from all the variables in our test project, but it was not working for the few variables....
Read more >
LWC Fundamentals: The @track Decorator - YouTube
In this Quick Take, we continue our learning on JavaScript Decorators in LWC by exploring properties with the @ track Decorator.
Read more >
Decorators - Salesforce Lightning Component Library
To tell the framework to observe changes to the properties of an object, decorate the field with @track . See Reactivity for Fields,...
Read more >
Decorators in Lightning Web Component (LWC)
The fundamental way detects the DOM changes is through tracked properties. Tracked properties are just like normal properties on your component ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found