This is an automated email from the ASF dual-hosted git repository.
gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new f541fa6 Fix for Issue #639 - limit use of ItemRendererSimpleBinding
to when it could work, improve SimpleBinding to handle non-valueChange cases,
which supports dataChange. Add fallback to GenericBinding Small update in TDJ
for renderer demo.
f541fa6 is described below
commit f541fa684366f27ca9af1368c58e7cf2794bf900
Author: greg-dove <[email protected]>
AuthorDate: Thu Jul 2 16:24:40 2020 +1200
Fix for Issue #639 - limit use of ItemRendererSimpleBinding to when it
could work, improve SimpleBinding to handle non-valueChange cases, which
supports dataChange. Add fallback to GenericBinding
Small update in TDJ for renderer demo.
---
.../royale/itemRenderers/AdvancedIconListItemRenderer.mxml | 11 ++++++++---
.../org/apache/royale/binding/ItemRendererDataBinding.as | 14 ++++++++++----
.../main/royale/org/apache/royale/binding/SimpleBinding.as | 14 +++++++++++---
3 files changed, 29 insertions(+), 10 deletions(-)
diff --git
a/examples/jewel/TourDeJewel/src/main/royale/itemRenderers/AdvancedIconListItemRenderer.mxml
b/examples/jewel/TourDeJewel/src/main/royale/itemRenderers/AdvancedIconListItemRenderer.mxml
index 7eea4ea..a7329e3 100644
---
a/examples/jewel/TourDeJewel/src/main/royale/itemRenderers/AdvancedIconListItemRenderer.mxml
+++
b/examples/jewel/TourDeJewel/src/main/royale/itemRenderers/AdvancedIconListItemRenderer.mxml
@@ -42,7 +42,7 @@ limitations under the License.
return getItemClassname(item)
}
- private function clickCloseButton():void
+ private function mutateData():void
{
var view:ListView = this.itemRendererOwnerView as ListView;
if (view) {
@@ -52,8 +52,13 @@ limitations under the License.
if (collection) {
iconListItem.componentSet =
(iconListItem.componentSet == 'Jewel') ? 'Basic' : 'Jewel';
collection.itemUpdated(iconListItem);
+ //fake a dataChange to force update the colorClass
of this renderer
+ dispatchEvent(new Event('dataChange'))
+ }
+ if (host.selectedItem == data) {
+ //fake a selectionChange to trigger selection
level bindings
+ host.dispatchEvent(new Event('selectionChanged'));
}
- //(host.dataProvider as ArrayList).removeItemAt(index);
}
}
}
@@ -89,7 +94,7 @@ limitations under the License.
<js:MaterialIcon text="{iconListItem.icon}"
visible="{iconListItem.icon != null}"
className="{colorClass}"
- click="clickCloseButton()"/>
+ click="mutateData()"/>
<j:Label html="{text}" multiline="true"/>
diff --git
a/frameworks/projects/Binding/src/main/royale/org/apache/royale/binding/ItemRendererDataBinding.as
b/frameworks/projects/Binding/src/main/royale/org/apache/royale/binding/ItemRendererDataBinding.as
index 19ad524..ac7d0b6 100644
---
a/frameworks/projects/Binding/src/main/royale/org/apache/royale/binding/ItemRendererDataBinding.as
+++
b/frameworks/projects/Binding/src/main/royale/org/apache/royale/binding/ItemRendererDataBinding.as
@@ -65,7 +65,7 @@ package org.apache.royale.binding
override protected function processBindingData(bindingData:Array,
first:int):void{
var fieldWatcher:Object;
var sb:SimpleBinding;
- var cb:ConstantBinding;
+
var binding:Object = null;
var n:int = bindingData[first];
var bindings:Array = [];
@@ -118,8 +118,9 @@ package org.apache.royale.binding
{
fieldWatcher =
compWatcher.children.watcherMap[binding.source[1]];
}
-
- if (compWatcher && fieldWatcher &&
+ //for ItemRendererSimpleBinding we only want single level
bindings via 'dataChange'
+ //because it only listens to top level 'dataChange', so
fieldWatcher should be null here:
+ if (compWatcher && !fieldWatcher &&
(binding.source[0] == "data" ||
(compWatcher.eventNames is String &&
compWatcher.eventNames ==
"dataChange")))
@@ -131,12 +132,15 @@ package org.apache.royale.binding
irsb.setDocument(_strand);
_strand.addBead(irsb);
}
- else if (fieldWatcher != null && fieldWatcher.eventNames
is String)
+ else if (fieldWatcher != null
+ && fieldWatcher.eventNames is String
+ && compWatcher.eventNames is String)
{
sb = new SimpleBinding();
sb.destinationPropertyName = binding.destination[1];
sb.eventName = fieldWatcher.eventNames as String;
sb.sourceID = binding.source[0];
+ sb.setSourceEventName(compWatcher.eventNames as
String);
sb.sourcePropertyName = binding.source[1];
sb.setDocument(_strand);
@@ -145,6 +149,8 @@ package org.apache.royale.binding
else if (fieldWatcher == null || fieldWatcher.eventNames
== null)
{
makeConstantBinding(binding);
+ } else {
+ makeGenericBinding(binding, i, watchers);
}
}
else
diff --git
a/frameworks/projects/Binding/src/main/royale/org/apache/royale/binding/SimpleBinding.as
b/frameworks/projects/Binding/src/main/royale/org/apache/royale/binding/SimpleBinding.as
index d17d146..d7dfe15 100644
---
a/frameworks/projects/Binding/src/main/royale/org/apache/royale/binding/SimpleBinding.as
+++
b/frameworks/projects/Binding/src/main/royale/org/apache/royale/binding/SimpleBinding.as
@@ -153,6 +153,11 @@ public class SimpleBinding implements IBead, IDocument,
IBinding
_sourceID = value;
}
+ private var _sourceEventName:String = 'valueChange';
+ public function setSourceEventName(eventName:String):void{
+ _sourceEventName = eventName;
+ }
+
/**
* @copy org.apache.royale.core.IBinding#destinationPropertyName
*
@@ -189,6 +194,8 @@ public class SimpleBinding implements IBead, IDocument,
IBinding
_sourcePropertyName = value;
}
+
+
/**
* @copy org.apache.royale.core.IBead#strand
*
@@ -210,7 +217,7 @@ public class SimpleBinding implements IBead, IDocument,
IBinding
if (sourceID != null)
{
source = dispatcher = document[sourceID] as
IEventDispatcher;
- document.addEventListener("valueChange",
sourceChangeHandler);
+ document.addEventListener(_sourceEventName,
sourceChangeHandler);
if (source == null)
{
return;
@@ -259,10 +266,11 @@ public class SimpleBinding implements IBead, IDocument,
IBinding
/**
* @royaleignorecoercion org.apache.royale.events.IEventDispatcher
+ * @royaleignorecoercion org.apache.royale.events.ValueChangeEvent
*/
- private function sourceChangeHandler(event:ValueChangeEvent):void
+ private function sourceChangeHandler(event:/*ValueChange*/Event):void
{
- if (event.propertyName != sourceID)
+ if (event.type == ValueChangeEvent.VALUE_CHANGE && (event as
ValueChangeEvent).propertyName != sourceID)
return;
if (dispatcher)