Repository navigation
Teach DI with saved reading progress - #36
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fifth lesson in my Angular guide: dependency injection. The feature slice is saved reading progress.
What shipped
Saved reading progress
aria-pressedbutton, and its label changes as well as its colour.ReadingProgressServiceis a root store with a private writable signal and a read-only view.BROWSER_STORAGEinjection token. It's localStorage in the browser andnullduring prerendering, decided once in its factory.SettingsServicenow injects it instead of checkingisPlatformBrowserand touching the global in two places. That makes the token the only code insrc/appthat refers to thelocalStorageglobal.Corrupt saved progress throws. The error names the bad value, rather than silently wiping progress.
Lesson 05: DI (
/thoughts/angular-05-dependency-injection)inject()and root singletons.InjectionToken, and swapping in specs.providersvsviewProviders, route andmultiproviders, and per-request roots on the server.Version and changelog. 1.4.4, with a matching changelog entry.
Commits
Verification
SettingsService, its two new specs fail for the right reason:expected 'dark' to be 'light': it ignored the injected storage.nullstorage was provided.ng test: 51 files, 375 tests, exit 0. Lint and bothtsc --noEmitconfigs are clean.TO-DOs for this PR