Closed JonathanDDuncan closed 7 years ago
Hey @JonathanDDuncan! Thanks for reporting this issue!
Between v3 and v4 gun-level changed its api a bit, which might be the cause of the errors you're seeing here. The gist linked above was written for v3, thus all the hacky webpack ignore fs/wsp/lib grossness. Hopefully a working v4 implementation will be less code. I'm gonna try to reproduce this issue on my machine, but in the meantime this may help you move foward (assumes you're using gun-level v4.0.1
& gun v0.3.x
):
IgnorePlugin
and json-loader
if you like.index.js
file, level
now expects a level instance. For example:+ const leveldb = levelUp('my-database-name', {
+ db: require('fruitdown')
+ })
window.gun = new Gun({
- level: {
- // sets the "down" implementation
- down: require('fruitdown')
- }
+ level: leveldb
});
I'll hack at it on my end keep you in the loop.
So after playing around with it for a while, I got pieces of it working with indexedDB in the browser. I did actually need the json-loader in webpack for levelup
. I'm not sure yet why it was complaining.
Here's what the index.js
file looks like:
const Gun = require('gun/gun');
// Imported for side effects.
require('gun-level');
const levelUp = require('levelup');
const fruitdown = require('fruitdown');
const level = levelUp('my-database-name', {
db: fruitdown,
});
// So you can experiment in the browser.
window.gun = new Gun({ level: level });
The revised webpack file:
module.exports = {
entry: './index.js',
output: { filename: 'bundle.js' },
module: {
loaders: [{
test: /\.json$/,
loader: 'json',
}],
},
};
The dependencies I needed to get it "working":
npm install --save-dev webpack json-loader
npm install --save gun gun-level levelup fruitdown
There's two issues I've noticed though.
localStorage
in addition to indexedDB. @amark, is there a way to disable localStorage per-instance?I need to do more digging to see if the issue is with how it's configured, the gun-level plugin, or with gun itself.
Probably not gonna happen tonight, but I'll do my best to get it resolved soon. Once again, thanks for reporting this!
For convenience I've attached a zip of my working files. gun-level-fruitdown.zip
Hi @PsychoLlama thank for taking a look at it. I tried out the zip file you attached and it works!! Still have to get it working with my app setup. But that will be for another day.
I am seeing the same issues with the data being saved to local storage too. Also the fakekey in the indexedDB without the real data.
Thanks Jonathan
Woohoo, glad it helped! I'm probably gonna take another look at it tonight and figure out why not all the data is saved.
Some of the reasons I wanted to save to IndexedDb was so that I could have more space for saving. But if the data isn't actually saved to IndexedDb just the keys, and localstorage is still being used. Then I expect if I do a big enough of a project I would still run out of space in localstorage even though I could still save tons more to IndexedDb. ;-(
I haven't actually run out of space yet with localstorage but want to be on the safe side.
Did you have a chance to look at the code?
Jonathan
Hey @JonathanDDuncan, sorry for the delay! I've dug into the code and added all sorts of log statements. I am now enlightened. Turns out all the data is actually making it to IndexedDB! It's a full replica of what's in localStorage. Sadly, after digging around in the gun source code, it doesn't look like you can disable localStorage.
For now, I'm using localStorage.clear()
before loading the bundle, though naturally that might not suite your needs. I'll pester @amark about an option to disable it.
Here's the updated example code: gun-level-idb.zip
I came across your example https://gist.github.com/PsychoLlama/5894445f48254f6f3f00
and added modified my create-elm-app to run parts of your example as I couldn't get it to run directly.
in index.js I have
and I added
to my pluggins
I am getting the following error in the console.
I'm not sure what the problem could be.