Closed SachaG closed 5 years ago
Ping @ochicf
Oh also I think it makes sense to use the type name instead of the collection name:
movies.edit.async
-> movie.update.async
runCallbacks({
// properties
arguments, // [arg1, arg2]
@mattblackdev the reason I didn't use arguments
is because it's a reserved word in JS.
@SachaG 🙈
@SachaG 🙈
Hi! Sorry for the late response, I've been kind of busy this week and I wanted to do it properly.
I like the proposal of having a single object as parameter for runCallbacks
. Some comments/questions:
properties
would be an object or an array? I'm guessing an array, since it fits better with how parameters in functions are handled.properties
, since arguments
is reserved, maybe args
, parameters
or params
would fit better? I think they better represent of what they actually are.options
could be spread directly to the runCallbacks
optionsSo, the signature would look like this:
runCallbacks({
name, // the name of the callback
iterator, // the object that will be iterated on
parameters, // or `args`, `params`. arguments passed down to each iteration (i.e. { arg1, arg2, arg3… })
...options, // callback options such as sync/async/concurrent
});
As for options, I'll refer to the last discussion we had about this topic, and more specific to my post in https://github.com/VulcanJS/Vulcan/issues/1949#issuecomment-389111037. Long story short, the options I think we have:
An option would be to have different specific runners, being consecutive.sync
, consecutive.async
, concurrent
the ones that cover the requirements exposed above.
runCallbacks({
name,
iterator,
parameters,
runs: 'consecutive.sync|consecutive.async|concurrent', // defaults to 'consecutive.sync'?
...otherOptions, // if any
});
That gives me an idea to maybe offer a simple API to add custom runners? That way anyone could add their callback runner if they need to. I think it's kind of complex so I'm not going to enter this rabbit hole right now, but if you guys think it is a good idea tell me and I'll ellaborate.
About the signature of an added callback, I'm guessing we would keep the same as we have right now, being function addedCallback(iterator, ...parameters) { return iterator; }
.
Tell me what you guys think!
properties would be an object or an array? I'm guessing an array, since it fits better with how parameters in functions are handled.
An object I think, otherwise we'll just end up with the same backwards compatibility issues when something changes (i.e. the second argument was modifier
but it's now data
).
following on renaming properties, since arguments is reserved, maybe args, parameters or params would fit better? I think they better represent of what they actually are.
Good point. Maybe args
then?
So, the added callbacks would be like this then, function callbackName(iterator, argsAsObject) {}
, right?
Yes exactly, the callbacks would be the same as now except that all args would be "compressed" into the second argument.
Currently:
Proposal: