package org.libspark.model { import flash.events.Event; import org.libspark.common.Any; import org.libspark.common.ability.IComparable; import org.libspark.common.store.IReadableStore; import org.libspark.common.store.IWritableStore; import org.libspark.events.HierarchicalEventDispatcher; import org.libspark.events.IHierarchicalEventDispatcher; import org.libspark.events.ModelEvent; import org.libspark.events.PropertyChangeEvent; public class AbstractModel extends Any implements IModel { public function AbstractModel() { dispatcher = new HierarchicalEventDispatcher(this); } protected function addDependency(model:IModel):void { model.parentDispatcher = this; } protected function removeDependency(model:IModel):void { if (model.parentDispatcher == this) { model.parentDispatcher = null; } } protected function notifyPropertyChange(propertyName:String):void { var event:PropertyChangeEvent = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE, propertyName); dispatchEvent(event); dispatchEvent(new ModelEvent(ModelEvent.UPDATE, event)); } private var _dispatcher:IHierarchicalEventDispatcher; protected function get dispatcher():IHierarchicalEventDispatcher { return _dispatcher; } protected function set dispatcher(value:IHierarchicalEventDispatcher):void { _dispatcher = value; } public function get parentDispatcher():IHierarchicalEventDispatcher { return dispatcher.parentDispatcher; } public function set parentDispatcher(value:IHierarchicalEventDispatcher):void { dispatcher.parentDispatcher = value; } public function dispatchCaptureEvent(event:Event):void { dispatcher.dispatchCaptureEvent(event); } public function dispatchBubblingEvent(event:Event):void { dispatcher.dispatchBubblingEvent(event); } public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void { dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference); } public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void { dispatcher.removeEventListener(type, listener, useCapture); } public function dispatchEvent(event:Event):Boolean { return dispatcher.dispatchEvent(event); } public function hasEventListener(type:String):Boolean { return dispatcher.hasEventListener(type); } public function willTrigger(type:String):Boolean { return dispatcher.willTrigger(type); } } }