From the course: Creating Angular Libraries
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution - Angular Tutorial
From the course: Creating Angular Libraries
Solution
(upbeat music) - [Instructor] Okay, here's my solution for the challenge. Keep in mind that my solution and your solution may be different, and that's okay. From the root of the workspace, I'll go to projects NGX gem finder, source, lib, utils, and click on calculate average dot TS to open the file. First, I created a constant called cache and set its value to a new weak map. This is where I keep track of calculated averages. I used a weak map here because they accept any non primitive value as a key, which means I can use the input itself as the key for the cache. No need to string apply the data. I get the added benefit of garbage collection with weak maps, but there's some nuance to exactly when keys and values get garbage collected. So I need to be careful and watch for memory leaks. In a real world project, I might experiment with different caching strategies to see what works best for this particular use case. I then export a constant called calculate average and set its value…
Contents
-
-
-
-
-
(Locked)
Common configuration tweaks2m 29s
-
(Locked)
Skipping change detection on component subtrees1m 45s
-
(Locked)
Component view encapsulation2m 41s
-
(Locked)
Isolating injectors within hierarchies4m 37s
-
(Locked)
Optimizing slow computations2m 41s
-
(Locked)
Avoiding zone pollution2m 3s
-
(Locked)
Angular without Zone.js (zoneless)46s
-
(Locked)
Make components portable with Angular Elements5m 16s
-
(Locked)
Coding challenge26s
-
(Locked)
Solution2m 6s
-
(Locked)
-
-