Created
March 11, 2011 15:17
-
-
Save mewdriller/865999 to your computer and use it in GitHub Desktop.
Robotlegs utility similar to EventMap to help automagically remove bindings in a Mediator's preRemove logic.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.clutch.robotlegs | |
{ | |
import mx.binding.utils.BindingUtils; | |
import mx.binding.utils.ChangeWatcher; | |
public class BindingMap implements IBindingMap | |
{ | |
private var _bindings:Vector.<ChangeWatcher> = new Vector.<ChangeWatcher>(); | |
public function BindingMap() | |
{ | |
} | |
public function mapPropertyBind(site:Object, prop:String, host:Object, chain:Object, commitOnly:Boolean = false, useWeakReference:Boolean = true):ChangeWatcher | |
{ | |
// Create the binding as usual. | |
var cw:ChangeWatcher = BindingUtils.bindProperty(site, prop, host, chain, commitOnly, useWeakReference); | |
// Store the binding. | |
_bindings.push(cw); | |
// Return the reference. | |
return cw; | |
} | |
public function mapSetterBind(setter:Function, host:Object, chain:Object, commitOnly:Boolean = false, useWeakReference:Boolean = true):ChangeWatcher | |
{ | |
// Create the binding as usual. | |
var cw:ChangeWatcher = BindingUtils.bindSetter(setter, host, chain, commitOnly, useWeakReference); | |
// Store the binding. | |
_bindings.push(cw); | |
// Return the reference. | |
return cw; | |
} | |
public function mapWatch(host:Object, chain:Object, handler:Function, commitOnly:Boolean = false, useWeakReference:Boolean = true):ChangeWatcher | |
{ | |
// Create the binding as usual. | |
var cw:ChangeWatcher = ChangeWatcher.watch(host, chain, handler, commitOnly, useWeakReference); | |
// Store the binding. | |
_bindings.push(cw); | |
// Return the reference. | |
return cw; | |
} | |
public function unmapBindings():void | |
{ | |
// Go through each of the bindings: | |
while (_bindings.length > 0) | |
{ | |
// Remove the reference and kill the binding. | |
_bindings.pop().unwatch(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment