CollectionEventKind.RESET, WTF Does That Mean?
When handling Flex’s collection change events, most of the change types are pretty self-explanatory. For example, CollectionEventKind.ADD is when an item is added to the collection, or CollectionEventKind.UPDATE is when an item’s property inside the collection changes. However, there’s this ambiguous change type called RESET. The documentation does a wonderful job of describing when this type of collection event is fired: Indicates that the collection has changed so drastically that a reset is required. (ASDoc Link)
Digging through ListCollectionView provides some better insight of when RESET is dispatched. Anytime a collection is passed to ListCollectionView.list, and both the old list and the new list has items in it, it will fire a reset collection change event. Here’s the code Adobe uses for setting a list on ListCollectionView:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public function set list(value:IList):void { if (_list != value) { var oldHasItems:Boolean; var newHasItems:Boolean; if (_list) { _list.removeEventListener(CollectionEvent.COLLECTION_CHANGE, listChangeHandler); oldHasItems = _list.length > 0; } _list = value; if (_list) { // weak listeners to collections and dataproviders _list.addEventListener(CollectionEvent.COLLECTION_CHANGE, listChangeHandler, false, 0, true); newHasItems = _list.length > 0; } if (oldHasItems || newHasItems) reset(); dispatchEvent(new Event("listChanged")); } } |
Lastly, ListCollectionView is a pretty useful class. A lot of new Flex developers go straight to using ArrayCollection, and forget about its father, ListCollectionView. This collection allows you to apply different sorts and filters on a collection without directly modifying the wrapped collection. You can also call addItem() and removeItemAt() on ListCollectionView and have it modify the wrapped collection. Pretty nifty! Here’s an example of it in action:
1 2 3 4 5 6 7 8 9 10 11 | var col:ArrayCollection = new ArrayCollection(); col.addItem('a'); col.addItem('b'); col.addItem('c'); var wrapper:ListCollectionView = new ListCollectionView(col); wrapper.removeItemAt(0); wrapper.removeItemAt(0); wrapper.removeItemAt(0); trace(col.length); // traces: 0 |
by GadgetGadget.info - Gadgets on the web » CollectionEventKind.RESET, WTF Does That Mean?
[...] thedude58 wrote an interesting post today!.Here’s a quick excerptHowever, there’s this ambiguous change type called RESET. The documentation does a wonderful job of describing when this type of collection event is fired: Indicates that the collection has changed so drastically that a reset is … [...]