Today I Learned

TIL, 2022-09-09

Decoded Front-end

Reference

  • Try catch can catch errors but it doesn’t catch ALL errors, and it doesn’t catch async errors.
  • Angular has ErrorHandler class. We can DI it. Reference
  • unknown vs any - will force error to be narrowed first.
  • Angular does not catch errors that are in setTimeout, but ErrorHandler will catch that error.
    • ngZone.onError is subscribed to by ErrorHandler and is runOutsideAngular.
  • tap can catch errors. But, we can also use catchError() anyway and return a new observable (let’s say an empty array).
  • We can also combine both, so we can use tap to set the component error, and also do catchError after that replaces the initial error and returns an empty array. So an async pipe in the template will receive what was returned with catchError.
  • HTTP interceptor = can catch errors on a global scale.

Push-based Architectures with RxJS

Reference

  • Traditional pull-based architecture: the views will explicitly call service methods to “force-reload” the data. Consider findAllUsers to retried a list of users.
    • Issues: How do the views know when the data is updated?
    • How do unrelated views get notified that new data is available?
    • Should uncoupled view components poll for updated data?
    • Why is my shared data changing, and who is changing the data when?
  • Push-based architecture:
    • Direct data access is prohibited. The true data is exposed via a service.
    • Data is always immutable. Data is read-only. Changes to the inside properties are not allowed.
  • We are encouraged to write passive view components.
    • Views that only render when the data arrives via a push-stream.
    • Views that delegate user interactions to a non-view layer.
    • Views that require no business-logic testing.

Components-constructors: the power of ng-content in Angular

Reference

This project is maintained by daryllxd