forked from mystiq/hydrogen-web
fix handlers in test missing methods, now that observable list is typed
This commit is contained in:
parent
581ef47c78
commit
de8995fa7e
1 changed files with 31 additions and 30 deletions
|
@ -15,6 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Range, RangeZone} from "./Range";
|
import {Range, RangeZone} from "./Range";
|
||||||
|
import {defaultObserverWith} from "../../../../observable/list/BaseObservableList";
|
||||||
|
|
||||||
function skipOnIterator<T>(it: Iterator<T>, pos: number): boolean {
|
function skipOnIterator<T>(it: Iterator<T>, pos: number): boolean {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
@ -268,7 +269,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["b", "c", "d", "e"]);
|
const list = new ObservableArray(["b", "c", "d", "e"]);
|
||||||
const range = new ListRange(1, 3, list.length);
|
const range = new ListRange(1, 3, list.length);
|
||||||
let added = false;
|
let added = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onAdd(idx, value) {
|
onAdd(idx, value) {
|
||||||
added = true;
|
added = true;
|
||||||
const result = range.queryAdd(idx, value, list);
|
const result = range.queryAdd(idx, value, list);
|
||||||
|
@ -280,7 +281,7 @@ export function tests() {
|
||||||
newRange: new ListRange(1, 3, 5)
|
newRange: new ListRange(1, 3, 5)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.insert(0, "a");
|
list.insert(0, "a");
|
||||||
assert(added);
|
assert(added);
|
||||||
},
|
},
|
||||||
|
@ -288,7 +289,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "d", "e"]);
|
||||||
const range = new ListRange(1, 3, list.length);
|
const range = new ListRange(1, 3, list.length);
|
||||||
let added = false;
|
let added = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onAdd(idx, value) {
|
onAdd(idx, value) {
|
||||||
added = true;
|
added = true;
|
||||||
const result = range.queryAdd(idx, value, list);
|
const result = range.queryAdd(idx, value, list);
|
||||||
|
@ -300,7 +301,7 @@ export function tests() {
|
||||||
newRange: new ListRange(1, 3, 5)
|
newRange: new ListRange(1, 3, 5)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.insert(2, "c");
|
list.insert(2, "c");
|
||||||
assert(added);
|
assert(added);
|
||||||
},
|
},
|
||||||
|
@ -308,7 +309,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d"]);
|
const list = new ObservableArray(["a", "b", "c", "d"]);
|
||||||
const range = new ListRange(1, 3, list.length);
|
const range = new ListRange(1, 3, list.length);
|
||||||
let added = false;
|
let added = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onAdd(idx, value) {
|
onAdd(idx, value) {
|
||||||
added = true;
|
added = true;
|
||||||
const result = range.queryAdd(idx, value, list);
|
const result = range.queryAdd(idx, value, list);
|
||||||
|
@ -317,7 +318,7 @@ export function tests() {
|
||||||
newRange: new ListRange(1, 3, 5)
|
newRange: new ListRange(1, 3, 5)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.insert(4, "e");
|
list.insert(4, "e");
|
||||||
assert(added);
|
assert(added);
|
||||||
},
|
},
|
||||||
|
@ -326,7 +327,7 @@ export function tests() {
|
||||||
const viewportItemCount = 4;
|
const viewportItemCount = 4;
|
||||||
const range = new ListRange(0, 3, list.length, viewportItemCount);
|
const range = new ListRange(0, 3, list.length, viewportItemCount);
|
||||||
let added = false;
|
let added = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onAdd(idx, value) {
|
onAdd(idx, value) {
|
||||||
added = true;
|
added = true;
|
||||||
const result = range.queryAdd(idx, value, list);
|
const result = range.queryAdd(idx, value, list);
|
||||||
|
@ -337,7 +338,7 @@ export function tests() {
|
||||||
value: "c"
|
value: "c"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.insert(2, "c");
|
list.insert(2, "c");
|
||||||
assert(added);
|
assert(added);
|
||||||
},
|
},
|
||||||
|
@ -345,7 +346,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(1, 3, list.length);
|
const range = new ListRange(1, 3, list.length);
|
||||||
let removed = false;
|
let removed = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onRemove(idx) {
|
onRemove(idx) {
|
||||||
removed = true;
|
removed = true;
|
||||||
const result = range.queryRemove(idx, list);
|
const result = range.queryRemove(idx, list);
|
||||||
|
@ -357,7 +358,7 @@ export function tests() {
|
||||||
newRange: new ListRange(1, 3, 4)
|
newRange: new ListRange(1, 3, 4)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.remove(0);
|
list.remove(0);
|
||||||
assert(removed);
|
assert(removed);
|
||||||
},
|
},
|
||||||
|
@ -365,7 +366,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(1, 3, list.length);
|
const range = new ListRange(1, 3, list.length);
|
||||||
let removed = false;
|
let removed = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onRemove(idx) {
|
onRemove(idx) {
|
||||||
removed = true;
|
removed = true;
|
||||||
const result = range.queryRemove(idx, list);
|
const result = range.queryRemove(idx, list);
|
||||||
|
@ -378,7 +379,7 @@ export function tests() {
|
||||||
});
|
});
|
||||||
assert.equal(list.length, 4);
|
assert.equal(list.length, 4);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.remove(2);
|
list.remove(2);
|
||||||
assert(removed);
|
assert(removed);
|
||||||
},
|
},
|
||||||
|
@ -386,7 +387,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(1, 3, list.length);
|
const range = new ListRange(1, 3, list.length);
|
||||||
let removed = false;
|
let removed = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onRemove(idx) {
|
onRemove(idx) {
|
||||||
removed = true;
|
removed = true;
|
||||||
const result = range.queryRemove(idx, list);
|
const result = range.queryRemove(idx, list);
|
||||||
|
@ -395,7 +396,7 @@ export function tests() {
|
||||||
newRange: new ListRange(1, 3, 4)
|
newRange: new ListRange(1, 3, 4)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.remove(3);
|
list.remove(3);
|
||||||
assert(removed);
|
assert(removed);
|
||||||
},
|
},
|
||||||
|
@ -403,7 +404,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c"]);
|
const list = new ObservableArray(["a", "b", "c"]);
|
||||||
const range = new ListRange(1, 3, list.length);
|
const range = new ListRange(1, 3, list.length);
|
||||||
let removed = false;
|
let removed = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onRemove(idx) {
|
onRemove(idx) {
|
||||||
removed = true;
|
removed = true;
|
||||||
const result = range.queryRemove(idx, list);
|
const result = range.queryRemove(idx, list);
|
||||||
|
@ -415,7 +416,7 @@ export function tests() {
|
||||||
value: "a"
|
value: "a"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.remove(2);
|
list.remove(2);
|
||||||
assert(removed);
|
assert(removed);
|
||||||
},
|
},
|
||||||
|
@ -423,7 +424,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c"]);
|
const list = new ObservableArray(["a", "b", "c"]);
|
||||||
const range = new ListRange(0, 3, list.length);
|
const range = new ListRange(0, 3, list.length);
|
||||||
let removed = false;
|
let removed = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onRemove(idx) {
|
onRemove(idx) {
|
||||||
removed = true;
|
removed = true;
|
||||||
const result = range.queryRemove(idx, list);
|
const result = range.queryRemove(idx, list);
|
||||||
|
@ -433,7 +434,7 @@ export function tests() {
|
||||||
removeIdx: 2,
|
removeIdx: 2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.remove(2);
|
list.remove(2);
|
||||||
assert(removed);
|
assert(removed);
|
||||||
},
|
},
|
||||||
|
@ -441,7 +442,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(1, 4, list.length);
|
const range = new ListRange(1, 4, list.length);
|
||||||
let moved = false;
|
let moved = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onMove(fromIdx, toIdx, value) {
|
onMove(fromIdx, toIdx, value) {
|
||||||
moved = true;
|
moved = true;
|
||||||
const result = range.queryMove(fromIdx, toIdx, value, list);
|
const result = range.queryMove(fromIdx, toIdx, value, list);
|
||||||
|
@ -451,7 +452,7 @@ export function tests() {
|
||||||
toIdx: 3
|
toIdx: 3
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.move(2, 3);
|
list.move(2, 3);
|
||||||
assert(moved);
|
assert(moved);
|
||||||
},
|
},
|
||||||
|
@ -459,7 +460,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(2, 5, list.length);
|
const range = new ListRange(2, 5, list.length);
|
||||||
let moved = false;
|
let moved = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onMove(fromIdx, toIdx, value) {
|
onMove(fromIdx, toIdx, value) {
|
||||||
moved = true;
|
moved = true;
|
||||||
const result = range.queryMove(fromIdx, toIdx, value, list);
|
const result = range.queryMove(fromIdx, toIdx, value, list);
|
||||||
|
@ -470,7 +471,7 @@ export function tests() {
|
||||||
value: "a"
|
value: "a"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.move(0, 3); // move "a" to after "d"
|
list.move(0, 3); // move "a" to after "d"
|
||||||
assert(moved);
|
assert(moved);
|
||||||
},
|
},
|
||||||
|
@ -478,7 +479,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(0, 3, list.length);
|
const range = new ListRange(0, 3, list.length);
|
||||||
let moved = false;
|
let moved = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onMove(fromIdx, toIdx, value) {
|
onMove(fromIdx, toIdx, value) {
|
||||||
moved = true;
|
moved = true;
|
||||||
const result = range.queryMove(fromIdx, toIdx, value, list);
|
const result = range.queryMove(fromIdx, toIdx, value, list);
|
||||||
|
@ -489,7 +490,7 @@ export function tests() {
|
||||||
value: "e"
|
value: "e"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.move(4, 1); // move "e" to before "b"
|
list.move(4, 1); // move "e" to before "b"
|
||||||
assert(moved);
|
assert(moved);
|
||||||
},
|
},
|
||||||
|
@ -497,7 +498,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(0, 3, list.length);
|
const range = new ListRange(0, 3, list.length);
|
||||||
let moved = false;
|
let moved = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onMove(fromIdx, toIdx, value) {
|
onMove(fromIdx, toIdx, value) {
|
||||||
moved = true;
|
moved = true;
|
||||||
const result = range.queryMove(fromIdx, toIdx, value, list);
|
const result = range.queryMove(fromIdx, toIdx, value, list);
|
||||||
|
@ -508,7 +509,7 @@ export function tests() {
|
||||||
value: "d"
|
value: "d"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.move(1, 3); // move "b" to after "d"
|
list.move(1, 3); // move "b" to after "d"
|
||||||
assert(moved);
|
assert(moved);
|
||||||
},
|
},
|
||||||
|
@ -516,7 +517,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(2, 5, list.length);
|
const range = new ListRange(2, 5, list.length);
|
||||||
let moved = false;
|
let moved = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onMove(fromIdx, toIdx, value) {
|
onMove(fromIdx, toIdx, value) {
|
||||||
moved = true;
|
moved = true;
|
||||||
const result = range.queryMove(fromIdx, toIdx, value, list);
|
const result = range.queryMove(fromIdx, toIdx, value, list);
|
||||||
|
@ -527,7 +528,7 @@ export function tests() {
|
||||||
value: "b"
|
value: "b"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.move(3, 0); // move "d" to before "a"
|
list.move(3, 0); // move "d" to before "a"
|
||||||
assert(moved);
|
assert(moved);
|
||||||
},
|
},
|
||||||
|
@ -535,7 +536,7 @@ export function tests() {
|
||||||
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
const list = new ObservableArray(["a", "b", "c", "d", "e"]);
|
||||||
const range = new ListRange(1, 4, list.length);
|
const range = new ListRange(1, 4, list.length);
|
||||||
let moved = false;
|
let moved = false;
|
||||||
list.subscribe({
|
list.subscribe(defaultObserverWith({
|
||||||
onMove(fromIdx, toIdx, value) {
|
onMove(fromIdx, toIdx, value) {
|
||||||
moved = true;
|
moved = true;
|
||||||
const result = range.queryMove(fromIdx, toIdx, value, list);
|
const result = range.queryMove(fromIdx, toIdx, value, list);
|
||||||
|
@ -546,7 +547,7 @@ export function tests() {
|
||||||
value: "e"
|
value: "e"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
list.move(0, 4); // move "a" to after "e"
|
list.move(0, 4); // move "a" to after "e"
|
||||||
assert(moved);
|
assert(moved);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue