forked from mystiq/hydrogen-web
Mock IDBKeyRange, too
This commit is contained in:
parent
71694787cd
commit
713f675f3a
3 changed files with 8 additions and 6 deletions
|
@ -32,10 +32,12 @@ interface QueryTargetInterface<T> {
|
|||
export class QueryTarget<T> {
|
||||
protected _target: QueryTargetInterface<T>;
|
||||
protected _idbFactory: IDBFactory
|
||||
protected _IDBKeyRange: typeof IDBKeyRange
|
||||
|
||||
constructor(target: QueryTargetInterface<T>, idbFactory: IDBFactory) {
|
||||
constructor(target: QueryTargetInterface<T>, idbFactory: IDBFactory, _IDBKeyRange: typeof IDBKeyRange) {
|
||||
this._target = target;
|
||||
this._idbFactory = idbFactory;
|
||||
this._IDBKeyRange = _IDBKeyRange;
|
||||
}
|
||||
|
||||
_openCursor(range?: IDBQuery, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null> {
|
||||
|
@ -161,7 +163,7 @@ export class QueryTarget<T> {
|
|||
const sortedKeys = keys.slice().sort(compareKeys);
|
||||
const firstKey = backwards ? sortedKeys[sortedKeys.length - 1] : sortedKeys[0];
|
||||
const lastKey = backwards ? sortedKeys[0] : sortedKeys[sortedKeys.length - 1];
|
||||
const cursor = this._target.openKeyCursor(IDBKeyRange.bound(firstKey, lastKey), direction);
|
||||
const cursor = this._target.openKeyCursor(this._IDBKeyRange.bound(firstKey, lastKey), direction);
|
||||
let i = 0;
|
||||
let consumerDone = false;
|
||||
await iterateCursor(cursor, (value, key) => {
|
||||
|
|
|
@ -130,8 +130,8 @@ class QueryTargetWrapper<T> {
|
|||
export class Store<T> extends QueryTarget<T> {
|
||||
private _transaction: Transaction;
|
||||
|
||||
constructor(idbStore: IDBObjectStore, transaction: Transaction, idbFactory: IDBFactory) {
|
||||
super(new QueryTargetWrapper<T>(idbStore), idbFactory);
|
||||
constructor(idbStore: IDBObjectStore, transaction: Transaction) {
|
||||
super(new QueryTargetWrapper<T>(idbStore), transaction.idbFactory, transaction.IDBKeyRange);
|
||||
this._transaction = transaction;
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ export class Store<T> extends QueryTarget<T> {
|
|||
}
|
||||
|
||||
index(indexName: string): QueryTarget<T> {
|
||||
return new QueryTarget<T>(new QueryTargetWrapper<T>(this._idbStore.index(indexName)), this._idbFactory);
|
||||
return new QueryTarget<T>(new QueryTargetWrapper<T>(this._idbStore.index(indexName)), this._idbFactory, this._IDBKeyRange);
|
||||
}
|
||||
|
||||
put(value: T): void {
|
||||
|
|
|
@ -56,7 +56,7 @@ export class Transaction {
|
|||
// more specific error? this is a bug, so maybe not ...
|
||||
throw new StorageError(`Invalid store for transaction: ${name}, only ${this._allowedStoreNames.join(", ")} are allowed.`);
|
||||
}
|
||||
return new Store(this._txn.objectStore(name), this, this.idbFactory);
|
||||
return new Store(this._txn.objectStore(name), this);
|
||||
}
|
||||
|
||||
_store<T>(name: StoreNames, mapStore: (idbStore: Store<any>) => T): T {
|
||||
|
|
Loading…
Reference in a new issue