Fausto NA edited this page Jul 28, 2017 · 5 revisions

strict

Source

It throws an exception on undefined property access, which is useful for catching errors in reducers and connects, where we access a lot of action types and action creators. Meant for usage during development. It will be integrated in the configuration step in a future release.

For now, this is how we use it at store2be in our apps:

export function actions(...args) {
  return process.env.NODE_ENV !== 'production'
    ? belt.strict(belt.actions(...args))
    : belt.actions(...args)
}

Simple enough: if we're not building for production, we use belt.strict. Otherwise, we use the regular actions method in the library. If you test your code properly, you'll catch nasty bugs during development caused by stuff like this:

// Application some patches ago, in a reducer far away...
case actions.FETCH_BOOKS_SUCCESS:
   return update(/* Etc. */)

Then, you migrate to redux-belt but you forgot to refactor or remove that case statement. This might introduce bugs that are extremely difficult to find and that could easily slip into production. If you use strict and you test that reducer, you'll get a nice failure in the tests:

Tried to access non-existent action type or creator FETCH_BOOKS_SUCCESS on object: /* Stringified actions object */`
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.