Rui::Model::List - a listenable collection
$list = Rui::Model::List->new;
$list = Rui::Model::List->new( data => qw[ a b ], attach => 0, # not needed because 0 is default events => { RangeAdded => $self, RangeRemoved => $self, RangeChanged => $self, }, ); # List State Event Fired # ---------- ----------- $list->set('foo', 1); # a foo RangeChanged [index=1, size=1] $list->add('x'); # a foo x RangeAdded [index=1, size=1] $list->add(['y', 'z'], 0); # y z a foo x RangeAdded [index=0, size=2] $list->remove(0, 3); # foo x RangeRemoved [index=0, size=3] $list->remove(0); # x RangeRemoved [index=0, size=1]
print $list->getIndexByItem('x'); # 0 print $list->get(0); # x print $list->itemExists('foo'); # 0 print $list->getSize; # 1
# example of list attaching to item events and re-broadcasting them $list = Rui::Model::List->new( data => [map {Rui::Model::Value->new} (0..2)], attach => 1, ); $list->addListener(RangeChanged => $self); $list->get(0)->data('foo'); # RangeChanged [index=0, size=1]
$event->index
is
the first index of change in the list, $event->data
is the
number of relevant elements.
Note: you cannot put undef values in the list. Use a value model with an undef value.
If attach
is true, then you can only put objects that feature
Change
and Erase
events in the list (something like a value model. The list will listen to these events in its
children, and update the list listeners.
If attach
is false, you can put anything in the list, except undef
values.
RangeChanged
will only be fired when attach
is true.