Class: CollectionItem

CollectionItem(brain, data)

Represents an item within a collection, providing methods for data manipulation, validation, and interaction with its collection.

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.

Source:

Classes

CollectionItem

Members

ajson

Retrieves string representation of the item, including its key and data.

Source:

collection

Retrieves the collection this item belongs to.

Source:

collection_key

Retrieves the collection name for the instance, either from data or the class method.

Source:

component

Override in child classes to set the component for this item

Source:

key

Retrieves or generates the key for this item.

Source:

ref

Provides a reference object for this item, containing the collection name and key.

Source:

(static) collection_key

Retrieves the collection name derived from the class name.

Source:

(static) defaults

Default properties for an instance of CollectionItem.

Source:

Methods

delete()

Deletes the item from its collection.

Source:

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
Name Type Attributes Description
exclude_key string <optional>

A single key to exclude.

exclude_keys Array.<string> <optional>

An array of keys to exclude. If exclude_key is provided, it's added to this array.

exclude_key_starts_with string <optional>

Exclude keys starting with this string.

exclude_key_starts_with_any Array.<string> <optional>

Exclude keys starting with any of these strings.

exclude_key_includes string <optional>

Exclude keys that include this string.

key_ends_with string <optional>

Include only keys ending with this string.

key_starts_with string <optional>

Include only keys starting with this string.

key_starts_with_any Array.<string> <optional>

Include only keys starting with any of these strings.

key_includes string <optional>

Include only keys that include this string.

Source:
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.

Source:
Returns:

The unique key.

Type
string

init()

Initializes the item with input_data, potentially asynchronously. Handles interactions with other collection items.

Source:

merge_defaults()

Merges default properties from all classes in the inheritance chain.

Source:

parse()

Parses the item's data for any necessary processing or transformation. Placeholder for override in child classes.

Source:

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.

Source:
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.

Source:
Returns:

True if data was successfully updated.

Type
boolean

validate_save() → {boolean}

Validates the item's data before saving.

Source:
Returns:

True if the data is valid for saving.

Type
boolean