Initial POC of bead notification
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BeadBase.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BeadBase.as
new file mode 100644
index 0000000..8141d60
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BeadBase.as
@@ -0,0 +1,90 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.core
+{
+ public class BeadBase implements IBead
+ {
+ public function BeadBase()
+ {
+
+ }
+
+ /**
+ * The strand. Do not modify except
+ * via the strand setter. For reading only.
+ *
+ * Because Object.defineProperties in JS
+ * doesn't allow you to just override the setter
+ * (you have to override the getter as well even
+ * if it just calls the super getter) it is
+ * more efficient to expose this variable than
+ * have all of the layers of simple overrides.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ protected var _strand:IStrand;
+
+ /**
+ * Get the strand for this bead
+ *
+ * Override this for whatever else you need to do when
+ * being hooked to the Strand
+ *
+ * @copy org.apache.royale.core.IBead#strand
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+ }
+
+ /**
+ * Allows an IBead to declare what notifications it wants.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function listInterests():Array
+ {
+ return [];
+ }
+
+ /**
+ * Used by an IStrand to notify the bead.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function handleNotification(notification:INotification):void
+ {
+ // implement in sub-classes
+ }
+ }
+}
\ No newline at end of file
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BeadViewBase.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BeadViewBase.as
index 9d42a0c..c497159 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BeadViewBase.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BeadViewBase.as
@@ -30,7 +30,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class BeadViewBase extends EventDispatcher implements IBeadView
+ public class BeadViewBase extends BeadBase implements IBeadView
{
/**
* Constructor.
@@ -46,42 +46,6 @@
}
/**
- * The strand. Do not modify except
- * via the strand setter. For reading only.
- *
- * Because Object.defineProperties in JS
- * doesn't allow you to just override the setter
- * (you have to override the getter as well even
- * if it just calls the super getter) it is
- * more efficient to expose this variable than
- * have all of the layers of simple overrides.
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- protected var _strand:IStrand;
-
- /**
- * Get the strand for this bead
- *
- * Override this for whatever else you need to do when
- * being hooked to the Strand
- *
- * @copy org.apache.royale.core.IBead#strand
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- public function set strand(value:IStrand):void
- {
- _strand = value;
- }
-
- /**
* The host component.
*
* @langversion 3.0
@@ -94,5 +58,6 @@
{
return _strand as IUIBase;
}
+
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserResizeListener.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserResizeListener.as
index 5009148..bf115de 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserResizeListener.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserResizeListener.as
@@ -34,7 +34,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.8
*/
- public class BrowserResizeListener implements IBead
+ public class BrowserResizeListener extends BeadBase
{
/**
* Constructor.
@@ -97,7 +97,7 @@
* @productversion Royale 0.8
* @royaleignorecoercion org.apache.royale.core.IInitialViewApplication
*/
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
app = value as IInitialViewApplication;
COMPILE::SWF
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserScroller.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserScroller.as
index 65dfe30..53624d9 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserScroller.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserScroller.as
@@ -34,7 +34,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class BrowserScroller implements IBead
+ public class BrowserScroller extends BeadBase
{
/**
* Constructor.
@@ -58,13 +58,16 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
app = value as IInitialViewApplication;
- app.addEventListener("viewChanged", viewChangedHandler);
+ }
+ override public function listInterests():Array
+ {
+ return ["viewChanged"];
}
- private function viewChangedHandler(event:Event):void
+ override public function handleNotification(notification:INotification):void
{
COMPILE::SWF
{
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/CSSFontFaceBead.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/CSSFontFaceBead.as
index aceb53a..2878040 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/CSSFontFaceBead.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/CSSFontFaceBead.as
@@ -44,7 +44,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class CSSFontFaceBead implements IBead
+ public class CSSFontFaceBead extends BeadBase
{
/**
* Constructor.
@@ -57,9 +57,7 @@
public function CSSFontFaceBead()
{
}
-
- private var _strand:IStrand;
-
+
/**
* @copy org.apache.royale.core.IBead#strand
*
@@ -68,7 +66,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
_strand = value;
COMPILE::SWF
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/CallLaterBead.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/CallLaterBead.as
index 0c0af79..eee25f1 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/CallLaterBead.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/CallLaterBead.as
@@ -23,7 +23,6 @@
import flash.events.Event;
}
- import org.apache.royale.core.IBead;
import org.apache.royale.core.IStrand;
/**
@@ -36,7 +35,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class CallLaterBead implements IBead
+ public class CallLaterBead extends BeadBase
{
/**
* Constructor.
@@ -50,22 +49,7 @@
{
super();
}
-
- private var _strand:IStrand;
-
- /**
- * @copy org.apache.royale.core.IBead#strand
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- public function set strand(value:IStrand):void
- {
- _strand = value;
- }
-
+
private var calls:Array;
/**
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ElementWrapper.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ElementWrapper.as
index 60a352c..88350b8 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ElementWrapper.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ElementWrapper.as
@@ -37,6 +37,9 @@
import org.apache.royale.events.Event;
import org.apache.royale.events.EventDispatcher;
+ import org.apache.royale.utils.beads.sendLookupNotifications;
+ import org.apache.royale.utils.beads.removeInterests;
+ import org.apache.royale.utils.beads.insertInterests;
COMPILE::SWF
public class ElementWrapper extends EventDispatcher implements IStrand
@@ -80,6 +83,7 @@
_beads.push(bead);
bead.strand = this;
+ insertInterests(beadLookup,bead);
}
/**
@@ -124,6 +128,7 @@
if (bead === value)
{
_beads.splice(i, 1);
+ removeInterests(beadLookup,bead);
return bead;
}
@@ -365,5 +370,37 @@
return source.dispatchEvent(e);
}
+
+ /**
+ * The beadLookup keeps references to beads using their notification interests
+ */
+ protected var beadLookup:Object = {};
+
+ /**
+ * Sends a notification instance.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function sendNotification(notification:INotification):void{
+ sendLookupNotifications(beadLookup,notification);
+ }
+
+ /**
+ * Simplified method for sending notifications.
+ * Use when body is not significant.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function notify(message:String):void{
+ var notification:INotification = new Notification(message);
+ sendNotification(notification);
+ }
+
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/EventLoggingBead.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/EventLoggingBead.as
index 7e30ac1..f0838be 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/EventLoggingBead.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/EventLoggingBead.as
@@ -41,7 +41,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class EventLoggingBead implements IBead
+ public class EventLoggingBead extends BeadBase
{
/**
* Constructor.
@@ -68,7 +68,7 @@
*
* @royaleignorecoercion org.apache.royale.events.IEventDispatcher
*/
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
_strand = value;
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/HTMLElementWrapper.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/HTMLElementWrapper.as
index 4ebff5a..65c3399 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/HTMLElementWrapper.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/HTMLElementWrapper.as
@@ -36,6 +36,9 @@
import goog.events.BrowserEvent;
import goog.events.EventTarget;
import org.apache.royale.events.utils.EventUtils;
+ import org.apache.royale.utils.beads.sendLookupNotifications;
+ import org.apache.royale.utils.beads.insertInterests;
+ import org.apache.royale.utils.beads.removeInterests;
}
COMPILE::SWF
@@ -192,6 +195,7 @@
}
bead.strand = this;
+ insertInterests(beadLookup,bead);
}
/**
@@ -236,6 +240,7 @@
if (bead === value)
{
_beads.splice(i, 1);
+ removeInterests(beadLookup,bead);
bead.strand = null;
return bead;
}
@@ -322,5 +327,36 @@
return goog.events.EventTarget.dispatchEventInternal_(source, e, ancestorsTree);
}
+ /**
+ * The beadLookup keeps references to beads using their notification interests
+ */
+ protected var beadLookup:Object = {};
+
+ /**
+ * Sends a notification instance.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function sendNotification(notification:INotification):void{
+ sendLookupNotifications(beadLookup,notification);
+ }
+
+ /**
+ * Simplified method for sending notifications.
+ * Use when body is not significant.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function notify(message:String):void{
+ var notification:INotification = new Notification(message);
+ sendNotification(notification);
+ }
+
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IBead.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IBead.as
index 72a6e60..f2ee8a9 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IBead.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IBead.as
@@ -42,6 +42,27 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- function set strand(value:IStrand):void
+ function set strand(value:IStrand):void;
+
+ /**
+ * Allows an IBead to declare what notifications it wants.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ function listInterests():Array;
+
+ /**
+ * Used by an IStrand to notify the bead.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ function handleNotification(notification:INotification):void;
+
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/INotification.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/INotification.as
new file mode 100644
index 0000000..758d488
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/INotification.as
@@ -0,0 +1,64 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.core
+{
+ /**
+ * The INotification interface is for notifications sent by IStrands to IBeads
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public interface INotification
+ {
+
+ /**
+ * The name of the notification (read only)
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ function get name():String;
+
+ /**
+ * The payload of the notification (if any)
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ function get body():Object;
+ function set body(value:Object):void;
+
+ /**
+ * The IBead who sent the notification (if applicable)
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ function get originator():IBead;
+ function set originator(value:IBead):void;
+ }
+}
\ No newline at end of file
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IStrand.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IStrand.as
index c8832eb..4190610 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IStrand.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IStrand.as
@@ -72,6 +72,27 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- function removeBead(bead:IBead):IBead;
+ function removeBead(bead:IBead):IBead;
+
+ /**
+ * Sends a notification instance.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ function sendNotification(notification:INotification):void;
+
+ /**
+ * Simplified method for sending notifications.
+ * Use when body is not significant.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ function notify(message:String):void;
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ITransformModel.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ITransformModel.as
index 3fac83d..fef2f4f 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ITransformModel.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ITransformModel.as
@@ -30,7 +30,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public interface ITransformModel extends IEventDispatcher, IBead
+ public interface ITransformModel extends IBead
{
/**
* The matrix of the Transform
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ItemRendererClassFactory.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ItemRendererClassFactory.as
index 6031bc9..7e34286 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ItemRendererClassFactory.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ItemRendererClassFactory.as
@@ -200,5 +200,14 @@
{
this.document = document;
}
+
+ public function listInterests():Array
+ {
+ return [];
+ }
+ public function handleNotification(notification:INotification):void
+ {
+
+ }
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/LayoutBase.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/LayoutBase.as
index 1ca0ffa..4b9d0d0 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/LayoutBase.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/LayoutBase.as
@@ -86,13 +86,35 @@
(value as IEventDispatcher).addEventListener("widthChanged", sizeChange);
(value as IEventDispatcher).addEventListener("heightChanged", sizeChange);
(value as IEventDispatcher).addEventListener("sizeChanged", sizeChange);
-
(value as IEventDispatcher).addEventListener("childrenAdded", handleChildrenAdded);
(value as IEventDispatcher).addEventListener("initComplete", handleInitComplete);
(value as IEventDispatcher).addEventListener("layoutNeeded", handleLayoutNeeded);
}
+ public function listInterests():Array
+ {
+ return ["widthChanged","heightChanged","sizeChanged","childrenAdded","initComplete","layoutNeeded"];
+ }
+ public function handleNotification(notification:INotification):void{
+ switch(notification.name)
+ {
+ case "widthChanged":
+ case "heightChanged":
+ case "sizeChanged":
+ handleSizeChange();
+ break;
+ case "childrenAdded":
+ handleChildrenAdded();
+ break;
+ case "initComplete":
+ handleInitComplete();
+ break;
+ case "layoutNeeded":
+ handleLayoutNeeded();
+ break;
+ }
+ }
private var lastWidth:Number = -1;
private var lastHeight:Number = -1;
@@ -106,7 +128,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.8
*/
- protected function handleSizeChange(event:Event):void
+ protected function handleSizeChange():void
{
if (host.width == lastWidth &&
host.height == lastHeight) return;
@@ -124,7 +146,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.8
*/
- protected function handleChildrenAdded(event:Event):void
+ protected function handleChildrenAdded():void
{
COMPILE::SWF {
if (sawInitComplete)
@@ -208,7 +230,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.8
*/
- protected function handleLayoutNeeded(event:Event):void
+ protected function handleLayoutNeeded():void
{
performLayout();
}
@@ -221,7 +243,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.8
*/
- protected function handleInitComplete(event:Event):void
+ protected function handleInitComplete():void
{
sawInitComplete = true;
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/MXMLDragInitiator.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/MXMLDragInitiator.as
index 87d7b81..ace4d6d 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/MXMLDragInitiator.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/MXMLDragInitiator.as
@@ -135,5 +135,29 @@
dispatchEvent(new Event("acceptedDrop"));
}
+ /**
+ * Allows an IBead to declare what notifications it wants.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function listInterests():Array
+ {
+ return [];
+ }
+
+ /**
+ * Used by an IStrand to notify the bead.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function handleNotification(notification:INotification):void
+ {
+ }
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/Notification.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/Notification.as
new file mode 100644
index 0000000..46a39e6
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/Notification.as
@@ -0,0 +1,59 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.core
+{
+ public class Notification implements INotification
+ {
+ public function Notification(name:String)
+ {
+ _name = name;
+ }
+
+ private var _name:String;
+
+ public function get name():String
+ {
+ return _name;
+ }
+
+ private var _body:Object;
+
+ public function get body():Object
+ {
+ return _body;
+ }
+
+ public function set body(value:Object):void
+ {
+ _body = value;
+ }
+
+ private var _originator:IBead;
+
+ public function get originator():IBead
+ {
+ return _originator;
+ }
+
+ public function set originator(value:IBead):void
+ {
+ _originator = value;
+ }
+ }
+}
\ No newline at end of file
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ParentDocumentBead.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ParentDocumentBead.as
index 76ffda1..59b4962 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ParentDocumentBead.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ParentDocumentBead.as
@@ -42,7 +42,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class ParentDocumentBead extends EventDispatcher implements IBead
+ public class ParentDocumentBead extends BeadBase
{
/**
* Constructor.
@@ -57,22 +57,8 @@
super();
}
- private var _strand:IStrand;
-
- /**
- * @copy org.apache.royale.core.IBead#strand
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- public function set strand(value:IStrand):void
- {
- _strand = value;
//TODO (aharui) watch for re-parenting
- }
private var _id:String;
@@ -97,7 +83,8 @@
if (_id != value)
{
_id = value;
- dispatchEvent(new org.apache.royale.events.Event("idChanged"));
+ //TODO harbs is this really necessary?
+ // dispatchEvent(new org.apache.royale.events.Event("idChanged"));
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleLocalizedValuesImpl.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleLocalizedValuesImpl.as
index 30bdcdf..7e80052 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleLocalizedValuesImpl.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleLocalizedValuesImpl.as
@@ -31,14 +31,13 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class SimpleLocalizedValuesImpl extends EventDispatcher implements ILocalizedValuesImpl
+ public class SimpleLocalizedValuesImpl extends BeadBase implements ILocalizedValuesImpl
{
public function SimpleLocalizedValuesImpl()
{
super();
}
- private var mainClass:Object;
private var locale:String;
/**
@@ -71,7 +70,7 @@
bundle = {};
bundles[actualBundleName] = bundle;
// go look for the bundle
- var data:String = mainClass[actualBundleName];
+ var data:String = _strand[actualBundleName];
var rows:Array = data.split("\n");
var n:int = rows.length;
for (var i:int = 0; i < n; i++)
@@ -101,18 +100,6 @@
locale = value;
}
- /**
- * @copy org.apache.royale.core.IBead#strand()
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- public function set strand(value:IStrand):void
- {
- this.mainClass = value;
- }
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleStatesImpl.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleStatesImpl.as
index 5c8f9ba..680e691 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleStatesImpl.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleStatesImpl.as
@@ -248,5 +248,29 @@
}
}
}
+ /**
+ * Allows an IBead to declare what notifications it wants.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function listInterests():Array
+ {
+ return [];
+ }
+
+ /**
+ * Used by an IStrand to notify the bead.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function handleNotification(notification:INotification):void
+ {
+ }
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/Strand.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/Strand.as
index a608762..5b72a6a 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/Strand.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/Strand.as
@@ -20,6 +20,9 @@
{
import org.apache.royale.events.Event;
import org.apache.royale.events.EventDispatcher;
+ import org.apache.royale.utils.beads.sendLookupNotifications;
+ import org.apache.royale.utils.beads.insertInterests;
+ import org.apache.royale.utils.beads.removeInterests;
/**
* The Strand class is the base class for non-display object
@@ -30,7 +33,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class Strand extends EventDispatcher implements IStrand
+ public class Strand implements IStrand
{
/**
* Constructor.
@@ -78,7 +81,7 @@
if (_model != value)
{
addBead(value as IBead);
- dispatchEvent(new Event("modelChanged"));
+ notify("modelChanged");
}
}
@@ -101,7 +104,7 @@
if (_id != value)
{
_id = value;
- dispatchEvent(new Event("idChanged"));
+ notify("idChanged");
}
}
@@ -140,6 +143,7 @@
if (bead is IBeadModel)
_model = bead as IBeadModel;
bead.strand = this;
+ insertInterests(beadLookup,bead);
}
/**
@@ -177,11 +181,42 @@
if (bead == value)
{
_beads.splice(i, 1);
+ removeInterests(beadLookup,bead);
return bead;
}
}
return null;
}
-
+
+ /**
+ * The beadLookup keeps references to beads using their notification interests
+ */
+ protected var beadLookup:Object = {};
+
+ /**
+ * Sends a notification instance.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function sendNotification(notification:INotification):void{
+ sendLookupNotifications(beadLookup,notification);
+ }
+
+ /**
+ * Simplified method for sending notifications.
+ * Use when body is not significant.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function notify(message:String):void{
+ var notification:INotification = new Notification(message);
+ sendNotification(notification);
+ }
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/StyleChangeNotifier.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/StyleChangeNotifier.as
index bc2bd0d..fee358d 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/StyleChangeNotifier.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/StyleChangeNotifier.as
@@ -35,7 +35,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public class StyleChangeNotifier implements IBead
+ public class StyleChangeNotifier extends BeadBase
{
private var _strand:IStrand;
@@ -49,7 +49,7 @@
* @royaleignorecoercion org.apache.royale.core.IStyleableObject
* @royaleignorecoercion org.apache.royale.events.IEventDispatcher
*/
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
_strand = value;
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/TransformBeadBase.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/TransformBeadBase.as
index 03b93fe..1c54efc 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/TransformBeadBase.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/TransformBeadBase.as
@@ -26,7 +26,7 @@
import flash.geom.Matrix;
}
- public class TransformBeadBase implements IBead
+ public class TransformBeadBase extends BeadBase
{
private var _strand:IStrand;
@@ -42,17 +42,23 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
_strand = value;
- host.addEventListener(TransformModel.CHANGE, changeHandler);
var model:ITransformModel = transformModel;
if (model && model.matrix)
{
transform();
}
}
-
+ override public function listInterests():Array
+ {
+ return [TransformModel.CHANGE];
+ }
+ override public function handleNotification(notification:INotification):void
+ {
+ transform();
+ }
public function get transformModel():ITransformModel
{
return host.getBeadByType(ITransformModel) as ITransformModel;
@@ -79,10 +85,6 @@
// implementors should override this
}
- private function changeHandler(e:Event):void
- {
- transform();
- }
/**
* The host component.
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/TransformModel.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/TransformModel.as
index d36ae5c..91fd5c3 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/TransformModel.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/TransformModel.as
@@ -22,13 +22,12 @@
import org.apache.royale.events.EventDispatcher;
import org.apache.royale.geom.Matrix;
- public class TransformModel extends EventDispatcher implements ITransformModel
+ public class TransformModel extends BeadBase implements ITransformModel
{
public static const CHANGE:String = "transferModelChange";
private var _matrix:Matrix;
- private var _strand:IStrand;
public function TransformModel()
{
@@ -39,9 +38,9 @@
return _matrix;
}
- private function dispatchModelChangeEvent():void
+ private function notifyChange():void
{
- host.dispatchEvent(new Event(CHANGE));
+ _strand.notify(CHANGE);
}
private function get host():ITransformHost
@@ -54,14 +53,14 @@
_matrix = value;
if (_strand)
{
- dispatchModelChangeEvent();
+ notifyChange();
}
}
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
_strand = value;
- dispatchModelChangeEvent();
+ notifyChange();
}
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/MixinManager.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/MixinManager.as
index f8b657e..5639229 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/MixinManager.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/MixinManager.as
@@ -29,6 +29,7 @@
import org.apache.royale.core.IBead;
import org.apache.royale.core.IFlexInfo;
import org.apache.royale.core.IStrand;
+import org.apache.royale.core.BeadBase;
/**
* The MixinManager class is the class that instantiates mixins
@@ -40,7 +41,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
-public class MixinManager implements IBead
+public class MixinManager extends BeadBase
{
/**
* Constructor.
@@ -54,9 +55,7 @@
{
super();
}
-
- private var _strand:IStrand;
-
+
/**
* @copy org.apache.royale.core.IBead#strand
*
@@ -68,7 +67,7 @@
* @royaleignorecoercion org.apache.royale.core.IFlexInfo
* @royaleignoreimport org.apache.royale.core.IFlexInfo
*/
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
_strand = value;
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/ViewSourceContextMenuOption.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/ViewSourceContextMenuOption.as
index 6e519a6..1d8cee4 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/ViewSourceContextMenuOption.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/ViewSourceContextMenuOption.as
@@ -32,6 +32,7 @@
import org.apache.royale.core.IInitialViewApplication;
import org.apache.royale.core.IBead;
import org.apache.royale.core.IStrand;
+import org.apache.royale.core.BeadBase;
/**
* The ViewSourceContextMenuOption class is a class that
@@ -44,7 +45,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
-public class ViewSourceContextMenuOption implements IBead
+public class ViewSourceContextMenuOption extends BeadBase
{
/**
* Constructor.
@@ -57,8 +58,6 @@
public function ViewSourceContextMenuOption()
{
}
-
- private var _strand:IStrand;
/**
* @copy org.apache.royale.core.UIBase#strand
@@ -68,7 +67,7 @@
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public function set strand(value:IStrand):void
+ override public function set strand(value:IStrand):void
{
_strand = value;
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/insertInterests.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/insertInterests.as
new file mode 100644
index 0000000..6541fc0
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/insertInterests.as
@@ -0,0 +1,44 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.utils.beads
+{
+ import org.apache.royale.core.IBead;
+
+ /**
+ * @royaleignorecoercion String
+ *
+ */
+ public function insertInterests(lookup:Object,bead:IBead):void
+ {
+ var interests:Array = bead.listInterests();
+ for(var i:int=0;i<interests.length;i++)
+ {
+ var interest:String = interests[i] as String;
+ if(lookup[interest])
+ {
+ lookup[interest].push(bead);
+ }
+ else
+ {
+ lookup[interest] = [bead];
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/removeInterests.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/removeInterests.as
new file mode 100644
index 0000000..7248558
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/removeInterests.as
@@ -0,0 +1,39 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.utils.beads
+{
+ import org.apache.royale.core.IBead;
+
+ /**
+ * @royaleignorecoercion String
+ *
+ */
+ public function removeInterests(lookup:Object,bead:IBead):void
+ {
+ var interests:Array = bead.listInterests();
+ for(var i:int=0;i<interests.length;i++)
+ {
+ var interestArr:Array = lookup[interests[i]];
+ var interest:String = interests[i] as String;
+ var index:int = interestArr.indexOf(bead);
+ interestArr.splice(index,1);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/sendLookupNotifications.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/sendLookupNotifications.as
new file mode 100644
index 0000000..2d379e7
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/beads/sendLookupNotifications.as
@@ -0,0 +1,37 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.utils.beads
+{
+ import org.apache.royale.core.INotification;
+ import org.apache.royale.core.IBead;
+
+ public function sendLookupNotifications(lookup:Object,notification:INotification):void
+ {
+ var beads:Array = lookup[notification.name];
+ if(beads)
+ {
+ for(var i:int=0;i<beads.length;i++)
+ {
+ var bead:IBead = beads[i];
+ bead.handleNotification(notification);
+ }
+ }
+
+ }
+}
\ No newline at end of file