emberjs/ember.js

@tracked: lazy evaluation

Open

#18.118 geöffnet am 19. Juni 2019

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (4.216 Forks)batch import
DocumentationHelp Wanted

Repository-Metriken

Stars
 (22.437 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 11T 14h) (20 gemergte PRs in 30 T)

Beschreibung

While investigating #18075, I noticed a minor issue, that persists even after the change to WeakMap in #18091, because of the lazy evaluation

class Foo {
  @service someService;

  @tracked someProp = this.someService.serviceProp;
}

Assume Foo gets created by a container lookup or get manually called setOwner on.

Intuitively I would expect the above code to work. And it does. If this.someProp is only accessed later in the template or in init, everything works fine.

However, if you already access this.someProp in the constructor, you get a TypeError, because this.someService is undefined.

While I understand why, I still think this is inconsistent. If we decide to keep lazy evaluation of the initializers, we need to document it well. Would the new static decorators proposal support lazy evaluation in the first place?

Contributor Guide