Browse files

Totally revamped everything to be based on the new bifff... starting …

…changing projects
  • Loading branch information...
1 parent 30483f6 commit bcb22f4c82c903c326531c21d1457b566bc18484 @seanhess committed May 2, 2009
View
4 examples/FlickrBook/src/flickr/glue/MainGlue.mxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<GlueMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://glue.seanhess.net/2009" xmlns:views="flickr.ui.views.*" xmlns:business="flickr.business.*" xmlns:service="flickr.service.*" xmlns:model="flickr.model.*" xmlns:control="flickr.control.*">
+<Controller xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://glue.seanhess.net/2009" xmlns:views="flickr.ui.views.*" xmlns:business="flickr.business.*" xmlns:service="flickr.service.*" xmlns:model="flickr.model.*" xmlns:control="flickr.control.*">
<mx:Script>
<![CDATA[
@@ -46,4 +46,4 @@
<Inject currentSet="{photos.currentSet}"/>
</Glue>
-</GlueMap>
+</Controller>
View
4 examples/GlueLoginExample/src/login/control/MainGlue.mxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<GlueMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://glue.seanhess.net/2009" xmlns:control="login.control.*" xmlns:service="login.service.*" xmlns:view="login.view.*" xmlns:model="login.model.*">
+<Controller xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://glue.seanhess.net/2009" xmlns:control="login.control.*" xmlns:service="login.service.*" xmlns:view="login.view.*" xmlns:model="login.model.*">
<mx:Script>
<![CDATA[
@@ -35,4 +35,4 @@
<Route event="{Login.LOGOUT}" call="auth.logout()"/>
</Glue>
-</GlueMap>
+</Controller>
View
3 examples/GlueLoginExample/src/login/view/MainView.mxml
@@ -3,12 +3,15 @@
<mx:Script>
<![CDATA[
+ import mx.controls.Button;
import login.model.Navigation;
import login.model.User;
[Bindable] public var user:User;
[Bindable] public var nav:Navigation;
+ public var myButton:Button = new Button();
+
private function onLoginClick():void
{
dispatchEvent(new Event(Login.LOGIN));
View
4 examples/Library/src/GlueLibrary.mxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:view="books.view.*" xmlns:glue="books.glue.*">
- <glue:MainGlue/>
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:view="books.view.*" xmlns:glue="books.glue.*" xmlns:control="books.control.*">
+ <control:MainGlue/>
<view:MainView verticalCenter="0" horizontalCenter="0"/>
</mx:Application>
View
48 ...ples/Library/src/books/glue/MainGlue.mxml → ...s/Library/src/books/control/MainGlue.mxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<GlueMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://glue.seanhess.net/2009" xmlns:control="books.control.*" xmlns:view="books.view.*" xmlns:browse="books.view.browse.*" xmlns:pages="books.view.pages.*">
+<Controller xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://glue.seanhess.net/2009" xmlns:control="books.control.*" xmlns:view="books.view.*" xmlns:browse="books.view.browse.*" xmlns:pages="books.view.pages.*" xmlns:model="books.model.*">
<mx:Script>
<![CDATA[
@@ -8,37 +8,7 @@
]]>
</mx:Script>
-
-
-
-
-
-
-
-
- <!--
- CONTROLLERS
-
- Controllers should be specified as the first child of the Glue
- tag. This automatically sets the controller property for you.
- Alternatively, you can specify the controller elsewhere, and
- write <Glue controller="{myController}"/>. If you put a
- controller as the first parameter, it actually creates it and
- uses it, unlike views (see below).
-
- Note that I created a glue for library even though
- I didn't define any rules. I'm just doing this for consistency
-
- Browse and search use the inject tags to pull their books
- and authors lists from the library.
-
- BEST PRACTICE: Only specify injections and observes that set or
- call something on the controller in question.
- -->
-
- <Glue>
- <control:Library id="library"/>
- </Glue>
+ <model:Library id="library"/>
<Glue>
<control:Browse id="browse"/>
@@ -141,13 +111,13 @@
<Route child="{pages.back}" event="click" call="browse.goBack()"/>
- <Observe controller="{browse}" event="goBack" call="pages.goBack()"/>
- <Observe controller="{browse}" event="showSearch" call="pages.showSearch()"/>
- <Observe controller="{browse}" event="showBrowse" call="pages.showBrowse()"/>
- <Observe controller="{browse}" event="showBook" call="pages.showBook()"/>
- <Observe controller="{browse}" event="showAuthor" call="pages.showAuthor()"/>
+ <Observe model="{browse}" event="goBack" call="pages.goBack()"/>
+ <Observe model="{browse}" event="showSearch" call="pages.showSearch()"/>
+ <Observe model="{browse}" event="showBrowse" call="pages.showBrowse()"/>
+ <Observe model="{browse}" event="showBook" call="pages.showBook()"/>
+ <Observe model="{browse}" event="showAuthor" call="pages.showAuthor()"/>
- <Observe controller="{search}" event="search" call="pages.showSearchResults()"/>
+ <Observe model="{search}" event="search" call="pages.showSearchResults()"/>
</Glue>
<Glue>
@@ -176,4 +146,4 @@
<Route child="{searchView.searchBtn}" event="click" call="search.search(searchView.input.text)"/>
</Glue>
-</GlueMap>
+</Controller>
View
2 ...ples/Library/src/books/control/Library.as → examples/Library/src/books/model/Library.as
@@ -1,4 +1,4 @@
-package books.control
+package books.model
{
import books.model.mock.MockData;
View
BIN source/libs/Bifff0.3.i.swc
Binary file not shown.
View
3 source/src/manifest.xml
@@ -5,7 +5,6 @@
<component class="net.seanhess.glue.IGlueAction"/>
<component class="net.seanhess.glue.Observe"/>
<component class="net.seanhess.glue.Respond"/>
- <component class="net.seanhess.glue.Smart"/>
- <component class="net.seanhess.glue.GlueMap"/>
+ <component class="net.seanhess.glue.Controller"/>
<component class="net.seanhess.glue.Route"/>
</componentPackage>
View
54 source/src/net/seanhess/glue/Controller.as
@@ -0,0 +1,54 @@
+package net.seanhess.glue
+{
+ import flash.events.Event;
+
+ import net.seanhess.bifff.core.BehaviorMap;
+ import net.seanhess.bifff.core.ISelector;
+ import net.seanhess.bifff.utils.Debug;
+
+ /**
+ * So, how do I know when to actually execute? (Timer .... )
+ */
+ public class Controller extends BehaviorMap
+ {
+ override protected function initializeSelector(selector:ISelector):void
+ {
+ super.initializeSelector(selector);
+
+ if (selector is Glue)
+ {
+ var glue:Glue = selector as Glue;
+ glue.addEventListener(Glue.INITIALIZED, onGlueInitialized, false, 0, true);
+ glue.addEventListener(Glue.INSTANCE_CHANGE, onGlueInstanceChanged, false, 0, true);
+ }
+ }
+
+ private function onGlueInitialized(event:Event):void
+ {
+ var glue:Glue = event.target as Glue;
+ matchedSelector(glue.target, glue);
+ }
+
+ private function onGlueInstanceChanged(event:Event):void
+ {
+ var glue:Glue = event.target as Glue;
+ setCurrentInstance(glue.viewID, glue.currentInstance);
+ }
+
+ public function setCurrentInstance(viewID:String, view:*):void
+ {
+ if (this.hasOwnProperty(viewID))
+ this[viewID] = view;
+
+ else
+ throw new Error("Could not set current view instance: " + viewID + " to " + view + " on " + this);
+ }
+
+ override protected function commit():void
+ {
+ super.commit();
+ this.executor = new GlueExecutor();
+ Debug.instance.log("[ √ ] Project on " + target);
+ }
+ }
+}
View
95 source/src/net/seanhess/glue/Glue.as
@@ -1,37 +1,26 @@
package net.seanhess.glue
{
- import flash.events.IEventDispatcher;
+ import flash.events.Event;
import flash.utils.getQualifiedClassName;
import mx.core.UIComponent;
- import net.seanhess.bifff.core.BehaviorMap;
+ import net.seanhess.bifff.core.Node;
import net.seanhess.bifff.core.Selector;
- import net.seanhess.bifff.events.CreationComplete;
- import net.seanhess.bifff.scope.Scope;
import net.seanhess.bifff.utils.Invalidator;
[DefaultProperty("stuff")]
public class Glue extends Selector
{
- public var _controller:*;
- private var _controllerClass:String;
- private var mapTarget:IEventDispatcher;
- private var map:BehaviorMap;
- private var invalidator:Invalidator = new Invalidator(commit);
- private var viewID:String
+ public static const INITIALIZED:String = "initialized";
+ public static const INSTANCE_CHANGE:String = "currentInstanceChange";
- public function set find(value:String):void
- {
- this.match = value;
- }
+ private var _target:*;
+ private var _targetClass:String;
+ private var invalidator:Invalidator = new Invalidator(commit);
+ public var viewID:String
- public function set controller(value:*):void
- {
- _controller = value;
- var name:String = getQualifiedClassName(value);
- _controllerClass = name;
- }
+ public var currentInstance:*;
/**
* If you set the view, Glue will replace the instance in the map
@@ -44,56 +33,59 @@ package net.seanhess.glue
this.match = this.match || value.className;
}
+ /**
+ * You can set to a view class or a non-view class. This acts very
+ * differently depending on which one it is. If it is a view class
+ * (determined by whether it has properties similar to UIComponent)
+ * then it will set the match values appropriately and wait for it
+ * to show up in the behavior map
+ */
public function set target(value:*):void
{
if (value.hasOwnProperty("id") && value.hasOwnProperty("className")) // dynamic UIComponent...
view = value;
+
else
- controller = value;
+ {
+ _target = value;
+ var name:String = getQualifiedClassName(value);
+ _targetClass = name;
+ invalidator.invalidate("target");
+ nodes = [new Node(Node.NONE)];
+ }
}
- public function setCurrentInstance(view:*):void
+ public function get target():*
{
- if (viewID)
- (map as GlueMap).setCurrentInstance(viewID, view);
+ return _target;
}
- override public function matches(target:*, root:*=null):Boolean
+ public function setCurrentInstance(view:*):void
{
- if (_controller)
- {
- var targetClass:String = getQualifiedClassName(target);
- return (targetClass == _controllerClass);
- }
- else if (match)
- {
- var matches:Boolean = super.matches(target, root);
-
- if (matches)
- setCurrentInstance(target);
- return matches;
- }
- else
+ if (viewID)
{
- throw new Error("Could not find target for glue: "+this+". Make sure target is set as an attribute, or as the first child");
+ currentInstance = view;
+ dispatchEvent(new Event(INSTANCE_CHANGE));
}
}
- override public function set parent(value:Scope):void
+ override public function matches(target:*, root:*=null):Boolean
{
- super.parent = value;
- mapTarget = value.mapTarget; // woot! //
- map = value.map;
- invalidator.invalidate("parent");
+ var matches:Boolean = super.matches(target, root);
+
+ if (matches)
+ setCurrentInstance(target);
+
+ return matches;
}
+ /**
+ * Dispatch an initialized event, saying all our properties are set
+ */
protected function commit():void
{
- if (_controller)
- {
- var event:CreationComplete = new CreationComplete(_controller);
- mapTarget.dispatchEvent(event);
- }
+ if (_target && actions && invalidator.invalid("target"))
+ dispatchEvent(new Event(INITIALIZED));
}
[ArrayElementType("Object")]
@@ -102,9 +94,10 @@ package net.seanhess.glue
if (value.length > 0 && !(value[0] is IGlueAction))
{
target = value.shift();
- }
+ }
actions = value;
+ invalidator.invalidate("target");
}
}
}
View
10 source/src/net/seanhess/glue/GlueExecutor.as
@@ -1,16 +1,18 @@
package net.seanhess.glue
{
import net.seanhess.bifff.core.Executor;
+ import net.seanhess.bifff.core.Scope;
public class GlueExecutor extends Executor
{
- override public function executeActions(target:*, actions:Array):void
+ override public function executeBehaviors(target:*, behaviors:Array, scope:Scope):void
{
- for each (var action:Object in actions)
+ for each (var behavior:* in behaviors)
{
- if (action is IGlueAction)
+ if (behavior is IGlueAction)
{
- (action as IGlueAction).apply(target);
+ setBehaviorParent(behavior, scope);
+ (behavior as IGlueAction).applyAction(target);
}
}
}
View
30 source/src/net/seanhess/glue/GlueMap.as
@@ -1,30 +0,0 @@
-package net.seanhess.glue
-{
- import net.seanhess.bifff.core.BehaviorMap;
- import net.seanhess.bifff.utils.Debug;
-
- /**
- * So, how do I know when to actually execute? (Timer .... )
- */
- public class GlueMap extends BehaviorMap
- {
- public var event:Smart = new Smart("event");
- public var item:Smart = new Smart("item");
-
- public function setCurrentInstance(viewID:String, view:*):void
- {
- if (this.hasOwnProperty(viewID))
- this[viewID] = view;
-
- else
- throw new Error("Could not set current view instance: " + viewID + " to " + view + " on " + this);
- }
-
- override protected function commit():void
- {
- super.commit();
- this.executor = new GlueExecutor();
- Debug.instance.log("[ √ ] Project on " + target);
- }
- }
-}
View
2 source/src/net/seanhess/glue/IGlueAction.as
@@ -2,6 +2,6 @@ package net.seanhess.glue
{
public interface IGlueAction
{
- function apply(target:*):void;
+ function applyAction(target:*):void;
}
}
View
70 source/src/net/seanhess/glue/Inject.as
@@ -1,47 +1,29 @@
package net.seanhess.glue
{
- import flash.utils.Proxy;
- import flash.utils.flash_proxy;
-
- import net.seanhess.bifff.scope.IScopeable;
- import net.seanhess.bifff.scope.Scope;
- import net.seanhess.bifff.utils.Debug;
- import net.seanhess.bifff.utils.Invalidator;
- import net.seanhess.bifff.utils.TargetRegistry;
+ import net.seanhess.bifff.behaviors.Set;
/**
* Injects properties into controllers and views from a controller.
*
* Usage: <Inject myProperty="{mycontroller.value}"/>
* Usage: <Inject child="{myView.list}" dataProvider="{mycontroller.list}"/>
*/
- dynamic public class Inject extends Proxy implements IGlueAction, IScopeable
+ dynamic public class Inject extends Set implements IGlueAction
{
- protected var values:Object = {};
- protected var updates:Object = {};
- protected var invalidator:Invalidator = new Invalidator(commit);
protected var _to:*;
- [Bindable] public var parent:Scope;
-
- public var enableDebug:Boolean = true;
-
- public var registry:TargetRegistry = new TargetRegistry(actuallyApply);
- public function apply(target:*):void
+ /**
+ * Don't set the style, just throw an error. this is for injection
+ * not for looks, dangit!
+ */
+ override protected function setStyleOnTarget(target:*, property:String, value:*):void
{
- if (_to) target = _to;
- registry.applyTargets(target);
+ throw new Error("Could not set property '"+property+"' on target '"+target+"' to value '"+value+"'");
}
- public function actuallyApply(target:*):void
+ public function applyAction(target:*):void
{
- if (enableDebug) debug.log("[ √ ] Inject - " + target);
-
- for (var property:String in values)
- {
- var value:* = values[property];
- updateProperty(target, property, value);
- }
+ this.target = _to || target;
}
/**
@@ -57,37 +39,5 @@ package net.seanhess.glue
{
_to = value;
}
-
- protected function updateProperty(target:*, property:String, value:*):void
- {
- try
- {
- target[property] = value;
- if (enableDebug) debug.log("[ -> ] Inject("+property+":"+value+") -> " + target);
- }
-
- catch (e:Error)
- {
- throw new Error("Could not inject property: '" + property + "' with value: '" + value + "' on target: '" + target + "'");
- }
- }
-
- override flash_proxy function setProperty(name:*, value:*):void {
- values[name] = value;
- updates[name] = true;
- invalidator.invalidate("updates");
- }
-
- protected function commit():void
- {
- for (var target:* in registry.map)
- for (var property:String in updates)
- updateProperty(target, property, values[property]);
- }
-
- public function get debug():Debug
- {
- return Debug.instance;
- }
}
}
View
80 source/src/net/seanhess/glue/Observe.as
@@ -1,12 +1,9 @@
package net.seanhess.glue
{
import flash.events.Event;
- import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
- import net.seanhess.bifff.scope.IScopeable;
- import net.seanhess.bifff.scope.Scope;
- import net.seanhess.bifff.utils.Debug;
+ import net.seanhess.bifff.behaviors.Listen;
/**
* Usage: <Observe controller="{myController}" event="eventType" call="me.doAction()"/>
@@ -15,73 +12,40 @@ package net.seanhess.glue
* your current view or controller.
*/
[Event(name="call", type="flash.events.Event")]
- public class Observe extends EventDispatcher implements IGlueAction, IScopeable
+ public class Observe extends Listen implements IGlueAction
{
- private var _on:IEventDispatcher;
- public var event:String;
- [Bindable] public var parent:Scope;
+ protected var on:IEventDispatcher;
- public var enableDebug:Boolean = true;
-
- public function apply(target:*):void
- {
- var dispatcher:IEventDispatcher = target as IEventDispatcher;
-
- if (on)
- {
- (parent.selector as Glue).setCurrentInstance(target);
- dispatcher = on;
- }
-
- if (enableDebug) debug.log("[ √ ] Observe("+event+") - " + dispatcher);
-
- if (dispatcher == null)
- throw new Error("Target was not IEventDispatcher: " + target);
-
- dispatcher.addEventListener(event, function(event:Event):void {
-
- (parent.selector as Glue).setCurrentInstance(target);
-
- var message:String = "[ -> ] Observe("+event.type+") - " + event.target;
-
- if (on)
- message += " -> " + (parent.selector as Glue);
-
- if (enableDebug) debug.log(message);
-
- var scope:Scope = new Scope();
- scope.item = target;
- scope.event = event;
- Smart.setScope(scope);
-
- dispatchEvent(new Event("call"));
-
- });
- }
-
- public function set controller(value:IEventDispatcher):void
+ public function applyAction(target:*):void
{
- _on = value;
+ this.target = target;
}
-
+
public function set model(value:IEventDispatcher):void
{
- _on = value;
+ on = value;
}
public function set service(value:IEventDispatcher):void
{
- _on = value;
+ on = value;
}
- public function get on():IEventDispatcher
+ override protected function getDispatcher(target:*):IEventDispatcher
{
- return _on;
- }
-
- public function get debug():Debug
- {
- return Debug.instance;
+ var dispatcher:IEventDispatcher;
+
+ if (on)
+ {
+ (parent.selector as Glue).setCurrentInstance(target);
+ dispatcher = on;
+ }
+ else
+ {
+ dispatcher = super.getDispatcher(target);
+ }
+
+ return dispatcher;
}
}
}
View
2 source/src/net/seanhess/glue/Route.as
@@ -22,7 +22,7 @@ package net.seanhess.glue
*/
public function set child(value:*):void
{
- this.controller = value;
+ on = value;
}
}
}
View
63 source/src/net/seanhess/glue/Smart.as
@@ -1,63 +0,0 @@
-package net.seanhess.glue
-{
- import flash.utils.Proxy;
- import flash.utils.flash_proxy;
-
- import mx.core.IMXMLObject;
-
-
- /**
- * I'm not sure I even need these any more, now that I'm using strong references
- * everywhere!
- */
- [Bindable]
- dynamic public class Smart extends Proxy implements IMXMLObject
- {
- protected var _source:*;
-
- protected static var scope:Object;
-
- public var type:String;
-
- public function Smart(type:String=null)
- {
- this.type = type;
- }
-
- public static function setScope(scope:Object):void
- {
- Smart.scope = scope;
- }
-
- public static function getScope():Object
- {
- return Smart.scope;
- }
-
- public function initialized(document:Object, id:String):void
- {
- type = id;
- }
-
- public function set source(value:*):void
- {
- _source = value;
- }
-
- public function get source():*
- {
- return (_source) ? _source : Smart.scope[type];
- }
-
- override flash_proxy function getProperty(name:*):*
- {
- return source[name];
- }
-
- override flash_proxy function callProperty(name:*, ... rest):*
- {
- var source:* = this.source;
- return (source[name] as Function).apply(source, rest);
- }
- }
-}

0 comments on commit bcb22f4

Please sign in to comment.