added observable array

This commit is contained in:
Djeeberjr 2022-03-07 20:21:17 +01:00
parent 672826c326
commit 7c4fc95584
2 changed files with 57 additions and 1 deletions

View File

@ -4,7 +4,7 @@ using tink.CoreApi;
class Observable<T> { class Observable<T> {
private var value: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) { public function new(value:T) {
this.value = value; this.value = value;

View 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);
}
}