w7d2 - Redux/middleware Flashcards

1
Q

How do you assign a namespace to a rails resource? What does this change? What is a namespace?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we ensure that our state is immutable?

A

Call Object.freeze(state) at the top of every reducer. This will ensure that the state is never accidentally mutated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the limitation of Object.freeze ?

A

It is not a deep-freeze. Sub-elements within the frozen object can still be mutated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Does an ES6 fat-arrow function create a new scope?

A

No. It is not lexically scoped. ‘this’ means the same thing inside an arrow function that it does outside of it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is middleware installed into a store?

How would you set up a logger?

A

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) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When writing your own middleware, what signature must be followed?

A
const myMiddleware = store => next => action => {
 // my side effects
 return next(action);
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What npm package allows us to log changes to our store’s state?

A

redux-logger

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s the purpose of using a Thunk?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly