Mixin: ComponentMixin

ComponentMixin

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

Type
apy.components.ComponentMixin

<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

Type
apy.components.ComponentMixin

<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

Type
apy.components.fields.Poly

<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

Type
apy.helpers.StateHolder

<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

Type
apy.components.ComponentMixin

<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 method

Parameters:
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

Type
apy.components.ComponentMixin

<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

Type
apy.components.ComponentMixin

<static> oneMore()

Add one more child to the Component Useful for apy.components.Collection

Returns:

this

Type
apy.components.ComponentMixin

<static> prepend(child)

Prepend to components, any child implementing {apy.components.ComponentMixin} interface

Parameters:
Name Type Description
child apy.components.ComponentMixin

child component

Returns:

this

Type
apy.components.ComponentMixin

<static> remove(child)

Remove given child

Parameters:
Name Type Description
child apy.components.ComponentMixin

child component

Returns:

this

Type
apy.components.ComponentMixin

<static> reset()

Reset inner component value to its original value ($memo) if different

Returns:

this

Type
apy.components.ComponentMixin

<static> setCreateState()

Set the Component inner state to CREATE

Returns:

this

Type
apy.components.ComponentMixin

<static> setDeleteState()

Set the Component inner state to DELETE

Returns:

this

Type
apy.components.ComponentMixin

<static> setOptions(schema)

Component' schemas object setter

Parameters:
Name Type Description
schema Object

Component schema

Returns:

this

Type
apy.components.ComponentMixin

<static> setParent(parent)

Component's parent setter

Parameters:
Name Type Description
parent apy.components.ComponentMixin

(optional) A parent component.

Returns:

this

Type
apy.components.ComponentMixin

<static> setReadState()

Set the Component inner state to READ

Returns:

this

Type
apy.components.ComponentMixin

<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

Type
apy.components.ComponentMixin

<static> setUpdateState()

Set the Component inner state to UPDATE

Returns:

this

Type
apy.components.ComponentMixin

<static> setValue(value)

Component's value setter

Parameters:
Name Type Description
value Object

Component value

Returns:

this

Type
apy.components.ComponentMixin

<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 as continue

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];
    }
});