FYI: The pattern of MyClass(myObject) will always produce JS code which calls Language.as which throws an RTE if the object cannot be coerced as the class. Using compiler options to ignore coercion has no effect on this case.
Most of the time, this is not what’s needed. Generally a better pattern is (myObject as MyClass). This will produce JS code which calls Language.as unless coercion is ignored in which case the cast is simply dropped and more efficient JS code is used. There are a number of casts to IEventDispatcher and UIBase which should probably be redone. Thanks, Harbs > On Aug 24, 2017, at 12:53 AM, pio...@apache.org wrote: > > FLEX-35354 - Rename TabsItemRendererFactoryForArrayListData to > TabsDynamicItemsRendererFactoryForArrayListData > - Update TabsDynamicItemsRendererFactoryForArrayListData with new > implementation of DynamicItemsRendererFactoryForArrayListData > - Update example MDLDynamicTabsExample > > > Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo > Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/5b8f1c58 > Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/5b8f1c58 > Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/5b8f1c58 > > Branch: refs/heads/develop > Commit: 5b8f1c5898c776eb7470e855073833e68e794a6d > Parents: 56e467a > Author: piotrz <pio...@apache.org> > Authored: Wed Aug 23 23:53:09 2017 +0200 > Committer: piotrz <pio...@apache.org> > Committed: Wed Aug 23 23:53:09 2017 +0200 > > ---------------------------------------------------------------------- > .../src/main/flex/views/InitialView.mxml | 24 ++- > .../src/main/resources/mdl-styles.css | 2 +- > .../src/main/flex/MDLClasses.as | 2 +- > ...namicItemsRendererFactoryForArrayListData.as | 108 ++++++++++ > .../TabsItemRendererFactoryForArrayListData.as | 206 ------------------- > .../org/apache/flex/mdl/beads/views/TabsView.as | 6 +- > .../src/main/resources/defaults.css | 4 +- > 7 files changed, 129 insertions(+), 223 deletions(-) > ---------------------------------------------------------------------- > > > http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5b8f1c58/examples/flexjs/MDLDynamicTabsExample/src/main/flex/views/InitialView.mxml > ---------------------------------------------------------------------- > diff --git > a/examples/flexjs/MDLDynamicTabsExample/src/main/flex/views/InitialView.mxml > b/examples/flexjs/MDLDynamicTabsExample/src/main/flex/views/InitialView.mxml > index 5523b6f..1482982 100644 > --- > a/examples/flexjs/MDLDynamicTabsExample/src/main/flex/views/InitialView.mxml > +++ > b/examples/flexjs/MDLDynamicTabsExample/src/main/flex/views/InitialView.mxml > @@ -39,14 +39,18 @@ limitations under the License. > <mdl:model> > <models:TabsModel id="tabsModel"/> > </mdl:model> > - <mdl:Tabs id="myTabs" selectedIndex="1" tabIdField="tabId" > labelField="label" className="customTabs" > - dataProvider="{tabsModel.tabs}" width="500"> > - <mdl:beads> > - <js:DataProviderCollectionChangeNotifier > sourceID="tabsModel" propertyName="tabs" > - > destinationPropertyName="dataProvider" > changeEventName="dataProviderChanged" /> > - <js:DataProviderItemsChangeNotifier > sourceID="tabsModel" propertyName="tabs" > - > destinationPropertyName="dataProvider" > changeEventName="dataProviderChanged" /> > - </mdl:beads> > - </mdl:Tabs> > - <mdl:Button text="Add new Tab" click="onAddNewTabClick(event)"/> > + <mdl:GridCell column="6"> > + <mdl:Tabs id="myTabs" selectedIndex="1" tabIdField="tabId" > labelField="label" className="customTabs" > + dataProvider="{tabsModel.tabs}" width="500"> > + <mdl:beads> > + <js:DataProviderCollectionChangeNotifier > sourceID="tabsModel" propertyName="tabs" > + > destinationPropertyName="dataProvider" > changeEventName="dataProviderChanged" /> > + <js:DataProviderItemsChangeNotifier > sourceID="tabsModel" propertyName="tabs" > + > destinationPropertyName="dataProvider" > changeEventName="dataProviderChanged" /> > + </mdl:beads> > + </mdl:Tabs> > + </mdl:GridCell> > + <mdl:GridCell> > + <mdl:Button text="Add new Tab" click="onAddNewTabClick(event)"/> > + </mdl:GridCell> > </mdl:Grid> > \ No newline at end of file > > http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5b8f1c58/examples/flexjs/MDLDynamicTabsExample/src/main/resources/mdl-styles.css > ---------------------------------------------------------------------- > diff --git > a/examples/flexjs/MDLDynamicTabsExample/src/main/resources/mdl-styles.css > b/examples/flexjs/MDLDynamicTabsExample/src/main/resources/mdl-styles.css > index 8d52a54..e713389 100644 > --- a/examples/flexjs/MDLDynamicTabsExample/src/main/resources/mdl-styles.css > +++ b/examples/flexjs/MDLDynamicTabsExample/src/main/resources/mdl-styles.css > @@ -27,5 +27,5 @@ > { > IItemRenderer: > ClassReference("itemRenderers.CustomTabBarPanelItemRenderer"); > IBeadModel: > ClassReference("org.apache.flex.mdl.beads.models.TabArrayListModel"); > - IDataProviderItemRendererMapper: > ClassReference("org.apache.flex.mdl.beads.TabsItemRendererFactoryForArrayListData"); > + IDataProviderItemRendererMapper: > ClassReference("org.apache.flex.mdl.beads.TabsDynamicItemsRendererFactoryForArrayListData"); > } > \ No newline at end of file > > http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5b8f1c58/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as > ---------------------------------------------------------------------- > diff --git > a/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as > b/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as > index d9ac1ac..00ffe9d 100644 > --- a/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as > +++ b/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as > @@ -28,7 +28,7 @@ package > internal class MDLClasses > { > import > org.apache.flex.mdl.beads.TabsItemRendererFactoryForArrayData; > TabsItemRendererFactoryForArrayData; > - import > org.apache.flex.mdl.beads.TabsItemRendererFactoryForArrayListData; > TabsItemRendererFactoryForArrayListData; > + import > org.apache.flex.mdl.beads.TabsDynamicItemsRendererFactoryForArrayListData; > TabsDynamicItemsRendererFactoryForArrayListData; > import org.apache.flex.mdl.beads.models.TabArrayModel; > TabArrayModel; > import org.apache.flex.mdl.beads.models.TabArrayListModel; > TabArrayListModel; > import org.apache.flex.mdl.beads.models.ToastModel; ToastModel; > > http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5b8f1c58/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TabsDynamicItemsRendererFactoryForArrayListData.as > ---------------------------------------------------------------------- > diff --git > a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TabsDynamicItemsRendererFactoryForArrayListData.as > > b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TabsDynamicItemsRendererFactoryForArrayListData.as > new file mode 100644 > index 0000000..371f79b > --- /dev/null > +++ > b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TabsDynamicItemsRendererFactoryForArrayListData.as > @@ -0,0 +1,108 @@ > +//////////////////////////////////////////////////////////////////////////////// > +// > +// Licensed to the Apache Software Foundation (ASF) under one or more > +// contributor license agreements. See the NOTICE file distributed with > +// this work for additional information regarding copyright ownership. > +// The ASF licenses this file to You under the Apache License, Version 2.0 > +// (the "License"); you may not use this file except in compliance with > +// the License. You may obtain a copy of the License at > +// > +// http://www.apache.org/licenses/LICENSE-2.0 > +// > +// Unless required by applicable law or agreed to in writing, software > +// distributed under the License is distributed on an "AS IS" BASIS, > +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > +// See the License for the specific language governing permissions and > +// limitations under the License. > +// > +//////////////////////////////////////////////////////////////////////////////// > +package org.apache.flex.mdl.beads > +{ > + import org.apache.flex.collections.IArrayList; > + import org.apache.flex.core.IListPresentationModel; > + import org.apache.flex.events.CollectionEvent; > + > + import org.apache.flex.events.IEventDispatcher; > + import > org.apache.flex.html.beads.DynamicItemsRendererFactoryForArrayListData; > + import org.apache.flex.mdl.beads.models.ITabModel; > + import org.apache.flex.mdl.supportClasses.ITabItemRenderer; > + import org.apache.flex.events.Event; > + > + > [Event(name="itemRendererCreated",type="org.apache.flex.events.ItemRendererEvent")] > + > + /** > + * The TabsDynamicItemsRendererFactoryForArrayListData class reads an > + * array of data and creates an item renderer for every > + * ITabItemRenderer in the array. > + * > + * @langversion 3.0 > + * @playerversion Flash 10.2 > + * @playerversion AIR 2.6 > + * @productversion FlexJS 0.8 > + */ > + public class TabsDynamicItemsRendererFactoryForArrayListData extends > DynamicItemsRendererFactoryForArrayListData > + { > + public function > TabsDynamicItemsRendererFactoryForArrayListData(target:Object = null) > + { > + super(target); > + } > + > + protected var tabsIdField:String; > + > + /** > + * finish setup > + * > + * @langversion 3.0 > + * @playerversion Flash 10.2 > + * @playerversion AIR 2.6 > + * @productversion FlexJS 0.8 > + */ > + override protected function initComplete(event:Event):void > + { > + var model:ITabModel = _strand.getBeadByType(ITabModel) as > ITabModel; > + tabsIdField = model.tabIdField; > + > + super.initComplete(event); > + } > + > + override protected function > dataProviderChangeHandler(event:Event):void > + { > + var dp:IArrayList = dataProviderModel.dataProvider as IArrayList; > + if (!dp) > + return; > + > + dataGroup.removeAllItemRenderers(); > + > + var presentationModel:IListPresentationModel = > _strand.getBeadByType(IListPresentationModel) as IListPresentationModel; > + > + var n:int = dp.length; > + for (var i:int = 0; i < n; i++) > + { > + var ir:ITabItemRenderer = > itemRendererFactory.createItemRenderer(dataGroup) as ITabItemRenderer; > + ir.tabIdField = tabsIdField; > + > + var item:Object = dp.getItemAt(i); > + fillRenderer(i, item, ir, presentationModel); > + } > + > + IEventDispatcher(_strand).dispatchEvent(new > Event("itemsCreated")); > + } > + > + override protected function > itemAddedHandler(event:CollectionEvent):void > + { > + var dp:IArrayList = dataProviderModel.dataProvider as IArrayList; > + if (!dp) > + return; > + > + var presentationModel:IListPresentationModel = > _strand.getBeadByType(IListPresentationModel) as IListPresentationModel; > + > + var ir:ITabItemRenderer = > itemRendererFactory.createItemRenderer(dataGroup) as ITabItemRenderer; > + ir.tabIdField = tabsIdField; > + > + var index:int = dp.length - 1; > + fillRenderer(index, event.item, ir, presentationModel); > + > + IEventDispatcher(_strand).dispatchEvent(new > Event("itemsCreated")); > + } > + } > +} > > http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5b8f1c58/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TabsItemRendererFactoryForArrayListData.as > ---------------------------------------------------------------------- > diff --git > a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TabsItemRendererFactoryForArrayListData.as > > b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TabsItemRendererFactoryForArrayListData.as > deleted file mode 100644 > index c323332..0000000 > --- > a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TabsItemRendererFactoryForArrayListData.as > +++ /dev/null > @@ -1,206 +0,0 @@ > -//////////////////////////////////////////////////////////////////////////////// > -// > -// Licensed to the Apache Software Foundation (ASF) under one or more > -// contributor license agreements. See the NOTICE file distributed with > -// this work for additional information regarding copyright ownership. > -// The ASF licenses this file to You under the Apache License, Version 2.0 > -// (the "License"); you may not use this file except in compliance with > -// the License. You may obtain a copy of the License at > -// > -// http://www.apache.org/licenses/LICENSE-2.0 > -// > -// Unless required by applicable law or agreed to in writing, software > -// distributed under the License is distributed on an "AS IS" BASIS, > -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > -// See the License for the specific language governing permissions and > -// limitations under the License. > -// > -//////////////////////////////////////////////////////////////////////////////// > -package org.apache.flex.mdl.beads > -{ > - import org.apache.flex.collections.IArrayList; > - import org.apache.flex.core.IBead; > - import org.apache.flex.core.IDataProviderItemRendererMapper; > - import org.apache.flex.core.IItemRendererClassFactory; > - import org.apache.flex.core.IItemRendererParent; > - import org.apache.flex.core.IListPresentationModel; > - import org.apache.flex.core.IStrand; > - import org.apache.flex.core.SimpleCSSStyles; > - import org.apache.flex.core.UIBase; > - import org.apache.flex.core.ValuesManager; > - import org.apache.flex.events.CollectionEvent; > - > - import org.apache.flex.events.EventDispatcher; > - import org.apache.flex.events.IEventDispatcher; > - import org.apache.flex.html.beads.IListView; > - import org.apache.flex.mdl.beads.models.ITabModel; > - import org.apache.flex.mdl.supportClasses.ITabItemRenderer; > - import org.apache.flex.events.Event; > - > - > [Event(name="itemRendererCreated",type="org.apache.flex.events.ItemRendererEvent")] > - > - /** > - * The TabsItemRendererFactoryForArrayListData class reads an > - * array of data and creates an item renderer for every > - * ITabItemRenderer in the array. > - * > - * @langversion 3.0 > - * @playerversion Flash 10.2 > - * @playerversion AIR 2.6 > - * @productversion FlexJS 0.8 > - */ > - public class TabsItemRendererFactoryForArrayListData extends > EventDispatcher implements IBead, IDataProviderItemRendererMapper > - { > - public function > TabsItemRendererFactoryForArrayListData(target:Object = null) > - { > - super(target); > - } > - > - protected var dataProviderModel:ITabModel; > - > - protected var labelField:String; > - protected var tabsIdField:String; > - > - private var _strand:IStrand; > - > - /** > - * @copy org.apache.flex.core.IBead#strand > - * > - * @langversion 3.0 > - * @playerversion Flash 10.2 > - * @playerversion AIR 2.6 > - * @productversion FlexJS 0.8 > - */ > - public function set strand(value:IStrand):void > - { > - _strand = value; > - > IEventDispatcher(value).addEventListener("initComplete",finishSetup); > - } > - > - /** > - * finish setup > - * > - * @langversion 3.0 > - * @playerversion Flash 10.2 > - * @playerversion AIR 2.6 > - * @productversion FlexJS 0.8 > - */ > - private function finishSetup(event:Event):void > - { > - > IEventDispatcher(_strand).removeEventListener("initComplete",finishSetup); > - > - dataProviderModel = _strand.getBeadByType(ITabModel) as > ITabModel; > - var listView:IListView = _strand.getBeadByType(IListView) as > IListView; > - dataGroup = listView.dataGroup; > - dataProviderModel.addEventListener("dataProviderChanged", > dataProviderChangeHandler); > - dataProviderModel.addEventListener(CollectionEvent.ITEM_ADDED, > itemAddedHandler); > - > - tabsIdField = dataProviderModel.tabIdField; > - labelField = dataProviderModel.labelField; > - > - dataProviderChangeHandler(null); > - } > - > - private var _itemRendererFactory:IItemRendererClassFactory; > - > - /** > - * The org.apache.flex.core.IItemRendererClassFactory used > - * to generate instances of item renderers. > - * > - * @langversion 3.0 > - * @playerversion Flash 10.2 > - * @playerversion AIR 2.6 > - * @productversion FlexJS 0.8 > - */ > - public function get itemRendererFactory():IItemRendererClassFactory > - { > - if (_itemRendererFactory == null) { > - var factory:IItemRendererClassFactory = > _strand.getBeadByType(IItemRendererClassFactory) as IItemRendererClassFactory; > - if (factory == null) { > - factory = new > (ValuesManager.valuesImpl.getValue(_strand, "iItemRendererClassFactory")) as > IItemRendererClassFactory; > - _strand.addBead(factory); > - } > - _itemRendererFactory = factory; > - } > - return _itemRendererFactory; > - } > - > - /** > - * @private > - */ > - public function set > itemRendererFactory(value:IItemRendererClassFactory):void > - { > - _itemRendererFactory = value; > - } > - > - /** > - * The org.apache.flex.core.IItemRendererParent that will > - * parent the item renderers. > - * > - * @langversion 3.0 > - * @playerversion Flash 10.2 > - * @playerversion AIR 2.6 > - * @productversion FlexJS 0.8 > - */ > - protected var dataGroup:IItemRendererParent; > - > - protected function dataProviderChangeHandler(event:Event):void > - { > - var dp:IArrayList = dataProviderModel.dataProvider as IArrayList; > - if (!dp) > - return; > - > - dataGroup.removeAllItemRenderers(); > - > - var presentationModel:IListPresentationModel = > _strand.getBeadByType(IListPresentationModel) as IListPresentationModel; > - > - var n:int = dp.length; > - for (var i:int = 0; i < n; i++) > - { > - var ir:ITabItemRenderer = > itemRendererFactory.createItemRenderer(dataGroup) as ITabItemRenderer; > - dataGroup.addItemRenderer(ir); > - ir.index = i; > - ir.labelField = labelField; > - ir.tabIdField = tabsIdField; > - > - if (presentationModel) { > - var style:SimpleCSSStyles = new SimpleCSSStyles(); > - style.marginBottom = > presentationModel.separatorThickness; > - UIBase(ir).style = style; > - UIBase(ir).height = presentationModel.rowHeight; > - UIBase(ir).percentWidth = 100; > - } > - ir.data = dp.getItemAt(i); > - } > - > - IEventDispatcher(_strand).dispatchEvent(new > Event("itemsCreated")); > - } > - > - private function itemAddedHandler(event:CollectionEvent):void > - { > - var dp:IArrayList = dataProviderModel.dataProvider as IArrayList; > - if (!dp) > - return; > - > - var presentationModel:IListPresentationModel = > _strand.getBeadByType(IListPresentationModel) as IListPresentationModel; > - > - var ir:ITabItemRenderer = > itemRendererFactory.createItemRenderer(dataGroup) as ITabItemRenderer; > - dataGroup.addItemRenderer(ir); > - > - ir.index = dp.length - 1; > - ir.labelField = labelField; > - ir.tabIdField = tabsIdField; > - > - if (presentationModel) { > - var style:SimpleCSSStyles = new SimpleCSSStyles(); > - style.marginBottom = presentationModel.separatorThickness; > - UIBase(ir).style = style; > - UIBase(ir).height = presentationModel.rowHeight; > - UIBase(ir).percentWidth = 100; > - } > - ir.data = event.item; > - > - IEventDispatcher(_strand).dispatchEvent(new > Event("itemsCreated")); > - } > - } > -} > > http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5b8f1c58/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/TabsView.as > ---------------------------------------------------------------------- > diff --git > a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/TabsView.as > > b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/TabsView.as > index ffe291a..34c09f2 100644 > --- > a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/TabsView.as > +++ > b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/TabsView.as > @@ -26,7 +26,7 @@ package org.apache.flex.mdl.beads.views > import org.apache.flex.core.IStrand; > import org.apache.flex.mdl.TabBar; > import org.apache.flex.mdl.TabBarPanel; > - import org.apache.flex.mdl.beads.TabsItemRendererFactoryForArrayListData; > + import > org.apache.flex.mdl.beads.TabsDynamicItemsRendererFactoryForArrayListData; > import org.apache.flex.mdl.supportClasses.ITabItemRenderer; > > /** > @@ -166,8 +166,8 @@ package org.apache.flex.mdl.beads.views > > public function isTabsDynamic():Boolean > { > - var arrayListMapper:TabsItemRendererFactoryForArrayListData = > - _strand.getBeadByType(IDataProviderItemRendererMapper) > as TabsItemRendererFactoryForArrayListData; > + var > arrayListMapper:TabsDynamicItemsRendererFactoryForArrayListData = > + _strand.getBeadByType(IDataProviderItemRendererMapper) > as TabsDynamicItemsRendererFactoryForArrayListData; > return arrayListMapper != null; > } > } > > http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5b8f1c58/frameworks/projects/MaterialDesignLite/src/main/resources/defaults.css > ---------------------------------------------------------------------- > diff --git > a/frameworks/projects/MaterialDesignLite/src/main/resources/defaults.css > b/frameworks/projects/MaterialDesignLite/src/main/resources/defaults.css > index f8b3b05..9e5ece7 100644 > --- a/frameworks/projects/MaterialDesignLite/src/main/resources/defaults.css > +++ b/frameworks/projects/MaterialDesignLite/src/main/resources/defaults.css > @@ -122,7 +122,7 @@ Tabs > IBeadView: ClassReference("org.apache.flex.mdl.beads.views.TabsView"); > IBeadModel: > ClassReference("org.apache.flex.mdl.beads.models.TabArrayModel"); > IBeadLayout: ClassReference(null); > - IDataProviderItemRendererMapper: > ClassReference("org.apache.flex.mdl.beads.TabsItemRendererFactoryForArrayListData"); > + IDataProviderItemRendererMapper: > ClassReference("org.apache.flex.mdl.beads.TabsDynamicItemsRendererFactoryForArrayListData"); > IItemRendererClassFactory: > ClassReference("org.apache.flex.core.ItemRendererClassFactory"); > IItemRenderer: > ClassReference("org.apache.flex.mdl.itemRenderers.TabBarPanelItemRenderer"); > } > @@ -132,7 +132,7 @@ TabBar > IBeadView: ClassReference("org.apache.flex.mdl.beads.views.TabBarView"); > IBeadModel: > ClassReference("org.apache.flex.mdl.beads.models.TabArrayModel"); > IBeadLayout: ClassReference(null); > - IDataProviderItemRendererMapper: > ClassReference("org.apache.flex.mdl.beads.TabsItemRendererFactoryForArrayListData"); > + IDataProviderItemRendererMapper: > ClassReference("org.apache.flex.mdl.beads.TabsDynamicItemsRendererFactoryForArrayListData"); > IItemRendererClassFactory: > ClassReference("org.apache.flex.core.ItemRendererClassFactory"); > IItemRenderer: > ClassReference("org.apache.flex.mdl.itemRenderers.TabBarButtonTabsItemRenderer"); > } >