Base Component Interface. Apy Composite base component abstraction (field, resource, collection)
Define a set of common methods.
It relies on composite
design pattern.
Methods
-
<static> add(child)
-
Parameters:
Name Type Description child
apy.components.ComponentMixin child component
Returns:
this
-
<static> cleanedData()
-
Logic base to get cleaned data from component
Returns:
A list of cleaned component data
- Type
- Array
-
<static> clone(parent, value)
-
Clone component itself Note: cloning is always deep cloning
Parameters:
Name Type Description parent
apy.components.ComponentMixin (optional) different logical parent component (default is
this.$parent
)value
* any matching value (according to type)
Returns:
Cloned component
-
<static> cloneChild()
-
Clone a child component Note: cloning is always deep cloning
Returns:
Cloned child component
- Type
- *
-
<static> cloneValue(value)
-
Base method interface to clone a value
Parameters:
Name Type Description value
* Any value matching its type
Returns:
cloned value
- Type
- *
-
<static> count()
-
Count of inner component (children)
Returns:
children's count
- Type
- Number
-
<static> createPolyField(schema, value, name, parent)
-
Generalize Polymorph Field creation
Parameters:
Name Type Description schema
Object Field' schema
value
Object Field's value
name
string Field's name
parent
apy.components.ComponentMixin (optional) Field's parent
Returns:
A Polymorph Field instance
-
<static> createStateHolder(states, initialState)
-
Factory method to get a StateHolder instance
Parameters:
Name Type Description states
Array A list of known states
initialState
string The initial state (must be one of the
states
list).Returns:
A StateHolder instance
-
<static> createTypesFactory()
-
Create a registry of default value functions of known types
Returns:
A registry of default value functions of known types
- Type
- Object
-
<static> createTypesForPolyField()
-
Create a list of types to which
apy.components.fields.Poly
may switch It is used for Component having unknown schema definition.Returns:
A list of types
- Type
- Array
-
<static> data()
-
Shortcut original value getter
Returns:
Original value for the component (passed from constructor)
- Type
- *
-
<static> getChild(index)
-
Get a child component
Parameters:
Name Type Description index
Number Component index
Returns:
Child
-
<static> hasChildren()
-
Root component's has children?
Returns:
Is children's count > 0
- Type
- boolean
-
<static> hasUpdated()
-
Return true if at least one inner Component is updated In other words, if original value has changed from current one.
Returns:
Is the Component updated ?
- Type
- boolean
-
<static> inCreateState()
-
Indicate when the Component inner state is equal to CREATE
Returns:
- Type
- boolean
-
<static> inDeleteState()
-
Indicate when the Component inner state is equal to DELETE
Returns:
- Type
- boolean
-
<static> initialize(service, name, type, schema, value, $states, components, endpoint, relationName)
-
Common constructor-like
initialize
methodParameters:
Name Type Description service
apy.CompositeService Service instance
name
string Component name
type
string Component type
schema
Object Component schema
value
Object Component value
$states
apy.helpers.StateHolder Component inner state holder instance
components
Array Component initial components
endpoint
string Component endpoint
relationName
string (optional) Component relation name
Returns:
this
-
<static> inReadState()
-
Indicate when the Component inner state is equal to READ
Returns:
- Type
- boolean
-
<static> inUpdateState()
-
Indicate when the Component inner state is equal to UPDATE
Returns:
- Type
- boolean
-
<static> isReadOnly()
-
Is the component a
read-only
one ?Returns:
true or false
- Type
- boolean
-
<static> isState()
-
Factorize logic Return whether or not the Component's current state is in the passed state
Returns:
- Type
- boolean
-
<static> load()
-
Common method interface To be overridden in subclasses
Returns:
this
-
<static> oneMore()
-
Add one more child to the Component Useful for
apy.components.Collection
Returns:
this
-
<static> prepend(child)
-
Prepend to
components
, any child implementing {apy.components.ComponentMixin} interfaceParameters:
Name Type Description child
apy.components.ComponentMixin child component
Returns:
this
-
<static> remove(child)
-
Remove given child
Parameters:
Name Type Description child
apy.components.ComponentMixin child component
Returns:
this
-
<static> reset()
-
Reset inner component value to its original value ($memo) if different
Returns:
this
-
<static> setCreateState()
-
Set the Component inner state to CREATE
Returns:
this
-
<static> setDeleteState()
-
Set the Component inner state to DELETE
Returns:
this
-
<static> setOptions(schema)
-
Component' schemas object setter
Parameters:
Name Type Description schema
Object Component schema
Returns:
this
-
<static> setParent(parent)
-
Component's parent setter
Parameters:
Name Type Description parent
apy.components.ComponentMixin (optional) A parent component.
Returns:
this
-
<static> setReadState()
-
Set the Component inner state to READ
Returns:
this
-
<static> setState(state)
-
Set Component's inner StateHolder instance to the given state
Parameters:
Name Type Description state
string The state, must be one of the STATES list
Returns:
this
-
<static> setUpdateState()
-
Set the Component inner state to UPDATE
Returns:
this
-
<static> setValue(value)
-
Component's value setter
Parameters:
Name Type Description value
Object Component value
Returns:
this
-
<static> toString()
-
Base Component String representation
Returns:
Component base string representation
- Type
- string
-
<static> validate()
-
Validate each component if error, all errors are collected before being thrown.
Throws:
apy.errors.Error when validation fails
-
continue(char, field)
-
When a Component payload is received from the backend it may contain some extra metadata fields In Eve, those fields are prefixed with
_
Those properties are considered private to the Component
To be used in
forEach
loop ascontinue
Parameters:
Name Type Description char
string Object's property prefix ($, _)
field
string field's name
Returns:
- Type
- boolean
Example
var payload = { _id: '...', _etag: '...', _updated: '...', title: "A nice title", description: "Another nice description" } var myComponent = ... Object.keys(payload).forEach(function(key){ if(myComponent.continue(key, '_')) { myComponent[key] = payload[key]; } });