added observable array
This commit is contained in:
parent
672826c326
commit
7c4fc95584
@ -4,7 +4,7 @@ using tink.CoreApi;
|
||||
|
||||
class Observable<T> {
|
||||
private var value:T;
|
||||
private var callbacks:CallbackList<T> = new CallbackList(true);
|
||||
private var callbacks:CallbackList<T> = new CallbackList();
|
||||
|
||||
public function new(value:T) {
|
||||
this.value = value;
|
||||
|
56
src/util/ObservableArray.hx
Normal file
56
src/util/ObservableArray.hx
Normal file
@ -0,0 +1,56 @@
|
||||
package util;
|
||||
|
||||
class ObservableArray<T> extends Observable<Array<T>> {
|
||||
public function new(value: Array<T>) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
public function insert(pos: Int, x: T):Void {
|
||||
this.value.insert(pos,x);
|
||||
this.callbacks.invoke(this.value);
|
||||
}
|
||||
|
||||
public function pop(): Null<T> {
|
||||
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<T> {
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user