Permalink
Browse files

some addtion and renaming of vars with _

  • Loading branch information...
1 parent 273f290 commit f2a58d51518138a12f034a03ed2e036e2cebd972 @cloudshift committed Mar 19, 2012
Showing with 29 additions and 18 deletions.
  1. +1 −1 cloudshift/Core.hx
  2. +6 −6 cloudshift/Mixin.hx
  3. +22 −11 cloudshift/core/PartBaseImpl.hx
View
@@ -75,7 +75,7 @@ interface Part_<S,B,G,E> {
var _events:Observable<EPartState<E>>;
var partID(default,null):String;
var state:EPartState<E>;
- var info:PartInfo;
+ var _info:PartInfo;
var sstopper:Dynamic->Outcome<String,Dynamic>;
function start(d:S,?oc:Outcome<B,G>):Outcome<B,G>;
View
@@ -395,7 +395,7 @@ class HashX {
}
public static function
- keyArray<T>(h:Hash<T>) {
+ keyArray<T>(h:Hash<T>):Array<String> {
var a = [];
for (v in h.keys())
a.push(v);
@@ -628,8 +628,8 @@ class PartX {
part.part_.setStop(cb);
}
- public static function observe<S,B,G,E>(part:Part<S,B,G,E>,cb:E->Void) {
- part.part_.observe(cb);
+ public static function observe<S,B,G,E>(part:Part<S,B,G,E>,cb:E->Void):Void->Void {
+ return part.part_.observe(cb);
}
public static function notify<S,B,G,E>(part:Part<S,B,G,E>,e:E) {
@@ -640,8 +640,8 @@ class PartX {
return part.part_.partID;
}
- public static function observeState<S,B,G,E>(part:Part<S,B,G,E>,cb:EPartState<E>->Void):Void {
- part.part_._events.observe(cb);
+ public static function observeState<S,B,G,E>(part:Part<S,B,G,E>,cb:EPartState<E>->Void):Void->Void {
+ return part.part_._events.observe(cb);
}
public static function
@@ -651,7 +651,7 @@ class PartX {
public static function
info<S,B,G,E>(part:Part<S,B,G,E>) {
- return part.part_.info;
+ return part.part_._info;
}
@@ -5,20 +5,26 @@ using cloudshift.Mixin;
class PartBaseImpl<S,B,G,E> implements Part_<S,B,G,E> {
public static var runningParts:Array<AnyPart> = [];
+ static var _nextID = 0;
public var partID(default,null):String;
public var _events:Observable<EPartState<E>>;
public var state:EPartState<E>;
- public var info:PartInfo;
+ public var _info:PartInfo;
public var sstopper:Dynamic->Outcome<String,Dynamic>;
-
- var parent:Dynamic;
+
+ var _observers:Array<Void->Void>;
+ var _ID:Int;
+ var _parent:Dynamic;
public function new(parent:Dynamic,?info:PartInfo) {
- this.parent = parent;
- this.info = info;
- partID = Type.getClassName(Type.getClass(parent));
+ _parent = parent;
+ _info = info;
+ _ID = _nextID++;
+ _observers = [];
+ partID = Type.getClassName(Type.getClass(_parent))+Std.string(_ID);
_events = Core.event();
+
#if debug
partInfo("created");
#end
@@ -30,7 +36,7 @@ class PartBaseImpl<S,B,G,E> implements Part_<S,B,G,E> {
}
public function peer():Dynamic {
- return parent;
+ return _parent;
}
public function notify(e:E) {
@@ -42,13 +48,15 @@ class PartBaseImpl<S,B,G,E> implements Part_<S,B,G,E> {
}
public function observe(cb:E->Void,?info:Dynamic) {
- return _events.observe(function(s) {
+ var unsub = _events.observe(function(s) {
switch(s) {
case Event(s):
cb(s);
default:
}
- },info);
+ },partID);
+ _observers.push(unsub);
+ return unsub;
}
public function observeState(cb:EPartState<E>->Void) {
@@ -57,15 +65,15 @@ class PartBaseImpl<S,B,G,E> implements Part_<S,B,G,E> {
public function start(d:S,?oc:Outcome<B,G>):Outcome<B,G> {
- var p:Outcome<B,G> = parent.start_(d,oc);
+ var p:Outcome<B,G> = _parent.start_(d,oc);
checkErr("start",p);
p.outcome(function(outcome) {
partInfo("started");
state = Started;
- runningParts.push(parent);
+ // runningParts.push(_parent);
_events.notify(Started);
},function(msg) {
@@ -84,6 +92,9 @@ class PartBaseImpl<S,B,G,E> implements Part_<S,B,G,E> {
state = Stopped;
partInfo("stopped");
_events.notify(Stopped);
+ _observers.foreach(function(observerRemove) {
+ observerRemove();
+ });
},function(msg) {
_events.notify(Error(msg));
});

0 comments on commit f2a58d5

Please sign in to comment.