4 ms·
Computed properties has always been a possibility in Angular, you'd just create a getter[0] based on multiple different values, works like a charm. This new way
by spyke112 3y ago
Computed properties has always been a possibility in Angular, you'd just create a getter[0] based on multiple different values, works like a charm. This new way is probably faster, but I've honestly never had any issues with the other approach.
[0] https://www.typescripttutorial.net/typescript-tutorial/typescript-getters-setters/ https://www.typescripttutorial.net/typescript-tutorial/types...
- Timon3 3y agoWill the getter result be cached? If not, it's not a computed property.
- nitrammm 3y agoAccording to what definition?
- geysersam 3y agoIsn't that just semantics? Whatever name you give the feature "lazily computed and cached values in the context of web frameworks", previously Angular didn't have them (built in) and now they do.
- NoNameProvided 3y agoAngular did have it, it is called RxJS.
- Timon3 3y agoAccording to the "definition" on the Vue documentation page for computed properties: https://vuejs.org/guide/essentials/computed.html#computed-caching-vs-methods https://vuejs.org/guide/essentials/computed.html#computed-ca...
- nitrammm 3y agoThat describe what a computed properly is in the context of Vue.
- Timon3 3y agoAre you aware what comment tree you are in? This whole thing started because GP wrote this: > For example, this update brings us computed properties, an essential feature for any complex performant web application that was made popular by Vue.js 10 years ago [1]. So obviously the relevant definition is "what the feature does in Vue". What is your issue here?
- spyke112 3y agoI’d expect that it’s not cached. But then I would go ahead and call that memoization.
- Timon3 3y agoThe concept is actually slightly different. With memoization you store a map from inputs to outputs. A computed property doesn't necessarily do this, it just caches the result of the last computation. The important part is that a computed property tracks its dependencies and is automatically re-calculated ONLY when necessary. If it behaves differently, it's not equivalent to the concept of a computed property in Vue.
- ptrwis 3y agoThe problem I had with getters in a fairly complex application (WYSIWYG editor) was handling mouse events, in particular onMouseMove - change detection was triggered on every such event, and the application was very slow. EDIT: It was slow because there were many getters based on other getters etc and everything was recalculated on each event.
- spyke112 3y agoI don’t think a computed property would behave any better. It sounds like your event handling should have been decoupled from change detection and only applied changes when necessary. This would probably be a problem in any framework.
- ptrwis 3y agoThis is an issue with zone.js + getters, I changed the key components to OnPush change detection.