diff --git a/bin/route.swc b/bin/route.swc new file mode 100644 index 0000000..904648d Binary files /dev/null and b/bin/route.swc differ diff --git a/src/eu/kiichigo/route/kore/Action.as b/src/eu/kiichigo/route/kore/Action.as new file mode 100644 index 0000000..72adba5 --- /dev/null +++ b/src/eu/kiichigo/route/kore/Action.as @@ -0,0 +1,77 @@ +package eu.kiichigo.route.kore +{ + import spark.skins.spark.mediaClasses.fullScreen.FullScreenButtonSkin; + + public class Action implements IAction, IGuard + { + /** + * @private + */ + protected var _route:IRoute; + /** + * @copy eu.kiichigo.route.kore.IAction#route + */ + public function get route():IRoute + { + return null; + } + /** + * @private + */ + public function set route(value:IRoute):void + { + _route = value; + } + + + /** + * @private + */ + protected var _predicate:Object; + /** + * @copy eu.kiichigo.route.kore.IGuard#predicate + */ + public function get predicate():Object + { + return _predicate; + } + /** + * + */ + public function set predicate(value:Object):void + { + _predicate = value; + } + + /** + * eu.kiichigo.route.kore.IAction#run + */ + public function run( percept:Object ):IAction + { + if( evaluate() ) + exec( percept ); + + return this; + } + + protected function evaluate():Boolean + { + if( _predicate === null ) + return true; + else if( _predicate is Function ) + return _predicate.call() as Boolean; + else if( _predicate is Boolean ) + return _predicate; + + return true; + } + + /** + * Override this method in subclassed, in order to implement functionality of a Action + */ + protected function exec( percept:Object ):void + { + + } + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IAction.as b/src/eu/kiichigo/route/kore/IAction.as new file mode 100644 index 0000000..787500b --- /dev/null +++ b/src/eu/kiichigo/route/kore/IAction.as @@ -0,0 +1,21 @@ +package eu.kiichigo.route.kore +{ + public interface IAction + { + /** + * Reference to the IRoute instance that's a parent to current IAction. + */ + function get route():IRoute; + /** + * @private + */ + function set route( value:IRoute ):void; + + /** + * Executes current IAction instance with percept received from the IRoute + * @param percept Object passed by IRoute. + * @return An instance of current IAction. + */ + function run( percept:Object ):IAction; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IActions.as b/src/eu/kiichigo/route/kore/IActions.as new file mode 100644 index 0000000..3f23f0b --- /dev/null +++ b/src/eu/kiichigo/route/kore/IActions.as @@ -0,0 +1,14 @@ +package eu.kiichigo.route.kore +{ + public interface IActions extends IAction + { + /** + * Collection (vector) of IAction instances that will be run once this IActions instance is executed. + */ + function get actions():Vector.; + /** + * + */ + function set actions( value:Vector. ):void; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IAgent.as b/src/eu/kiichigo/route/kore/IAgent.as new file mode 100644 index 0000000..e6bac47 --- /dev/null +++ b/src/eu/kiichigo/route/kore/IAgent.as @@ -0,0 +1,7 @@ +package eu.kiichigo.route.kore +{ + public interface IAgent + { + + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IAsyncAciton.as b/src/eu/kiichigo/route/kore/IAsyncAciton.as new file mode 100644 index 0000000..a03d636 --- /dev/null +++ b/src/eu/kiichigo/route/kore/IAsyncAciton.as @@ -0,0 +1,7 @@ +package eu.kiichigo.route.kore +{ + public interface IAsyncAciton + { + + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IGuard.as b/src/eu/kiichigo/route/kore/IGuard.as new file mode 100644 index 0000000..f7b38d8 --- /dev/null +++ b/src/eu/kiichigo/route/kore/IGuard.as @@ -0,0 +1,17 @@ +package eu.kiichigo.route.kore +{ + public interface IGuard + { + /** + * Allowed types are: Boolean or Function closure that returns a Boolean. + * Indicates whether an IGuard instance will be executed or not. + * + * Default value is true + */ + function get predicate():Object; + /** + * @private + */ + function set predicate( value:Object ):void; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IPattern.as b/src/eu/kiichigo/route/kore/IPattern.as new file mode 100644 index 0000000..4fd376c --- /dev/null +++ b/src/eu/kiichigo/route/kore/IPattern.as @@ -0,0 +1,25 @@ +package eu.kiichigo.route.kore +{ + public interface IPattern + { + /** + * A closure that will match percept received by IRoute against current IPattern. + * Allowed signatures are: + *
    + *
  • function myMatcher( pattern:IPattern, percept:Object ):Boolean
  • + *
  • function myMatcher( percept:Object ):Boolean
  • + *
+ */ + function get matcher():Function; + /** + * @private + */ + function set matcher( value:Function ):void; + + /** + * Evaluates percept received by IRoute and returns Boolean. + * If true IRoute will execute IAction instances and closures. + */ + function match( percept:Object ):Boolean; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IPerceiver.as b/src/eu/kiichigo/route/kore/IPerceiver.as new file mode 100644 index 0000000..6cf9d28 --- /dev/null +++ b/src/eu/kiichigo/route/kore/IPerceiver.as @@ -0,0 +1,9 @@ +package eu.kiichigo.route.kore +{ + public interface IPerceiver + { + function get route():IRoute; + + function set route( value:IRoute ):void; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IRPCAction.as b/src/eu/kiichigo/route/kore/IRPCAction.as new file mode 100644 index 0000000..4fd15ca --- /dev/null +++ b/src/eu/kiichigo/route/kore/IRPCAction.as @@ -0,0 +1,7 @@ +package eu.kiichigo.route.kore +{ + public interface IRPCAction + { + + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IRoute.as b/src/eu/kiichigo/route/kore/IRoute.as new file mode 100644 index 0000000..dcdf72f --- /dev/null +++ b/src/eu/kiichigo/route/kore/IRoute.as @@ -0,0 +1,55 @@ +package eu.kiichigo.route.kore +{ + public interface IRoute + { + /** + * + */ + function get percept():Object; + + /** + * A reference to the IRouter instance that's a parent for current IRoute. + */ + function get router():IRouter; + /** + * @private + */ + function set router( value:IRouter ):void; + + /** + * Allowed types are: + *
    + *
  • An instance of IAction or IActions.
  • + *
  • Function closure: A function closure with a signature: + * <function ():void or function ( percept:Object ):void.
  • + *
  • Array or Vector: of Function closures, or mixed type.
  • + *
+ */ + function get actions():Object; + /** + * @private + */ + function set actions( value:Object ):void; + + /** + * + */ + function get perceiver():Object; + /** + * @private + */ + function set perceiver( value:Object ):void; + + /** + * IPattern instance or closure that will evaluate incoming percept and "decide" whether current IRoute instance will accept it or not. + * In case of closure - allowed signatures are: + * function ( percept:Object ):Boolean + * function ( pattern:Object, percept:Object ):Boolean. + */ + function get pattern():Object; + /** + * @private + */ + function set pattern( value:Object ):void; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/IRouter.as b/src/eu/kiichigo/route/kore/IRouter.as new file mode 100644 index 0000000..1b6240a --- /dev/null +++ b/src/eu/kiichigo/route/kore/IRouter.as @@ -0,0 +1,45 @@ +package eu.kiichigo.route.kore +{ + import eu.kiichigo.route.utils.ICache; + + public interface IRouter + { + /** + * An instance of ICache that handles creation and caching of Models, Views and various Utility classes. + * ICache can be shared by multiple IRouter by changing IRouter.group value. + */ + function get cache():ICache; + + /** + * Indicates a group to wich current IRouter belongs. Default value is null which means that no group is created. + */ + function get group():Object; + /** + * @private + */ + function set group( value:Object ):void; + + /** + * + */ + function get routes():Vector.; + /** + * @private + */ + function set routes( value:Vector. ):void; + + + /** + * Adds IRoute to a list of IRouter.routes and returns newly added IRoute. + * + * @param route IRoute instance to be added. + * @return Added IRoute instance. + */ + function add( route:IRoute ):IRoute; + + /** + * Clears and removes all IRoute instances, reseting current IRouter. + */ + function clear():void; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/kore/Router.as b/src/eu/kiichigo/route/kore/Router.as new file mode 100644 index 0000000..d610063 --- /dev/null +++ b/src/eu/kiichigo/route/kore/Router.as @@ -0,0 +1,110 @@ +package eu.kiichigo.route.kore +{ + import eu.kiichigo.route.utils.Cache; + import eu.kiichigo.route.utils.ICache; + import eu.kiichigo.route.utils.add; + import eu.kiichigo.route.utils.invalidate; + import eu.kiichigo.route.utils.log; + + import flash.events.EventDispatcher; + import flash.events.IEventDispatcher; + + import mx.utils.UIDUtil; + + public class Router extends EventDispatcher implements IRouter + { + /** + * @private + * Logging + */ + protected static const log:Function = eu.kiichigo.route.utils.log( Router ); + + /** + * @copy eu.kiichigo.route.kore.IRouter#cache + */ + public function get cache():ICache + { + // If Router.group will do more than a cache control - move this logic to state evaluation. + return Cache.get( _group ); + } + + + /** + * @private + */ + protected var _group:Object = "global"; + + /** + * @copy eu.kiichigo.route.kore.IRouter#group + */ + public function get group():Object + { + return _group; + } + /** + * @private + */ + public function set group(value:Object):void + { + _group = value; + } + + + /** + * @private + */ + protected const _routes:Vector. = new Vector.; + + /** + * @copy eu.kiichigo.route.kore.IRouter#routes + */ + public function get routes():Vector. + { + return _routes; + } + /** + * @private + */ + public function set routes( value:Vector. ):void + { + clear(); + eu.kiichigo.route.utils.add( _routes, initialize )( value ); + } + + + /** + * @copy eu.kiichigo.route.kore.IRouter#add + */ + public function add( route:IRoute ):IRoute + { + _routes.push( initialize( route ) ); + return route; + } + + + /** + * @copy eu.kiichigo.route.kore.IRouter#clear + */ + public function clear():void + { + if( _routes.fixed ) + _routes.fixed = false; + + for( var i:uint = 0; i < _routes.length; i ++ ) + _routes.shift(); + + _routes.fixed = true; + } + + /** + * @private + * Initializes IRoute as a part of IRouter. + */ + protected function initialize( route:IRoute ):IRoute + { + route.router = this; + + return route; + } + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/Cache.as b/src/eu/kiichigo/route/utils/Cache.as new file mode 100644 index 0000000..1337af9 --- /dev/null +++ b/src/eu/kiichigo/route/utils/Cache.as @@ -0,0 +1,65 @@ +/* +The MIT License + +Copyright (c) 2009-2011 +David "Nirth" Sergey ( nirth@kiichigo.eu, nirth.furzahad@gmail.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package eu.kiichigo.route.utils +{ + import flash.utils.Dictionary; + + public class Cache extends Hash + implements ICache + { + /** + * @private + * Logging + */ + // + /** + * @private + * A collection of instances of ICache. + */ + protected static const instances:Dictionary = new Dictionary; + + /** + * A Multiton Pattern creation method. + */ + public static function get( id:Object = "default" ):ICache + { + if( instances[id] === null ) + instances[id] = new Cache; + + return instances[id]; + } + + /** + * @copy eu.kiichigo.route.utils.ICache#instance + */ + public function instance( generator:Class ):* + { + if( has( generator ) ) + return retreive( generator ); + return store( generator, new generator ); + } + + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/Hash.as b/src/eu/kiichigo/route/utils/Hash.as new file mode 100644 index 0000000..822237d --- /dev/null +++ b/src/eu/kiichigo/route/utils/Hash.as @@ -0,0 +1,117 @@ +/* +The MIT License + +Copyright (c) 2009-2011 +David "Nirth" Sergey ( nirth@kiichigo.eu, nirth.furzahad@gmail.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package eu.kiichigo.route.utils +{ + import flash.utils.Dictionary; + import flash.utils.getQualifiedClassName; + + public class Hash implements IHash + { + /** + * @private + * Logging + */ + protected static const log:Function = eu.kiichigo.route.utils.log( Hash ); + + /** + * An instance of a Dictionary, that stores data. + */ + protected const data:Dictionary = new Dictionary; + + + /** + * Constructor + */ + public function Hash() + { + super(); + } + + + /** + * + */ + protected const _keys:Vector. = new Vector.; + + /** + * @copy eu.kiichigo.routes.utils.IHash#properties + */ + public function get keys():Vector. + { + return _keys; + } + + /** + * @copy eu.kiichigo.routes.utils.IHash#has + */ + public function has( key:Object ):Boolean + { + return data[key] != null; + } + + /** + * @copy eu.kiichigo.routes.utils.IHash#retreive + */ + public function retreive( key:Object ):Object + { + return data[key]; + } + + /** + * @copy eu.kiichigo.routes.utils.IHash#store + */ + public function store( key:Object, value:Object ):Object + { + data[key] = value; + if( _keys.indexOf( key ) == -1 ) + _keys.push( key ); + + return value; + } + + /** + * @copy eu.kiichigo.routes.utils.IHash#clear + */ + public function clear():void + { + for( var key:* in data ) + data[key] = null; + + for( var i:uint = 0; i < _keys.length; i ++ ) + _keys.shift(); + } + + /** + * @inheritDoc + */ + public function toString():String + { + var string:String = "[" + getQualifiedClassName( this ).split( "::" )[1] + " "; + for( var property:String in data ) + string += property + "=" + data[property], log( string, data[property] ); + return string + "]"; + } + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/ICache.as b/src/eu/kiichigo/route/utils/ICache.as new file mode 100644 index 0000000..e412c42 --- /dev/null +++ b/src/eu/kiichigo/route/utils/ICache.as @@ -0,0 +1,31 @@ +/* +The MIT License + +Copyright (c) 2009-2011 +David "Nirth" Sergey ( nirth@kiichigo.eu, nirth.furzahad@gmail.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package eu.kiichigo.route.utils +{ + public interface ICache extends IHash + { + function instance( generator:Class ):*; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/IHash.as b/src/eu/kiichigo/route/utils/IHash.as new file mode 100644 index 0000000..170d925 --- /dev/null +++ b/src/eu/kiichigo/route/utils/IHash.as @@ -0,0 +1,36 @@ +package eu.kiichigo.route.utils +{ + public interface IHash + { + /** + * List of properties. + */ + function get keys():Vector.; + + /** + * Checks if there is a value associated with key, and returns true and false otherwise. + * @param key Object representation of a key. + * @return true if key has a values assigned to it, false otherwise. + */ + function has( key:Object ):Boolean; + /** + * Retreives value associated with a key supplied in arguments, or null if no key-value pair exists. + * @param key Object representation of a key to search element by. + * @return Object representation of a value, if no key-value pair exists null is returned. + */ + function retreive( key:Object ):Object; + + /** + * Stores value passed in argument with a given key. + * @param key Object representation of a key. + * @param value Object representation of a value. + * @return A value passed as argument. + */ + function store( key:Object, value:Object ):Object; + + /** + * Clears ISimpleMap instance. + */ + function clear():void; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/add.as b/src/eu/kiichigo/route/utils/add.as new file mode 100644 index 0000000..a782477 --- /dev/null +++ b/src/eu/kiichigo/route/utils/add.as @@ -0,0 +1,17 @@ + +package eu.kiichigo.route.utils +{ + public function add( to:Object, initializer:Function ):Function + { + return function( from:Object ):void + { + if( to.fixed ) + to.fixed = false; + + for( var i:uint = 0; i < from.length; i ++ ) + to.push( initializer( from[i] ) ); + + to.fixed = true; + } + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/handler.as b/src/eu/kiichigo/route/utils/handler.as new file mode 100644 index 0000000..44964ec --- /dev/null +++ b/src/eu/kiichigo/route/utils/handler.as @@ -0,0 +1,36 @@ +/* +The MIT License + +Copyright (c) 2009-2011 +David "Nirth" Sergey ( nirth@kiichigo.eu, nirth.furzahad@gmail.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package eu.kiichigo.route.utils +{ + import flash.events.Event; + + public function handler( closure:Function, includeEvent:Boolean = false, ...rest ):Function + { + return function( event:Event ):void + { + closure.apply( null, includeEvent ? [event].concat( rest ) : rest ); + } + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/initialize.as b/src/eu/kiichigo/route/utils/initialize.as new file mode 100644 index 0000000..d96fc43 --- /dev/null +++ b/src/eu/kiichigo/route/utils/initialize.as @@ -0,0 +1,44 @@ +/* +The MIT License + +Copyright (c) 2009-2011 +David "Nirth" Sergey ( nirth@kiichigo.eu, nirth.furzahad@gmail.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package eu.kiichigo.route.utils +{ + /** + * Unsafe object initializer, this method will not catch errors for performance concerns. + * + * @param to Object that will be initialized, if Class is passed, object will be automatically created. + * @param from Object - holder of the properties that will be applied onto to argument. + * @return to object with applied parameters. + */ + public function initialize( to:Object, from:Object ):Object + { + if( to is Class ) + to = new to; + + for( var property:String in from ) + to[property] = from[property]; + + return to; + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/invalidate.as b/src/eu/kiichigo/route/utils/invalidate.as new file mode 100644 index 0000000..02b0a7c --- /dev/null +++ b/src/eu/kiichigo/route/utils/invalidate.as @@ -0,0 +1,34 @@ +/* +The MIT License + +Copyright (c) 2009-2011 +David "Nirth" Sergey ( nirth@kiichigo.eu, nirth.furzahad@gmail.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package eu.kiichigo.route.utils +{ + public function invalidate( closure:Function ):Function + { + return function( ...rest ):void + { + nextFrame.apply( null, rest ); + } + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/log.as b/src/eu/kiichigo/route/utils/log.as new file mode 100755 index 0000000..6adf039 --- /dev/null +++ b/src/eu/kiichigo/route/utils/log.as @@ -0,0 +1,104 @@ +/* +The MIT License + +Copyright (c) 2009-2011 +David "Nirth" Sergey ( nirth@kiichigo.eu, nirth.furzahad@gmail.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package eu.kiichigo.route.utils +{ + import flash.external.ExternalInterface; + import flash.utils.getQualifiedClassName; + import flash.utils.getTimer; + + /** + * Logger helper, work with Web Browser console and trace. + * + * // Initializer: + * protected static const logger:Function = eu.kiichigo.debug.log( SomeClass ); + * // Log simple trace-like messages + * + * // Will display "one, two" + * logger( "one", "two" ); + * // Will display "collection someId initialized with 5 elements. + * logger( "collection {0} initialized with {2} elements", myCollection.id, myCollection.length ); + * // Will display "Object SomeObject has width 120" + * logger( "Object $name has width $width", { name: "SomeObject", width: 120 } ); + * + */ + public function log( filter:Object = "", ...rest:* ):Function + { + if( filter is Class ) + filter = getQualifiedClassName( filter ).split( "::" )[1]; + + if(rest && rest.length) + rest = [filter].concat(rest), filter = ""; + + var closure:Function = function( ...messages:* ):void + { + var string:String = ( ( filter && filter.length ) ? "[" + filter + "] " : "" ); + + if( messages.length == 2 && + messages[0].toString().indexOf( "$" ) != -1 ) + { + string += messages[0]; + var max:uint = 55; + while( string.indexOf( "$" ) != -1 && max > 0 ) + { + var from:int = string.indexOf( "$" ); + var to:int = string.indexOf( " ", from ); + var name:String = string.substring( from, to == -1 ? string.length : to ); + string = string.split( name ).join( messages[1][name.split( "$" ).join( "" )] ); + max -- + } + } + else if( messages[0].toString().indexOf( "{" ) != -1 && + messages[0].toString().indexOf( "}" ) != -1 ) + { + string += messages.shift(); + for( var i:int = 0; i < messages.length; i ++ ) + string = string.split( "{" + i + "}" ).join( messages[i] ); + } + else + { + for( var j:uint = 0; j < messages.length; j ++ ) + if( messages[j] is String ) + string += messages[j] + " "; + else if( messages[j] == null ) + string += 'null '; + else if( messages[j] is Number || messages[j] is Boolean ) + string += messages[j].toString() + " "; + else if( messages[j] is XML || messages[j] is XMLList ) + string += messages[j].toXMLString() + " "; + else + string += messages[j].toString() + " "; + } + + if( ExternalInterface.available ) + ExternalInterface.call( "console.log", string ); + trace( string ); + } + + if( rest && rest.length ) + closure.apply( null, rest ); + + return closure + } +} \ No newline at end of file diff --git a/src/eu/kiichigo/route/utils/nextFrame.as b/src/eu/kiichigo/route/utils/nextFrame.as new file mode 100644 index 0000000..0013bdc --- /dev/null +++ b/src/eu/kiichigo/route/utils/nextFrame.as @@ -0,0 +1,42 @@ +/* +The MIT License + +Copyright (c) 2009-2011 +David "Nirth" Sergey ( nirth@kiichigo.eu, nirth.furzahad@gmail.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package eu.kiichigo.route.utils +{ + import flash.display.Sprite; + import flash.events.Event; + import flash.events.IEventDispatcher; + + public function nextFrame( closure:Function, ...rest ):void + { + var handler:Function = function( event:Event ):void + { + ( event.target as IEventDispatcher ).removeEventListener( event.type, handler ); + closure.apply( null, rest ); + } + + var sprite:Sprite = new Sprite; + sprite.addEventListener( Event.ENTER_FRAME, handler, false, 0, true ); + } +} \ No newline at end of file