Created
December 20, 2011 16:17
-
-
Save mikecann/1502132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package base; | |
import js.Dom; | |
import js.JQuery; | |
import robothaxe.core.IViewContainer; | |
/** | |
* ... | |
* @author | |
*/ | |
class BaseView implements IViewContainer | |
{ | |
public var viewAdded:Dynamic -> Void; | |
public var viewRemoved:Dynamic -> Void; | |
public var element : HtmlDom; | |
public var parent : BaseView; | |
public var children : Array<BaseView>; | |
public function new(element:HtmlDom) | |
{ | |
this.element = element; | |
this.children = []; | |
} | |
public function add(child:BaseView) : Void | |
{ | |
children.push(child); | |
child.parent = this; | |
child.viewAdded = viewAdded; | |
child.viewRemoved = viewRemoved; | |
if(viewAdded!=null) child.addChildren(); | |
element.appendChild(child.element); | |
if(viewAdded!=null) viewAdded(child); | |
} | |
public function remove(child:BaseView) : Void | |
{ | |
if (viewRemoved != null) child.removeChildren(); | |
children.remove(child); | |
child.parent = null; | |
child.viewAdded = null; | |
child.viewRemoved = null; | |
element.removeChild(child.element); | |
if (viewRemoved != null) viewRemoved(child); | |
} | |
public function addChildren() : Void | |
{ | |
for (c in children) | |
{ | |
c.viewAdded = viewAdded; | |
c.viewRemoved = viewRemoved; | |
c.addChildren(); | |
viewAdded(c); | |
} | |
} | |
public function removeChildren() : Void | |
{ | |
for (c in children) | |
{ | |
c.removeChildren(); | |
element.removeChild(c.element); | |
c.parent = null; | |
c.viewAdded = null; | |
c.viewRemoved = null; | |
if (viewRemoved != null) viewRemoved(c); | |
} | |
} | |
public function isAdded(view:Dynamic):Bool | |
{ | |
return Lambda.has(children,view); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment