Skip to content

Instantly share code, notes, and snippets.

@mewdriller
Created March 11, 2011 15:17
Show Gist options
  • Save mewdriller/865999 to your computer and use it in GitHub Desktop.
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.
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