ArrayCollection filterFunction behavior: persisting Commands?

pdemling's Avatar


02 Jul, 2012 08:38 PM

[First off, I'm currently in the middle of a big refactor-to-Robotlegs effort, and loving the framework - so thank you already for this great resource!]

So I have a situation where I use a Command to define and then assign a filterFunction to an arrayCollection in one of my data Models. I put this in a Command because the filterFunction needs to reference other models in the app (namely, complex data-selection criteria in other Models). Then after calling refresh() on the ArrayCollection, my ViewMediator picks up a "data refreshed" custom event, and passes the filtered data Model to its View. So far so good! But it gets better, unexpectedly (to me):

If I later refresh the data Model's ArrayCollection (either from the ViewMediator, or from a different Command - doesn't matter), the fitlerFunction still applies - and what's more, in debug mode I can see it step into the filterFunction code in the Command in which it's defined - even though a new instance of the Command hasn't been invoked! Also, no need to send a refreshed version of the Model from C to VM to V: it just magically updates correctly in the view, wherever I call refresh() from.

This struck me as weird, given my current understanding of RL, that 1) Commands do not persist after their execute() call, and 2) Views are very decoupled from Models. My guess is that my adding a reference to the Command instance (when I assign one of its functions as the ArrayCollection's filter function) prevents the RL framework from destroying the instance (like the FlashPlayer GC works, not destroying instances with a positive reference count). is that correct? And either way, is this in general a kosher way of handling complex filterFunctions that need access to multiple Models?

Thanks for any input.


  1. Support Staff 1 Posted by Shaun Smith on 02 Jul, 2012 10:51 PM

    Shaun Smith's Avatar

    Hi Peter,

    Yup, the filterFunction is keeping the command instance pinned in memory - normal Flash Player GC stuff. Robotlegs releases all internal references to commands after execution, but can't do anything about references that it didn't create.

    Personally, I don't mind the actual mechanics involved in your setup - but I would move that stuff out of the command and into an explicit persistent construct (like a service). Commands are supposed to be fire-and-forget, and the fact that this particular command persists is not being made clear. It doesn't reveal its intent.

    Hope that helps!

  2. 2 Posted by pdemling on 03 Jul, 2012 01:19 PM

    pdemling's Avatar

    Thanks for the reply, Shaun! That does clear things up.

    I've struggled with the best place for locating the filterFunction, since it needs to reference multiple (data-selection) Models, and its complex churning feels like business logic. That's why I initially went with Command; but I agree that the lack of clarity on its quirky persistence is not ideal. And I suppose injecting the (data-selection) Models into the Service is preferable to injecting them into the data-storage Model itself...

    As to getting a M's ArrayCollection to update in a V: after a one-time initialization of the V's instance by passing it in through the VM, is it normal/expected to see it automatically update, simply by calling refesh() on the M's ArrayCollection? I had thought I would have to explicitly pass it down (M to VM to V) on every update - but I'm seeing it happen without that effort. Again, I'm assuming this is because I initialized the V's instance with a reference to the M's instance; but I didn't know if this kind of "implicit update by reference" was considered loosely-coupled best-practice for a RL architecture.


  3. 3 Posted by pdemling on 03 Jul, 2012 06:05 PM

    pdemling's Avatar

    So I may have answered my own questions (but I'd be interested to hear if you have different design opinions):

    I located the complex filterFunction (that needs multiple injected Models) in a separate FilterFunctionService, injected that Service into my data-retrieval Service, and then called its setFilterFunction(myArrayCollectyion) method. So it now persists in a RL-expected way (in a Service). It is somewhat unusual (I think?) to inject a Service into a Service; but it seemed sensible for this purpose, and also has the advantage of being reusable by other data-retrieval Services in the app.

    As to getting a M's ArrayCollection to update in a V, I have the VM listen for a "model initialized" event, and do a one-time setting of V.dataSource = M.dataSource. Updates then automatically happen whenever I call M.dataSource.refresh(), and I can optionally have the VM listen for a "model refreshed" event if I need to invoke any additional view-specific refreshing.

    Thanks again for the assistance! Again, really loving working with the framework (and hoping it helps us extend the viability of Flash/Flex in the enterprise against the tidal wave of HTML5).


  4. Ondina D.F. closed this discussion on 16 Jul, 2012 08:32 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac