diff --git a/src/util/Observable.hx b/src/util/Observable.hx index 01299b6..44f314d 100644 --- a/src/util/Observable.hx +++ b/src/util/Observable.hx @@ -4,7 +4,7 @@ using tink.CoreApi; class Observable { private var value:T; - private var callbacks:CallbackList = new CallbackList(true); + private var callbacks:CallbackList = new CallbackList(); public function new(value:T) { this.value = value; diff --git a/src/util/ObservableArray.hx b/src/util/ObservableArray.hx new file mode 100644 index 0000000..ac95a4c --- /dev/null +++ b/src/util/ObservableArray.hx @@ -0,0 +1,56 @@ +package util; + +class ObservableArray extends Observable> { + public function new(value: Array) { + super(value); + } + + public function insert(pos: Int, x: T):Void { + this.value.insert(pos,x); + this.callbacks.invoke(this.value); + } + + public function pop(): Null { + var poped = this.pop(); + this.callbacks.invoke(this.value); + return poped; + } + + public function push(x: T):Int { + var i = this.value.push(x); + this.callbacks.invoke(this.value); + return i; + } + + public function remove(x: T): Bool { + var b = this.value.remove(x); + this.callbacks.invoke(this.value); + return b; + } + + public function resize(len: Int) { + this.value.resize(len); + this.callbacks.invoke(this.value); + } + + public function reverse() { + this.value.reverse(); + this.callbacks.invoke(this.value); + } + + public function shift(): Null { + var e = this.value.shift(); + this.callbacks.invoke(this.value); + return e; + } + + public function sort(f:(T, T) -> Int):Void { + this.value.sort(f); + this.callbacks.invoke(this.value); + } + + public function unshift(x: T):Void { + this.value.unshift(x); + this.callbacks.invoke(this.value); + } +}