the drunken landlady
DESCRIPTION
ArrayCollection: Advanced Filtering & Data SharingTRANSCRIPT
![Page 1: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/1.jpg)
ArrayCollection:The Drunken Landlady
Ben Schmidtke III
Digital Primates
Twitter: stunnedgrowth
![Page 2: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/2.jpg)
Who Am I
• Ben Schmidtke III
• Consultant - Digital Primates IT Consulting Group
• Flash Platform Developer for 11 years
• Adobe Certified Instructor
• Play Irish Fiddle & Concertina
• Twitter: stunnedgrowth
![Page 3: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/3.jpg)
Agenda
• ArrayCollection (Overview)
• Standard Filtering
• Externalizing Filter
• Compound Filtering
• Sharing Collections, Better
• Questions
![Page 4: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/4.jpg)
Disclaimer
Concepts in compound filtering are bare bones
that would require additional work in order to
optimize for performance
![Page 5: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/5.jpg)
Disclaimer 2
Attempting the following solutions with
HierarchicalCollectionView and
GroupingCollection may require additional
customization.
![Page 6: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/6.jpg)
ArrayCollection
• “The ArrayCollection class is a wrapper class
that exposes an Array as a collection…”
• Is a class that presents different views of the
underlying array
• Can be sorted and filtered without modifying
the source array.
![Page 7: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/7.jpg)
ArrayCollection
• ArrayCollection is comprised of 3 critical
pieces:
– Array: Holds the data
– ArrayList: Manages I/O to the
Array, indexing, a lot of overhead here
– ListCollectionView: Responds to ArrayList
events, manages filtering and sorting
![Page 8: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/8.jpg)
ArrayCollection
![Page 9: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/9.jpg)
In Other Words
• ArrayCollection is a handy wrapper for a
source Array
• Methods for Adding & Removing Data
• Provides sorting and filtering
• Bindable: dispatches events
![Page 10: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/10.jpg)
However…
• ArrayCollection is
– Forces coupling of filter function to use
location
– Difficult to share data efficiently
– Difficult to keep multiple ArrayCollections in
sync when adding & removing items
– Performance Issues & Overhead
![Page 11: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/11.jpg)
Definition
• “View”
– Is a object that visibly displays content to be
viewed by a pair of eyes
– Is a collection of data providing a look at the
underlying data to be consumed by a display
object
![Page 12: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/12.jpg)
Standard Filtering
• Filtering a ArrayCollection alters the data
view but not the underlying data
• To filter, uses filterFunction
• A filterFunction runs every time the data
in the collection changes
![Page 13: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/13.jpg)
Filter Function
• Can be run manually by calling refresh()
or setting the function again
• Returns True or False if the item should
be visible in the collection view
![Page 14: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/14.jpg)
Example Functionpublic function flexFeedsOnlyFilter( item:Object ):Boolean
{
if( !item || !(item is FeedItem) )
{
return false;
}
var fItem:FeedItem = (item as FeedItem);
if(fItem.subject == FeedTypes.FLEX)
{
return true;
}
return false;
}
![Page 15: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/15.jpg)
I Have Filtering Issues
• Filter function’s end up in random classes
scattered all over application.
– Not easily reused
– Couples filtering to view
– Maintenance, difficult to find to change
– Data replication/solutions so not affect
source data model
![Page 16: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/16.jpg)
I Have Filtering Issues
• Difficulty sharing filtered data with
application, bad practices
• Compound filtering difficult
• Have to call refresh()
– Refresh does a lot more than filter…
• And more…
![Page 17: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/17.jpg)
Guideline
• When describing a filter function’s
functionality, if the word “and” is in the
sentence, it’s doing too much.
• Keep it simple
• Limit it to one task
![Page 18: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/18.jpg)
Filtering Tasks
• Task 1: Externalize the filterFunction
• Task 2: Auto refresh
• Task 3: Compound filtering
![Page 19: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/19.jpg)
Task 1: Externalize Function
• Filter Function will:
– Be wrapped in external class
– Filter Function will contain all logic specific
to the objective of the filter
– Allow for easy manipulation of a property
that varies the outcome of the results
![Page 20: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/20.jpg)
We need a few things
• Base Interface
– filterFunction (item:Object):Boolean
• Base Class
– Extends EventDispatcher
– Implements Interface
– Allows for override of filterFunction
![Page 21: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/21.jpg)
Create Filter Class
• Create new class
• Extend base filter class
• Move filter code into filterFunction
method
• Add property to change outcome
• Apply to collection
![Page 22: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/22.jpg)
Externalized
• Easily reused
• Much easier to UnitTest
• Operates on data passed to it instead of
reaching out
• No longer coupled to the part of the
application applying the filter
![Page 23: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/23.jpg)
Task 2: Autorun
• Filter Function will:
– Dispatch events when it should be run
• Alter ArrayCollection:
– Add new filter property
– Automatically run filter when set
– Watch for changes and refresh()
![Page 24: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/24.jpg)
Auto Running
• Less code to maintain
• No need to call refresh() anymore
• Be careful when working with values that
change rapidly, causing performance
problems
![Page 25: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/25.jpg)
Task 3: Compound Filtering
• ArrayCollection will:
– Allow for multiple filters to be applied
– Will refresh when any of them change
![Page 26: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/26.jpg)
Sharing Collection Data
• Typically a ArrayCollection needs to be
manipulated for a variety of reasons:
– Sorting
– Filtering
– Data Modification
![Page 27: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/27.jpg)
Common Issue
ArrayCollection needs to be filtered or
without affecting the data model because
the data is being used in multiple views.
![Page 28: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/28.jpg)
Common Solution
var newColl:ArrayCollection =
new ArrayCollection( masterColl.source );
![Page 29: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/29.jpg)
Sharing Option #1
new ArrayCollection( master.source );
![Page 30: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/30.jpg)
The Problem?
• Any changes to the master collection will
not be reflected in the new collection
without knowing to call refresh()
– unless it is a property change event on
existing data
![Page 31: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/31.jpg)
Sharing Option #2
• Change ArrayCollection to accept a list
new ArrayCollection ( master.list );
![Page 32: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/32.jpg)
Perks To List Sharing
• Any changes made to the data will
automatically update in all
ArrayCollections
• Sorting & Filtering are unique
• Smaller memory footprint with only one
ArrayList
• Less to manage
![Page 33: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/33.jpg)
Task 4: Modify ArrayCollection
• Modify ArrayCollection constructor to
accept a IList
• Change Model to return shared list
collections
![Page 34: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/34.jpg)
Putting It All Together
• Example of single shared collection in
multiple views uniquely sorted with
compound filtering and all responding to
data changes.
![Page 35: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/35.jpg)
Sharing Option #3
• Uses masterColl.source
• All sub collections handed out are stored
• Watcher Object watches for changes on
master collection
• Notifies sub collections of changes
![Page 36: The Drunken Landlady](https://reader035.vdocuments.mx/reader035/viewer/2022062308/559bde071a28ab39568b4600/html5/thumbnails/36.jpg)
Thank You, Questions?
Ben Schmidtke III
Consultant - Digital Primates IT Consulting Group