CollectionBase
Direct Subclass:
Base class for all collections classes.
Example:
API:
->set_all(arg_items):nothing - Set all collection items.
->get_all(arg_types):array - Get all collection items or filter items with given type.
->get_all_names(arg_types):array - Get all items names with or without a filter on items types.
->get_all_ids():array - Get all items ids with or without a filter on items types.
->item(arg_name):Instance - Get an item by its name.
->get_count():number - Get all items count.
->get_first():object|undefined - Get first item.
->get_last():object|undefined - Get last item.
->add(arg_item):nothing - Add an item to the collection.
->add_first(arg_item):nothing - Add an item to the collection at the first position.
->remove(arg_item):nothing - Remove an item from the collection.
->has(arg_item):boolean - Test if an item is inside the collection.
->find_by_name(arg_name):Instance|undefined - Find an item by its name into the collection.
->find_by_id(arg_id):Instance|undefined - Find an item by its id into the collection.
->find_by_attr(arg_attr_name, arg_attr_value):Instance|undefined - Find an item by one of its attributes into the collection.
->find_by_filter(arg_filter_function):Instance|undefined - Find an item by a filter function.
->filter_by_attr(arg_attr_name, arg_attr_value):array - Filter items by one of theirs attributes into the collection.
->filter_by_filter(arg_filter_function):array - Filter items by a filter function.
->get_accepted_types():array - Get all collection accepted types.
->set_accepted_types(arg_types):nothing - Set all collection accepted types.
->add_accepted_type(arg_type):nothing - Add one collection accepted type.
->has_accepted_type(arg_type):boolean - Test if collection has given accepted type.
->forEach(arg_cb):nothing - forEach wrapper on ordered items.
Constructor Summary
Public Constructor | ||
public |
constructor(): nothing Create a collection of Instance objects. |
Member Summary
Public Members | ||
public |
Class type flag. |
Private Members | ||
private |
_accepted_types: array Accepted types array. |
|
private |
_items_array: array Items array. |
|
private |
Items ids map. |
|
private |
Items names map. |
Method Summary
Public Methods | ||
public |
Add an item to the collection. |
|
public |
add_accepted_type(arg_type: string): nothing Add one collection accepted type. |
|
public |
Add an item to the collection at the first position. |
|
public |
filter_by_attr(arg_attr_name: string, arg_attr_value: any): array Filter items by one of theirs attributes into the collection. |
|
public |
filter_by_filter(arg_filter_function: string): array Filter items by a filter function. |
|
public |
find_by_attr(arg_attr_name: string, arg_attr_value: any): Instance | undefined Find an item by one of its attributes into the collection. |
|
public |
find_by_filter(arg_filter_function: string): Instance | undefined Find an item by a filter function. |
|
public |
find_by_id(arg_id: string): Instance | undefined Find an item by its id into the collection. |
|
public |
find_by_name(arg_name: string): Instance | undefined Find an item by its name into the collection. |
|
public |
forEach wrapper on ordered items. |
|
public |
Get an item by its name. |
|
public |
get_accepted_types(): array Get all collection accepted types. |
|
public |
Get all collection items or filter items with given type. |
|
public |
get_all_ids(): array Get all items ids with or without a filter on items types. |
|
public |
get_all_names(arg_types: array | string | nothing): array Get all items names with or without a filter on items types. |
|
public |
Get all items count. |
|
public |
Get first item. |
|
public |
Get last item. |
|
public |
Test if an item is inside the collection. |
|
public |
has_accepted_type(arg_type: string): boolean Test if collection has given accepted type. |
|
public |
Get an item by its name. |
|
public |
Remove an item from the collection. |
|
public |
set_accepted_types(arg_types: array): nothing Set all collection accepted types. |
|
public |
Set all collection items. |
|
public |
toString(): * Format string dump. |
Private Methods | ||
private |
Add an item to the collection without type checks (unsafe). |
|
private |
_add_first(arg_item: Instance): nothing Add an item to the collection without type checks at first position (unsafe). |
|
private |
_get_all(): array Get all collection items. |
|
private |
Test if an item is inside the collection without type checks (unsafe). |
|
private |
Remove an item from the collection without type checks (unsafe). |
|
private |
_set_all(arg_items: array): nothing Set all collection items. |
Inherited Summary
From class Loggable | ||
public |
Log context. |
|
public |
Class type flag. |
|
public |
Trace is enabled for this flag. |
|
private |
Logger manager instance (default undefined) |
|
public |
Trace DEBUG formatted message. |
|
public |
disable_trace(): nothing Disable traces. |
|
public |
enable_trace(): nothing Enable traces. |
|
public |
enter_group(arg_group: string): nothing Trace INFO message on "enter trace group". |
|
public |
Trace ERROR formatted message. |
|
public |
Define get class name method for non Instance classes. |
|
public |
Get instance context. |
|
public |
Get logger manager. |
|
public |
Define get instance name method for non Instance classes. |
|
public |
Get trace flag. |
|
public |
Trace INFO formatted message. |
|
public |
leave_group(arg_group: string): nothing Trace INFO message on "leave trace group". |
|
public |
separate_level_1(): nothing Trace INFO trace level 1 separator. |
|
public |
separate_level_2(): nothing Trace INFO trace level 2 separator. |
|
public |
separate_level_3(): nothing Trace INFO trace level 3 separator. |
|
public |
Set trace flag. |
|
public |
should_trace(arg_traces_cfg: object): boolean Calculate should trace flag. |
|
public |
should_trace_class(arg_traces_cfg: object): boolean Calculate should trace flag for classes. |
|
public |
should_trace_collection_item(arg_traces_cfg: object, arg_collection_name: string, arg_this_item_accessor: string): boolean Calculate should trace flag for given collection of names or patterns. |
|
public |
should_trace_module(arg_traces_cfg: object): boolean Calculate should trace flag for modules. |
|
public |
should_trace_name(arg_traces_cfg: object): boolean Calculate should trace flag for instances names. |
|
public |
Toggle trace flag. |
|
public |
update_trace_enabled(): nothing Update trace enabled flag. |
|
public |
Trace WARN formatted message. |
From class Errorable | ||
private |
Error text (default null). |
|
private |
Has error flag (default false). |
|
public |
Set an error. |
|
public |
Default helper for "not implemented" error. |
|
public |
Get error message. |
|
public |
Test is an error is set. |
Public Constructors
public constructor(): nothing source
Create a collection of Instance objects.
Override:
Errorable#constructorReturn:
nothing |
Public Members
Private Members
Public Methods
public add(arg_item: Instance): nothing source
Add an item to the collection.
Params:
Name | Type | Attribute | Description |
arg_item | Instance | Instance item. |
Return:
nothing |
public add_accepted_type(arg_type: string): nothing source
Add one collection accepted type.
Params:
Name | Type | Attribute | Description |
arg_type | string | accepted types string. |
Return:
nothing |
public add_first(arg_item: Instance): nothing source
Add an item to the collection at the first position.
Params:
Name | Type | Attribute | Description |
arg_item | Instance | Instance item. |
Return:
nothing |
public filter_by_attr(arg_attr_name: string, arg_attr_value: any): array source
Filter items by one of theirs attributes into the collection.
Params:
Name | Type | Attribute | Description |
arg_attr_name | string | instance attribute name. |
|
arg_attr_value | any | instance attribute value. |
Return:
array |
public filter_by_filter(arg_filter_function: string): array source
Filter items by a filter function.
Params:
Name | Type | Attribute | Description |
arg_filter_function | string | function to apply on instance, returns a boolean. |
Return:
array |
public find_by_attr(arg_attr_name: string, arg_attr_value: any): Instance | undefined source
Find an item by one of its attributes into the collection.
Params:
Name | Type | Attribute | Description |
arg_attr_name | string | instance attribute name. |
|
arg_attr_value | any | instance attribute value. |
public find_by_filter(arg_filter_function: string): Instance | undefined source
Find an item by a filter function.
Params:
Name | Type | Attribute | Description |
arg_filter_function | string | function to apply on instance, returns a boolean. |
public find_by_id(arg_id: string): Instance | undefined source
Find an item by its id into the collection.
Params:
Name | Type | Attribute | Description |
arg_id | string | instance id. |
public find_by_name(arg_name: string): Instance | undefined source
Find an item by its name into the collection.
TODO: optimize with a map index.
Params:
Name | Type | Attribute | Description |
arg_name | string | instance name. |
public forEach(arg_cb: function): nothing source
forEach wrapper on ordered items.
Params:
Name | Type | Attribute | Description |
arg_cb | function | callback to call on each item. |
Return:
nothing |
public get(arg_name: string): Instance | undefined source
Get an item by its name.
Params:
Name | Type | Attribute | Description |
arg_name | string | instance name. |
public get_accepted_types(): array source
Get all collection accepted types.
Return:
array | array of types strings. |
public get_all(arg_types: array | string | nothing): array source
Get all collection items or filter items with given type.
Params:
Name | Type | Attribute | Description |
arg_types | array | string | nothing | type or types for items filtering. |
Return:
array | all or filtered items, empty array if not found. |
public get_all_ids(): array source
Get all items ids with or without a filter on items types.
Return:
array | all items ids. |
public get_all_names(arg_types: array | string | nothing): array source
Get all items names with or without a filter on items types.
Params:
Name | Type | Attribute | Description |
arg_types | array | string | nothing | type or types for items filtering. |
Return:
array | all or filtered items names, empty array if not found. |
public has(arg_item: Instance): boolean source
Test if an item is inside the collection.
Params:
Name | Type | Attribute | Description |
arg_item | Instance | Instance item. |
public has_accepted_type(arg_type: string): boolean source
Test if collection has given accepted type.
Params:
Name | Type | Attribute | Description |
arg_type | string | accepted types string. |
public item(arg_name: string): Instance | undefined source
Get an item by its name.
Params:
Name | Type | Attribute | Description |
arg_name | string | instance name. |
public remove(arg_item: Instance): nothing source
Remove an item from the collection.
Params:
Name | Type | Attribute | Description |
arg_item | Instance | Instance item. |
Return:
nothing |
public set_accepted_types(arg_types: array): nothing source
Set all collection accepted types.
Params:
Name | Type | Attribute | Description |
arg_types | array | accepted types strings array. |
Return:
nothing |
public set_all(arg_items: Instance | array): nothing source
Set all collection items.
Params:
Name | Type | Attribute | Description |
arg_items | Instance | array | collection items: one or many Instance objects. |
Return:
nothing |
Private Methods
private _add(arg_item: Instance): nothing source
Add an item to the collection without type checks (unsafe).
Params:
Name | Type | Attribute | Description |
arg_item | Instance | Instance item. |
Return:
nothing |
private _add_first(arg_item: Instance): nothing source
Add an item to the collection without type checks at first position (unsafe).
Params:
Name | Type | Attribute | Description |
arg_item | Instance | Instance item. |
Return:
nothing |
private _has(arg_item: Instance): boolean source
Test if an item is inside the collection without type checks (unsafe).
Params:
Name | Type | Attribute | Description |
arg_item | Instance | Instance item. |
private _remove(arg_item: Instance): nothing source
Remove an item from the collection without type checks (unsafe).
Params:
Name | Type | Attribute | Description |
arg_item | Instance | Instance item. |
Return:
nothing |
private _set_all(arg_items: array): nothing source
Set all collection items.
Params:
Name | Type | Attribute | Description |
arg_items | array | Instance objects array. |
Return:
nothing |