brandonroberts / ngrx-db-builds

MIT License
1 stars 1 forks source link

Need help regarding typescript version of this database.js #1

Open JigneshRaval opened 3 years ago

JigneshRaval commented 3 years ago

Hi @brandonroberts ,

A long time back I had found your repository ngrx/db (https://github.com/ngrx/db/blob/master/src/database.ts) and found it very useful but now I am using Angular 8+ having RxJs version 6+ and some functionality is breaking.

open method works fine and creates DB with store name but when I tried to insert record it gives me following error.

ERROR TypeError: write$.pipe is not a function
    at Database.insert (indexeddb.service.ts:157)

Below is the code for insert method. https://github.com/ngrx/db/blob/master/src/database.ts#L135

insert(
    storeName: string,
    records: any[],
    notify: boolean = true
): Observable<any> {
    const write$ = this.executeWrite(storeName, 'put', records);

    // Old Code
    // ========================
    /* return _do.call(write$, (payload: any) => notify ? this.changes.next({type: DB_INSERT, payload }) : ({})); */

    // New code with RxJs 6
    // ========================
    return write$.pipe(tap(function (payload) {
        return notify ? this.changes.next({ type: DB_INSERT, payload: payload }) : {};
    }));
}

So if possible for you then I have a small request to you. Can you please provide the TypeScript and RxJs6 version of above functionality. I looked at your new repository but it is JS file : https://github.com/brandonroberts/ngrx-db-builds/blob/master/src/database.js

Also if possible for you can you please add small tutorial or steps to use this DB in Angular 8+.

That will be your great help.

Thank you, Jignesh

JigneshRaval commented 3 years ago

Hi @brandonroberts ,

Some how I am able to manage above mentioned errors by taking referance from your latest database.js and replacing mergeMap.call to pipe function and have created example on Stackblitz.

https://angular-indexeddb-example.stackblitz.io

https://stackblitz.com/edit/angular-indexeddb-example?file=src%2Fapp%2Fmodules%2Findexeddb.module.ts

But still not able to get the data back. it gives undefined.

Please guide. Thanks,