Constructor
new CollectionItem(brain, data)
Creates an instance of CollectionItem.
Parameters:
Name | Type | Description |
---|---|---|
brain |
Object | The central storage or context. |
data |
Object | null | Initial data for the item. |
Classes
Members
ajson
Retrieves string representation of the item, including its key and data.
collection
Retrieves the collection this item belongs to.
collection_key
Retrieves the collection name for the instance, either from data or the class method.
component
Override in child classes to set the component for this item
key
Retrieves or generates the key for this item.
ref
Provides a reference object for this item, containing the collection name and key.
(static) collection_key
Retrieves the collection name derived from the class name.
(static) defaults
Default properties for an instance of CollectionItem.
Methods
delete()
Deletes the item from its collection.
filter(filter_opts) → {boolean}
Filters items in the collection based on provided options. functional filter (returns true or false) for filtering items in collection; called by collection class
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
filter_opts |
Object | Filtering options. Properties
|
Returns:
True if the item passes the filter, false otherwise.
- Type
- boolean
get_key() → {string}
Generates or retrieves a unique key for the item. Can be overridden in child classes.
Returns:
The unique key.
- Type
- string
init()
Initializes the item with input_data, potentially asynchronously. Handles interactions with other collection items.
merge_defaults()
Merges default properties from all classes in the inheritance chain.
parse()
Parses the item's data for any necessary processing or transformation. Placeholder for override in child classes.
sanitize_data(data) → {Object}
Sanitizes the data of an item to ensure it can be safely saved.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The data to sanitize. |
Returns:
The sanitized data.
- Type
- Object
update_data(data) → {boolean}
Updates the data of this item with new data.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The new data for the item. |
Returns:
True if data was successfully updated.
- Type
- boolean
validate_save() → {boolean}
Validates the item's data before saving.
Returns:
True if the data is valid for saving.
- Type
- boolean