handle source changes
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/1a83e200 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/1a83e200 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/1a83e200 Branch: refs/heads/develop Commit: 1a83e200b33d172818bc0c3eb52da1b52ec2adf9 Parents: 17505db Author: Alex Harui <[email protected]> Authored: Tue Oct 28 09:43:33 2014 -0700 Committer: Alex Harui <[email protected]> Committed: Wed Oct 29 11:15:42 2014 -0700 ---------------------------------------------------------------------- .../org/apache/flex/binding/SimpleBinding.as | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1a83e200/frameworks/as/projects/FlexJSUI/src/org/apache/flex/binding/SimpleBinding.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/binding/SimpleBinding.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/binding/SimpleBinding.as index 6b169f2..7bd82b7 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/binding/SimpleBinding.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/binding/SimpleBinding.as @@ -24,6 +24,7 @@ package org.apache.flex.binding import org.apache.flex.core.IBead; import org.apache.flex.core.IStrand; import org.apache.flex.core.IDocument; + import org.apache.flex.events.ValueChangeEvent; /** * The SimpleBinding class is lightweight data-binding class that @@ -144,7 +145,15 @@ package org.apache.flex.binding if (destination == null) destination = value; if (sourceID != null) + { source = document[sourceID] as IEventDispatcher; + if (source == null) + { + document.addEventListener("valueChange", + sourceChangeHandler); + return; + } + } else source = document as IEventDispatcher; source.addEventListener(eventName, changeHandler); @@ -168,5 +177,21 @@ package org.apache.flex.binding { destination[destinationPropertyName] = source[sourcePropertyName]; } + + private function sourceChangeHandler(event:ValueChangeEvent):void + { + if (event.propertyName != sourceID) + return; + + if (source) + source.removeEventListener(eventName, changeHandler); + + source = document[sourceID] as IEventDispatcher; + if (source) + { + source.addEventListener(eventName, changeHandler); + destination[destinationPropertyName] = source[sourcePropertyName]; + } + } } } \ No newline at end of file
