Closed biirus closed 7 years ago
Hello, you'd need to use parametirezedMatcher
there's an entire chapter in documentation which covers exactly your use case.
Something like:
// view
export default view(({ model, dispatch }) => (
<ul>
{model.list.map((item, index) =>
<li>
<Component model={{content: item}} dispatch={forwardTo(dispatch, 'Component', index)} />
</li>
)}
</ul>
));
// updater
import { Updater, Matchers } from 'redux-elm';
export default new Updater({ components: [] })
.case('Component', (model, action) => {
const numericComponentIndex = parseInt(action.matching.args.param, 10);
return {
...model,
components: model.components.map((componentModel, index) => {
if (index === numericComponentIndex) {
return componentUpdater(componentModel, action);
} else {
return componentModel;
}
})
};
}, Matchers.parameterizedMatcher)
Thanks, @tomkis1! My bad =(
np!
Hi, there!
Maybe I have a very stupid question but I can't understand how to make multiple components composition when the list of components is dynamically changes. For example I have two components:
Component it's view:
ComponentList is's view:
it's updater:
It is totally clear for me. But what should I do, if I have dynamically changed component list. Eg:
How should my ComponentList updater look like?