Class: Facets

baja. Facets


new Facets()

Represents a baja:Facets in BajaScript.

BFacets is a map of name/value pairs used to annotate a
BComplex's Slot or to just provide additional metadata
about something. The values of facets may only be
BIDataValues which are a predefined subset of simples.

When creating a Simple, always use the make() method instead of
creating a new Object.

Extends

Members


<static> DEFAULT :baja.Facets

Default Facets instance.

Type:

<static> NULL :baja.Facets

NULL Facets instance.

Type:

decodeFromString

Decode a String to a Facets.

Overrides:

Methods


<static> getFacetsFromObject(obj)

Return the facets for the given object.

If the object is a Facets, that object is returned.

If the object has a facets slot, the value of that slot is returned.

If the object has a parent, the Facets from the object's parent slot is
returned.

If the facets can't be found then baja.Facets.DEFAULT is returned.

Parameters:
Name Type Description
obj
Returns:
Type
baja.Facets

<static> make(keys [, values])

Make a Facets object. This function can either take two Array objects
for keys and values, two Facets or two object literals. In the latter two
cases, a new Facets object will be returned containing a combination of
keys and values from both input Facets objects. If a key exists on both
Facets objects, the value from the second Facets will take precedence.

Parameters:
Name Type Argument Description
keys Array.<String> | baja.Facets | Object

an array of keys for the
facets. The keys must be Strings. (This may also be a Facets (or object
literal) whose values will be combined with the second parameter. Values in
this object will be overwritten by corresponding values from the other).

values Array.<baja.Simple> | baja.Facets | Object <optional>

an array of values
for the facets. The values must be BajaScript Objects whose Type
implements BIDataValue. (This may also be a Facets (or object literal)
object whose values will be combined with the first parameter. Values in
this object will overwrite corresponding values on the other.)

Returns:

the Facets

Type
baja.Facets
Example
var facets1 = baja.Facets.make(['a', 'b'], ['1', '2']);
  var facets2 = baja.Facets.make(['b', 'c'], ['3', '4']);
  var facets3 = baja.Facets.make(facets1, facets2);
  baja.outln(facets3.get('a')); //1
  baja.outln(facets3.get('b')); //3 - facets2 overwrote value in facets1
  baja.outln(facets3.get('c')); //4

decodeAsync(str [, batch])

Decode a String to a Facets, doing an async decode on each individual
encoded Simple.

Parameters:
Name Type Argument Description
str String
batch baja.comm.Batch <optional>
Overrides:
Returns:
Type
Promise.<baja.Facets>

encodeToString()

Encode Facets to a String.

Overrides:
Returns:
Type
String

equals(obj)

Equality test.

Parameters:
Name Type Description
obj
Inherited From:
Returns:
Type
Boolean

equivalent(obj)

Equivalence test.

equivalent() is used to compare if two Objects have equivalent
state, but might not want to return true for equals since it
it has implied semantics for many operations. The default
implementation returns the result of baja.Object#equals.

Parameters:
Name Type Description
obj
Inherited From:
Returns:
Type
Boolean

get(key [, def])

Return a value from the map for the given key.

Parameters:
Name Type Argument Description
key String

the key used to look up the data value

def <optional>

if defined, this value is returned if the key can't be found.

Returns:

the data value for the key (null if not found)


getAgents( [is], batch)

Returns a promise that resolves to the agent list for this Object.

Parameters:
Name Type Argument Description
is Array.<String> <optional>

An optional array of filters to add to the
agent query.

batch baja.comm.Batch

An optional object used to batch network
calls together.

Inherited From:
See:
Returns:

A promise that will resolve with the Agent Info.

Type
Promise

getIcon()

Return the Object's Icon.

Inherited From:
Returns:
Type
baja.Icon

getKeys()

Return a copy of the Facets keys.

Returns:

all of the keys used in the Facets

Type
Array.<String>

getType()

Get the type of this instance.

Inherited From:
Returns:
Type
Type

make()

Make a Facets object. Same as baja.Facets.make.

Overrides:
See:

newCopy( [exact])

Every value may be cloned using the newCopy method.

Please note that Simples are immutable so they don't
allocate a new instance.

Parameters:
Name Type Argument Description
exact Boolean <optional>

true if an exact copy of the value should be
made (only valid in the Component architecture).

Inherited From:
See:
Returns:

a copy of the value (or the same instance if the value is a
Simple).


toObject()

Converts the Facets (itself) to an object literal.

Returns:
Type
Object

toString( [cx])

Return a String representation of the Facets.

Parameters:
Name Type Argument Description
cx Object <optional>

Passed directly into the toString() functions of the
individual Simples within. Object Literal used to specify formatting
facets.

Overrides:
Returns:

returns a Promise if a cx is passed in.

Type
String | Promise.<String>

valueOf()

Return the value of the Facets.

Overrides:
Returns:
Type
String