1
1
// RxJS.
2
- import { of , Subscription } from 'rxjs' ;
2
+ import { of } from 'rxjs' ;
3
3
4
4
// Class.
5
5
import { IDBData } from './idb-data.class' ;
6
6
7
7
// Type.
8
- import { IDBStoreParameters } from './type/idb-store-parameters.type' ;
9
- import { IDBRequestTransaction } from './type/idb-request-transaction.type' ;
10
8
import { IDBRequestOnSuccess } from './type/idb-request-on-success.type' ;
9
+ import { IDBRequestTransaction } from './type/idb-request-transaction.type' ;
10
+ import { IDBStoreParameters } from './type/idb-store-parameters.type' ;
11
11
12
12
// Interface.
13
13
import { IDBStoreInterface } from './interface/idb-store.interface' ;
@@ -90,25 +90,20 @@ export class IDBStore<
90
90
storeNames : StoreNames | StoreNames [ ] = this . #database. connection . storeNames ,
91
91
mode : IDBTransactionMode = "readwrite"
92
92
) : this {
93
- this . #promise( ( resolve , reject , subscription ) => (
94
- subscription . add (
95
- ( Array . isArray ( value ) ? of ( ...value ) : of ( value ) ) . subscribe ( {
96
- next : value => this . #add(
97
- storeName ,
98
- value as any ,
99
- key ,
100
- onsuccess ,
101
- onerror ,
102
- transaction ,
103
- storeNames ,
104
- mode
105
- ) ,
106
- complete : ( resolve ( subscription ) , complete ) ,
107
- error : err => ( resolve ( subscription ) , reject ( err ) , typeof error === 'function' && error ( err ) , err )
108
- } ) ,
93
+ ( Array . isArray ( value ) ? of ( ...value ) : of ( value ) ) . subscribe ( {
94
+ next : value => this . #add(
95
+ storeName ,
96
+ value as any ,
97
+ key ,
98
+ onsuccess ,
99
+ onerror ,
100
+ transaction ,
101
+ storeNames ,
102
+ mode
109
103
) ,
110
- subscription
111
- ) ) ;
104
+ complete,
105
+ error
106
+ } )
112
107
return this ;
113
108
}
114
109
@@ -362,8 +357,7 @@ export class IDBStore<
362
357
name : string ,
363
358
364
359
// Request.
365
- onsuccess ?: IDBRequestOnSuccess < any , any > | null ,
366
- onerror ?: ( this : IDBRequest < any > , ev : Event ) => any ,
360
+ onsuccess ?: ( index : IDBIndex ) => any ,
367
361
368
362
// Transaction.
369
363
transaction ?: IDBRequestTransaction ,
@@ -374,9 +368,7 @@ export class IDBStore<
374
368
) : this {
375
369
this . #database. objectStore (
376
370
storeName ,
377
- store => {
378
- const index = store . index ( name ) ;
379
- } ,
371
+ store => typeof onsuccess === 'function' && onsuccess ( store . index ( name ) ) ,
380
372
transaction ?. oncomplete ,
381
373
transaction ?. onabort ,
382
374
transaction ?. onerror ,
@@ -404,7 +396,7 @@ export class IDBStore<
404
396
direction ?: IDBCursorDirection ,
405
397
406
398
// Request.
407
- onsuccess ?: IDBRequestOnSuccess < any , IDBCursorWithValue | null > | null ,
399
+ onsuccess ?: IDBRequestOnSuccess < IDBCursorWithValue , IDBCursorWithValue | null > | null ,
408
400
onerror ?: ( this : IDBRequest < IDBCursorWithValue | null > , ev : Event ) => any | null ,
409
401
410
402
// Transaction.
@@ -471,7 +463,6 @@ export class IDBStore<
471
463
) ;
472
464
return this ;
473
465
}
474
-
475
466
476
467
/**
477
468
*
@@ -520,24 +511,5 @@ export class IDBStore<
520
511
) ;
521
512
return this ;
522
513
}
523
-
524
- /**
525
- *
526
- * @param executor
527
- * @returns
528
- */
529
- #promise(
530
- executor : (
531
- resolve : ( value : Subscription | PromiseLike < Subscription > ) => void ,
532
- reject : ( reason ?: any ) => void ,
533
- subscription : Subscription
534
- ) => Subscription
535
- ) : this {
536
- new Promise < Subscription > ( ( resolve , reject ) => executor ( resolve , reject , new Subscription ( ) ) )
537
- . then ( subscription => subscription . unsubscribe ( ) )
538
- . catch ( ( ) => { } )
539
- . finally ( ) ;
540
- return this ;
541
- }
542
514
}
543
515
0 commit comments