w7d2 - Redux/middleware Flashcards
How do you assign a namespace to a rails resource? What does this change? What is a namespace?
A namespace is a subset of controllers that live under a specific URL.
namespace :api do
resources :cats
end
This will change the url-helper method from cats into api_cats.
This will change the url for cats from /cats to /api/cats
How do we ensure that our state is immutable?
Call Object.freeze(state) at the top of every reducer. This will ensure that the state is never accidentally mutated.
What is the limitation of Object.freeze ?
It is not a deep-freeze. Sub-elements within the frozen object can still be mutated.
Does an ES6 fat-arrow function create a new scope?
No. It is not lexically scoped. ‘this’ means the same thing inside an arrow function that it does outside of it.
How is middleware installed into a store?
How would you set up a logger?
It’s passed along when a store is created:
createStore( reducer, preLoadedState, enhancer )
An example of the ‘enhancer’ param:
///////////
import { createStore, applyMiddleware } from ‘redux’;
import { logger } from ‘redux-logger’;
createStore( reducer, preLoadedState, applyMiddleware(logger) )
When writing your own middleware, what signature must be followed?
const myMiddleware = store => next => action => { // my side effects return next(action); };
What npm package allows us to log changes to our store’s state?
redux-logger
What’s the purpose of using a Thunk?
To handle asynchronous calls via action creators. By doing so, we keep all async calls in one location, rather than having them randomly strewn throughout our components.