Comments (6)
Thanks for flagging this Ryan.
As it is a callback that cFun looks like it was meant to be a
cFun.call(null, data);
Would you be able to test if that works? I won't be in front of a pc for
a few days and this seems a pretty major bug.
joe
On 08/01/15 22:32, Ryan wrote:
To verify that this was an issue, I made a simple index.html file w/
the following code (taken from the docs)var db = new loki('test', { env: 'BROWSER'}), db2 = new loki('test', { env: 'BROWSER'}); var users = db.addCollection('users'); users.insert({ name: 'joe' }); users.insert({ name: 'john' }); users.insert({ name: 'jack' }); console.log(users.data); db.saveDatabase(); db2.loadDatabase(function () { var users2 = db2.getCollection('users') console.log(users2.data); });
|loadDatabase| breaks in the following code snippet (which exists in
two areas):if (localStorageAvailable()) { self.loadJSON(localStorage.getItem(this.filename)); cFun(null, data); } else { cFun(new Error('localStorage is not available')); }
Data is undefined and an error is thrown. I've verified that removing
data from the callback resolves the issue.—
Reply to this email directly or view it on GitHub
#56.
from lokijs.
That alone didn't work. Data being undefined but referenced like a global variable still causes that nasty error to get thrown.
Assuming that you want the localStorage / BROWSER version to work just like the NODEJS version, the following
var data = localStorage.getItem(this.filename);
self.loadJSON(data, options || {});
cFun.call(null, data);
worked fine and may suffice as a solution.
from lokijs.
If you want to submit a PR i'm happy for you to get the credit for it.
Otherwise I'll see if @obeliskos has time to address this.
On Thu, Jan 8, 2015 at 10:53 PM, Ryan [email protected] wrote:
That alone didn't work. Data being undefined but referenced like a global
variable still causes that nasty error to get thrown.Assuming that you want the localStorage / BROWSER version to work just
like the NODEJS version, the followingvar data = localStorage.getItem(this.filename); self.loadJSON(data, options || {}); cFun.call(null, data);
worked fine and may suffice as a solution.
—
Reply to this email directly or view it on GitHub
#56 (comment).
from lokijs.
PR Submitted. Thanks!
from lokijs.
I needed to modify the call to just cFun(null, data) instead of the cFun.call which appears to treat the first param as a 'this' context before mapping the other args so the data was being mapped to err. I suppose we could have just passed this as first param but I don't know that we need that context to a user function.
from lokijs.
Re-opening to allow time for all to review changes
from lokijs.
Related Issues (20)
- Corrupted idIndex and $loki value HOT 1
- [Question] Subscribe: performance and efficiency HOT 3
- Incorrect implementation of `getObjectDelta`
- Incorrect implementation of `ResultSet.update`
- TTL options of Collections do not persist (re-open #626)
- Is this project dead? HOT 14
- Incorrect implementation of unit test of `immutable`
- Incorrect implementation of `inflate`
- `simpleSort` with `useJavascriptSorting` don't support `dotNotation`
- Unit test of `persistence` is not correctly implemented
- `compoundEval` is not correctly implemented
- The unit test of `sotringIndexing` is not correctly implemented
- The unit test of `test` is not correctly implemented
- Error: this collection cannot be loaded lazily HOT 2
- Use https in description
- [Question] Reload database / cancel changes HOT 2
- Feature Request: IPFS Adapter HOT 1
- clone is required to use pre-update HOT 1
- 'Leave a tip" link is broken
- Failed to add collection:', [Error: ensureNotFalsy() is falsy] 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 lokijs.