Git Product home page Git Product logo

Comments (19)

elsigh avatar elsigh commented on June 15, 2024 4

fwiw I'm getting this same error trying to use localforage-observable and found this issue.

My code is

import localforage from "localforage";
import "localforage-observable";

I've tried a few of the other incantations mentioned but no dice.
using
[email protected]
[email protected]

from localforage-observable.

thgreasi avatar thgreasi commented on June 15, 2024 1

I guess that you only get newObservable in the browser and not in Typescript.
Ok, great. I know what I have to change. I will try to release v1.1.1 tonight and v1.2.0 with proper typings during the weekend!

from localforage-observable.

thgreasi avatar thgreasi commented on June 15, 2024

You should be able to use this extension by importing it right after localforage itself, using a similar import statement.

In ES6 you should do:

import * as localforage from 'localforage';
import * as lo from 'localforage-observable'; // OR just import  'localforage-observable';

var observable = localforage.newObservable();
localforage.setItem('test', 'testvalue');

This lib is currently missing some typings. Also, the fact that it extends the localforage prototype might make it even worse for typescript users. I will try to find out a solution during the weekend.

from localforage-observable.

Itrulia avatar Itrulia commented on June 15, 2024

import "localforage-observable does not work because it can't find the window module. import * as lo from "localforage-observable does work though. atleast it doesn't throw an error, but it can't find newObservable on localForage.

edit: import window from 'window'; fucks it up in localforage-observable.es6.js. When trying to console.log(lo) with the other method it also breaks with the same error.

from localforage-observable.

thgreasi avatar thgreasi commented on June 15, 2024

Typescript will not be able to find newObservable since we are currently missing some typings. To be honest I never actually tested this lib with typescript.
Have you tried localforage-observable.js ?
Also, can you give some feedback on v1.0.0, which doesn't contain the aforementioned import window from 'window' expression?

Thanks for the feedback so far!

from localforage-observable.

Itrulia avatar Itrulia commented on June 15, 2024

with import * lo from "localforage-observable the newObservable object isn't found on localForage in the browser, not in the typings :)

localforage-observable/dist/localforage-observable.js has the same window error. Trying the v1,0,0 now

from localforage-observable.

Itrulia avatar Itrulia commented on June 15, 2024

v1.0.0 is working

from localforage-observable.

Itrulia avatar Itrulia commented on June 15, 2024

Nah when you do: import * lo from "localforage-observable" it seems like that the code to append it is never executed or is working on another reference? console.log didn't bring it up and

this.db$ = fromPromise(localForage.ready()).map(x => localForage);
this.db$.take(1).subscribe(db => {
    db.newObservable.factory = (fn) => Observable.create(fn);
});

threw an error trying to access factory of undefined in the browser.

Thanks!

from localforage-observable.

thgreasi avatar thgreasi commented on June 15, 2024

It seems to work on the browser even on other instances, I will check it out on an Ionic project tonight.

from localforage-observable.

Itrulia avatar Itrulia commented on June 15, 2024

Well it isn't using imports and thats the problem :D

from localforage-observable.

thgreasi avatar thgreasi commented on June 15, 2024

Just released v1.1.1 that should fix the window error. Starting writing the Typings now. Any confirmation would be appreciated.

from localforage-observable.

Itrulia avatar Itrulia commented on June 15, 2024

Will check tomorrow, thanks!

from localforage-observable.

jloosli avatar jloosli commented on June 15, 2024

I tested using v1.1.1 and got the following to almost work:

import * as localforage from 'localforage';
import 'localforage-observable';

...

(localforage as any).newObservable({key: 'pending'}).subscribe((args) => console.log(args));

When I get to the newObservable part, I get the following error: ReferenceError: Observable is not defined.
This is in reference to this line in the localforage-observable library.

I've tried adding

import {Observable} from 'rxjs/Observable';

above the other imports and that doesn't change anything.

from localforage-observable.

jloosli avatar jloosli commented on June 15, 2024

Also, I can confirm that I no longer have the window error with v1.1.1

from localforage-observable.

thgreasi avatar thgreasi commented on June 15, 2024

@jloosli Thanks for the instant feeback 👍
I'm think I will be able to release v1.2.0 tomorrow.

from localforage-observable.

thgreasi avatar thgreasi commented on June 15, 2024

I just opened #11 that hopefully resolves this and #9.
Any feedback will be appreciated.

from localforage-observable.

Itrulia avatar Itrulia commented on June 15, 2024

@jloosli your problem stems from the fact that the library is using zen-observables by default. You need to override the factory function like this:

this.db$ = fromPromise(localForage.ready()).map(x => localForage);
this.db$.take(1).subscribe(db => {
    db.newObservable.factory = (fn) => Observable.create(fn);
});

Can also confirm that everything is working now

from localforage-observable.

thgreasi avatar thgreasi commented on June 15, 2024

Just released v1.2.0.
Readme now also points to an example Ionic 2 project.

from localforage-observable.

jloosli avatar jloosli commented on June 15, 2024

@Itrulia thanks for the heads up on RxJs vs Zen-Observables...I hadn't caught that when looking through the docs.

For what it's worth, 1.2.0 is working for me with the following in the top of the modules I use it in:

import * as localForage from 'localforage';
const lfo = require('localforage-observable');
const localforage = lfo.extendPrototype(localForage);
localforage.newObservable.factory = (subscribeFn) => Observable.create(subscribeFn);

For some reason, the only combination of imports/requires that worked was the hybrid thing above.

@thgreasi Thanks for the great work!

from localforage-observable.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.