Creates a new One instance for propagating operations to all the items in many.
The many objects or functions this One will delegate to.
Optional
recursive: booleanWhether to wrap the arrays returned by get
with another One.
Optional
context: any[]An optional shared context to be passed to all propagated method or function calls. This is an array of objects passed as the final arguments in calls. Empty array by default.
Optional
ctor: OneConstructorThe constructor used to create the get
Ones. This parameter is used internally;
no need to supply an argument.
const loginYes = new One([username => profileView(username)]);
loginYes.call([[username]]);
Optional
contextThe context shared by the many functions or methods of the objects in many. They all receive its items as their last set of arguments.
Optional
ctorThe constructor function used for creating new 'One's in calls to get
.
The many objects this One delegates to.
Optional
recursiveWhether this One will return other 'One's in calls to get
.
Calls all the items in many (if method is not specified) or their
corresponding methods (if method is specified). All the calls will
receive any items in this.context
as their final arguments to
enable communication.
args can be specified as follows:
[[a1, a2], [a1, a2], [a1, a2]]
If this.many
has 3 items, they will receive their own args. If there
are more items in this.many
, they will all get the last provided args array
(here the one passed to the third item).
The one
function wraps created 'One's with a proxy to allow methods
to be called directly on them. Assuming we want to pass the same args
as above to such a method, the call will look like:
object.method([a1, a2], [a1, a2], [a1, a2])
.
There is no need to wrap with the outer array in such cases.
Call returns an array containing the return values of the individual calls to many items.
Optional
args: any[]The function or method arguments
Optional
method: string | number | symbolThe name of a method to call. A function call is assumed if not specified.
Optional
ignoreContext: booleanSet this to a truthy value to prevent the shared context from getting passed in this call.
const loginYes = new One([username => profileView(username)]);
loginYes.call([[username]]);
Gets corresponding properties from all the objects in many. If this is a recursive One and forceArray is falsy, the array result will be used as the 'many' argument in a call to this.ctor and the created One is returned instead of the array.
Optional
prop: string | number | symbolOptional
forceArray: booleanconst o = new One([{a: 1}, {a: 2}])
o.get('a'); // [1, 2]
An object which delegates actions on it to other objects
Example