LK
connect(selectors,actions)
Size: a a a
LK
connect(selectors,actions)
IM
IM
connect(createStructuredSelector({
todos: todoSelector
}), actions)
IM
LK
state?
IM
createStructuredSelector
прокине кожному селектору state & propsLK
LK
LK
LK
IM
LK
LK
createStructuredSelector is a convenience function for a common pattern that arises when using Reselect. The selector passed to a connect decorator often just takes the values of its input-selectors and maps them to keys in an object:
createStructuredSelector takes an object whose properties are input-selectors and returns a structured selector. The structured selector returns an object with the same keys as the inputSelectors argument, but with the selectors replaced with their values.
LK
НШ
LK
LK
export function createStructuredSelector(selectors, selectorCreator = createSelector) {
if (typeof selectors !== 'object') {
throw new Error(
'createStructuredSelector expects first argument to be an object ' +
`where each property is a selector, instead received a ${typeof selectors}`
)
}
const objectKeys = Object.keys(selectors)
return selectorCreator(
objectKeys.map(key => selectors[key]),
(...values) => {
return values.reduce((composition, value, index) => {
composition[objectKeys[index]] = value
return composition
}, {})
}
)
}
LK
LK
НШ
selectorCreator
загляни, если интересно