Generic list of items that is stored in a given block.

Note: If you make any changes to the item contents manually, do not forget to notify the list about the changes by calling updated(itemID) method.

Note: Each list item should at least hold a numerical ID ("id" field). The ID of a list item should be unique in that list. If the items have an amount accociated, the field "amount" should also be given. You can get the next unique free ID from nextID property.

Note: If you remove the items from the list bypassing the removeItem() call, do not forget to call updated() method without any parameters to notify the server that the whole list was updated.

This class is described in detail in Generic Containers article.

Constructor

new (s:ServerClass, b:Block, a:String)

Creates a new generic list of items on top of cache block.

Parameters:

s

Slave server.

b

Cache block.

a

Block attribute name.

Fields

read only length:Int

List length.

read only nextID:Int

Next free unique item ID. Always increments.

Methods

addItem (item:Item):String

Adds an item to the list.

Parameters:

item

New item.

Returns:

Operation status. ok - operation successful. idExists - item with this ID exists in the list.

inline getBlock ():Block

Returns the block.

Returns:

Underlying cache block.

getByField (field:String, val:Dynamic):Item

Returns the first list item with a given field value.

Parameters:

field

List item field.

val

List item value.

Returns:

List item. Returns null if not found.

getIndex (id:Int):Int

Returns list item index by its ID.

Parameters:

id

List item ID.

Returns:

List item index. Returns -1 if not found.

getItem (id:Int):Item

Returns list item by its ID.

Parameters:

id

List item ID.

Returns:

List item. Returns null if not found.

inline getList ():Array<Item>

Returns the list of items from block.

Returns:

Array of list items.

hasItem (id:Int):Bool

Returns whether the list has an item with this ID.

Parameters:

id

List item ID.

Returns:

True if the list has an item with this ID. False otherwise.

removeItem (id:Int):Void

Removes the item with this ID from the list.

Parameters:

id

Unique item ID.

inline updated (?id:Int):Void

Notifies the cache block about the changes made to the list.

Parameters:

id

List item ID. If not set full block will be marked as updated.