Class: BatchResolve

baja. BatchResolve


new BatchResolve(ords)

BatchResolve is used to resolve a list of ORDs together.

This method should always be used if multiple ORDs need to be resolved at
the same time.

Parameters:
Name Type Description
ords Array.<baja.Ord>

an array of ORDs to resolve.

Extends

Methods


<static> resolve(params)

Resolve an array of ORDs.

Parameters:
Name Type Description
params Object

parameters object. This may also be the array of
ORDs directly if no other parameters are required.

Properties
Name Type Argument Description
ords Array.<(String|baja.Ord)> <optional>

the ORDs to resolve

base baja.Object <optional>

the base Object to resolve the ORDs
against.

subscriber baja.Subscriber <optional>

if defined, any mounted
Components are subscribed using this Subscriber.

lease Boolean <optional>

if defined, any resolved and mounted
components are leased.

leaseTime Number | baja.RelTime <optional>

the lease time used for
leasing Components.

Returns:

promise to be resolved with a BatchResolve instance

Type
Promise
Example
BatchResolve.resolve([ 'station:|slot:/foo', 'station:|slot:/bar' ])
  .then(function (br) {
    var foo = br.get(0), bar = br.get(1);
  });

each(func)

For each resolved target, call the specified function.

If any ORDs failed to resolve, an error will be thrown.

When the function is called, the this will be the resolved
Component's target. The target's object will be passed as a parameter
into the function.

Parameters:
Name Type Description
func function
Throws:

thrown if any of the ORDs failed to resolve

Type
Error

equals(obj)

Indicates whether some other object is equal to this one.

Parameters:
Name Type Description
obj Object

the reference object with which to compare.

Inherited From:
Returns:

true if this object is the same as the obj argument; false otherwise.

Type
Boolean

get(index)

Return the resolved object at the specified index.

If the ORD failed to resolve, an error will be thrown.

Parameters:
Name Type Description
index Number
Throws:

thrown if the ORD failed to resolve

Type
Error
Returns:

the resolved object

Type
baja.Object

getFail(index)

Return the error for a particular ORD that failed to resolve or null for no error.

Parameters:
Name Type Description
index Number
Returns:

the error or null if no error.

Type
Error

getOrd(index)

Return the ORD at the specified index or null if the index is invalid.

Parameters:
Name Type Description
index Number
Returns:
Type
baja.Ord

getTarget(index)

Return the ORD Target at the specified index.

If the ORD failed to resolve, an error will be thrown.

Parameters:
Name Type Description
index Number
Throws:

thrown if ORD failed to resolve

Type
Error
Returns:

the ORD Target

Type
module:baja/ord/OrdTarget

getTargetObjects()

Return an array of resolved objects.

If any of the ORDs failed to resolve, an error will be thrown.

Throws:

thrown if any ORDs failed to resolve

Type
Error
Returns:

an array of objects

Type
Array.<baja.Object>

getTargets()

Return an array of resolved ORD Targets.

If any of the ORDs failed to resolve, an error will be thrown.

Throws:

thrown if any ORDs failed to resolve

Type
Error
Returns:

an array of ORD Targets

Type
Array.<module:baja/ord/OrdTarget>

isResolved(index)

Return true if the ORD at the specified index has successfully resolved.

Parameters:
Name Type Description
index Number
Returns:
Type
Boolean

resolve( [obj])

Batch resolve an array of ORDs.

A Batch Resolve should be used whenever more than one ORD needs to resolved.

Any network calls that result from processing an ORD are always asynchronous.

This method can only be called once per BatchResolve instance.

When using promises, the static BatchResolve.resolve function will be
a little cleaner.

Parameters:
Name Type Argument Description
obj Object <optional>

the object literal that contains the method's
arguments.

Properties
Name Type Argument Description
ok function <optional>

(Deprecated: use Promise) the ok function called
once all of the ORDs have been successfully resolved. When the function is
called, this is set to the BatchResolve object.

fail function <optional>

(Deprecated: use Promise) the fail function
called if any of the ORDs fail to resolve. The first error found is pass
as an argument to this function.

base baja.Object <optional>

the base Object to resolve the ORDs against.

subscriber baja.Subscriber <optional>

if defined, any mounted
Components are subscribed using this Subscriber.

lease Boolean <optional>

if defined, any resolved and mounted
components are leased.

leaseTime Number | baja.RelTime <optional>

the lease time used for
leasing Components.

See:
Returns:

a promise that will be resolved once the ORD resolution
is complete. The argument to the then callback will be the BatchResolve
instance.

Type
Promise
Example
var r = new baja.BatchResolve(["station:|slot:/Ramp", "station:|slot:/SineWave"]);
  var sub = new baja.Subscriber(); // Also batch subscribe all resolved Components
  
  r.resolve({ subscriber: sub })
    .then(function () {
      // Get resolved objects
      var obj = r.getTargetObjects();
    })
    .catch(function (err) {
      // Called if any of the ORDs fail to resolve
    });

  // Or use the each method (will only be called if all ORDs resolve). Each will
  // be called for each target.
  r.resolve({
    each: function () {
      baja.outln("Resolved: " + this.toPathString());
    },
    subscriber: sub
  });

size()

Return the number of items in the Batch.

Returns:
Type
Number

valueOf()

Return the inner value of the object.

By default the object's instance is returned.

Inherited From:
Returns:

the inner value of the object or just the object's instance.

Type
*