new DynamicEnum()
Represents a baja:DynamicEnum
in BajaScript.
DynamicEnum
stores an ordinal state variable as
a Number
. An instance of EnumRange
may be used to specify the range.
When creating a Simple
, always use the make()
method instead of
creating a new Object.
Extends
Members
-
<static> DEFAULT :baja.DynamicEnum
-
Default DynamicEnum instance.
Type:
Methods
-
<static> make( [obj])
-
Make a
DynamicEnum
.Parameters:
Name Type Argument Description obj
Object | Number <optional>
the Object Literal for the method's arguments or an ordinal.
Properties
Name Type Argument Description ordinal
Number <optional>
the ordinal for the enum. If omitted it
defaults to the first ordinal in the range or 0 if the range has no
ordinals.range
baja.EnumRange <optional>
the range for the enum.
en
baja.DynamicEnum | baja.FrozenEnum | Boolean | String <optional>
if defined, this enum will be used for the ordinal and range.
As well as an enum, this can also be a TypeSpec
String (moduleName:typeName) for a FrozenEnum.Returns:
the DynamicEnum.
- Type
- baja.DynamicEnum
Example
//An ordinal or an Object Literal can be used for the method's arguments... var de1 = baja.DynamicEnum.make(0); // Just with an ordinal //... or with an Object Literal... var de2 = baja.DynamicEnum.make({ordinal: 0, range: enumRange}); //...or create from another enumeration... var de3 = baja.DynamicEnum.make({en: anEnum});
-
decodeAsync(str [, batch])
-
The string encoding of certain Simples may include Type information, or
other data that may be require asynchronous operations to decode. BOX is
designed to handle these situations when decoding data from the station,
but when user code needs to decode string-encoded Simples directly, prefer
this method as it gives the individual Simple a chance to import Types,
etc. to ensure that the decoded Simple is fully correct.The default implementation just returns
decodeFromString
directly.Parameters:
Name Type Argument Description str
string batch
baja.comm.Batch <optional>
optional batch to use
- Inherited From:
Returns:
may return the Simple instance
directly, or a Promise resolving to same - so wrap inPromise.resolve()
if unsure.- Type
- baja.Simple | Promise.<baja.Simple>
-
decodeFromString(str)
-
Decode a
DynamicEnum
from aString
.Parameters:
Name Type Description str
String - Overrides:
Returns:
- Type
- baja.DynamicEnum
-
encodeToString()
-
Encode a
DynamicEnum
to aString
.- 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(arg)
-
Get the enum for the specified tag or ordinal.
This method is used to access an enum based upon a tag or ordinal.
Parameters:
Name Type Description arg
String | Number | baja.Simple a tag or ordinal (any
baja:Number
type).- Since:
-
- Niagara 4.6
Throws:
-
if the tag or ordinal is invalid.
- Type
- Error
Returns:
the enum for the tag or ordinal.
- Type
- baja.DynamicEnum
-
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
-
getDataTypeSymbol()
-
Return the data type symbol.
Returns:
the data type symbol.
- Type
- String
-
getEnum()
-
Return the
Enum
(itself).- Inherited From:
Returns:
- Type
- baja.Enum
-
getIcon()
-
Return the Object's Icon.
- Inherited From:
Returns:
- Type
- baja.Icon
-
getOrdinal()
-
Return the ordinal.
Returns:
the ordinal.
- Type
- Number
-
getRange()
-
Return the range.
Returns:
the enum range.
- Type
- baja.EnumRange
-
getTag()
-
Return the tag for the ordinal.
Returns:
the tag.
- Type
- String
-
getType()
-
Get the type of this instance.
- Inherited From:
Returns:
- Type
- Type
-
is(arg)
-
Equals comparison via tag or ordinal.
Parameters:
Name Type Description arg
String | Number | baja.DynamicEnum the enum, tag or ordinal used for comparison.
Returns:
true if equal.
- Type
- Boolean
-
isActive()
-
Return whether the enum is active or not.
Returns:
true if active.
- Type
- Boolean
-
make( [obj])
-
Make a DynamicEnum.
Parameters:
Name Type Argument Description obj
Object | Number <optional>
the Object Literal for the method's arguments or an ordinal.
Properties
Name Type Argument Description ordinal
Number <optional>
the ordinal for the enum. If omitted it
defaults to the first ordinal in the range or 0 if the range has no
ordinals.en
baja.DynamicEnum | baja.FrozenEnum | Boolean | String <optional>
if defined, this enum will be used for the ordinal and range.
As well as an enum, this can also be a TypeSpec
String (moduleName:typeName) for a FrozenEnum.- Overrides:
Returns:
the DynamicEnum.
- Type
- baja.DynamicEnum
Example
// An ordinal or an Object Literal can be used for the method's arguments... var de1 = baja.$("baja:DynamicEnum").make(0); // Just with an ordinal //... or with an Object Literal... var de2 = baja.$("baja:DynamicEnum").make({ordinal: 0, range: enumRange}); //...or create from another enumeration... var de3 = baja.$("baja:DynamicEnum").make({en: anEnum});
-
newCopy( [exact])
-
Every value may be cloned using the
newCopy
method.Please note that
Simple
s 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
). -
toString( [cx])
-
Return the String representation of the DynamicEnum.
Parameters:
Name Type Argument Description cx
Object <optional>
Properties
Name Type Argument Description range
baja.EnumRange <optional>
range to use when formatting the string.
If not provided, the range configured on the DynamicEnum directly will be
used.- Overrides:
Returns:
a string representation of this
DynamicEnum (Promise if context given; String if no context given) -
valueOf()
-
Return the ordinal of the
Enum
(itself).- Inherited From:
Returns:
- Type
- Number