Use Volatile State and Lifecycle Methods to Manage Private State

Share this video with your friends

Send Tweet

MST has a pretty unique feature: It allows you to capture private state on models, and manage this state by using lifecycle hooks. For example by setting up a WebSocket connection and disposing of the connection automatically as soon as the instance gets removed from the store. In this lesson, we will leverage cancellable fetches to abort in-flight requests when appropriate

In this lesson you will learn:

  • Aborting window.fetch requests :-).
  • Storing private, volatile, internal state in the function closure
  • A second life-cycle hook: beforeDestroy
fulvio-m
fulvio-m
~ 2 years ago

Chrome 66 now supports AbortController: https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort

Only IE is left out, so it's pretty safe to use.