Comments (19)
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.
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.
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.
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.
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.
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.
v1.0.0 is working
from localforage-observable.
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.
It seems to work on the browser even on other instances, I will check it out on an Ionic project tonight.
from localforage-observable.
Well it isn't using imports and thats the problem :D
from localforage-observable.
Just released v1.1.1 that should fix the window
error. Starting writing the Typings now. Any confirmation would be appreciated.
from localforage-observable.
Will check tomorrow, thanks!
from localforage-observable.
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.
Also, I can confirm that I no longer have the window
error with v1.1.1
from localforage-observable.
@jloosli Thanks for the instant feeback 👍
I'm think I will be able to release v1.2.0 tomorrow.
from localforage-observable.
I just opened #11 that hopefully resolves this and #9.
Any feedback will be appreciated.
from localforage-observable.
@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.
Just released v1.2.0.
Readme now also points to an example Ionic 2 project.
from localforage-observable.
@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)
- Implement a getItemObservable method
- Error Building on Ionic 2 HOT 3
- clear() doesn't trigger event HOT 6
- Support for localforage instances HOT 1
- ReferenceError: Observable is not defined HOT 2
- I'm interested in what this adds to localForage's promise based api? HOT 1
- ReferenceError: Observable is not defined HOT 2
- IE 11 toString - Invalid calling object HOT 4
- [Feature Request] Provide a way to customize cross tab observer implementation
- [Question] Observe this same store from different instances
- How to install / what's the npm package name?
- How to merge multiple observables in to one? HOT 7
- localforage.setItem in a promise won't fire Observable with rxjs HOT 14
- Add support for cross-tab notifications HOT 10
- Fix import window from 'window' error HOT 1
- Add proper Typings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from localforage-observable.