redux-multi icon indicating copy to clipboard operation
redux-multi copied to clipboard

[question] What is the point?

Open reverofevil opened this issue 9 years ago • 5 comments

Currently the library just lets to write

dispatch(x);
dispatch(y);

as

dispatch([x, y]);

But I don't see why do I need a library for that. Even Promise.all is not a reason for another library. If this middleware have sent a store update event after all the updates once, it would make sense, but (surprisingly) it doesn't. So, what is the point?

reverofevil avatar Dec 11 '16 02:12 reverofevil

I think the point is to use it with redux-promise. Similar technic is used in F8 app by Facebook. See https://github.com/fbsamples/f8app/blob/master/js/actions/login.js#L80

This package is included in F8 here: https://github.com/fbsamples/f8app/blob/master/js/store/array.js

mucsi96 avatar Mar 12 '17 13:03 mucsi96

@mucsi96 That's just a call to Promise.all. You don't need any middleware to do that call.

reverofevil avatar Mar 12 '17 21:03 reverofevil

Ok but then what is the point for the https://github.com/fbsamples/f8app/blob/master/js/store/array.js file?

After every promise is resolved wrapped in Promise.all we will get an array of actions. Redux cannot handle that. You have map over every action and pass it to redux again using next

store => next => action =>
  Array.isArray(action)
    ? action.map(next)
    : next(action);

mucsi96 avatar Mar 12 '17 22:03 mucsi96

@mucsi96 File is not npm package. Being a Facebook employee doesn't imply you're doing it right. You can always use

const mapNext = require('../store/array.js');
const mapped = mapNext(list);

or

const mapped = list.map(next);

whichever is shorter for your purposes.

reverofevil avatar Mar 13 '17 11:03 reverofevil

How can you do for example 2 requests to the backend with that? How should the store configuration and the action dispatcher look like?

mucsi96 avatar Mar 13 '17 21:03 mucsi96