New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lowdb without lodash #109
Comments
Hi @davej, Thank you for the feedback and idea, it's always appreciated :) Is it related to If it's because you need to install lodash now, actually, lodash was always part of lowdb but was "hidden" in The only difference is now that it's explicit and you can have more control on lodash version used by lowdb. On the other side, the installation is a little less straightforward. So it may change, and I'm open to feedback. What's your context by the way? Browser or Node? |
It's just a general comment, not related to My context is Electron. I'm trying to trim down the Maybe I should be looking at using |
Ok I see, thank you for the explanations. One way would be to create a custom For example, generate a core build using const low = require('lowdb/lib/_index') // undocumented feature, may change without notice
const lodash = require('./lodash.custom.js')
const storage = require('./file-sync')
const db = low('db.json', { storage }, lodash) If it works for you, I could change lowdb API to make it easier to pass a lodash build. |
I don't know if I like the idea of adding a custom built lodash and then keeping it up-to-date outside of npm. Perhaps I could do something like this though: import runInContext from 'lodash/runInContext';
import get from 'lodash/get';
import chain from 'lodash/chain';
import wrap from 'lodash/wrap';
const db = low('db.json', { storage }, { runInContext, get, chain, wrap }); I'm using webpack so it will import only the included modules and I won't need to ship all of lodash with my app. A public API for passing a custom lodash would be great. |
I think you can keep it up-to-date, if you add it as a devDependency and include it in your build: $ npm install lodash-cli --save-dev {
"scripts": {
"build": "npm run lodash && npm run webpack",
"lodash": "lodash core",
}
} It will just be another part of your build and if you need to update I agree that using There's also |
Did some tests, and actually it doesn't seem to be that complicated to add methods dynamically. |
Excellent, will my example above work? |
I think so. You can already give it a try with the current version (feedback welcome ;)) const low = require('lowdb/lib/_index') // Undocumented feature, may change without notice
const lodash = require('lodash/core') // Smaller build
const storage = require('./file-sync')
// Add to core what you need
lodash.mixin({ get: require('lodash/get') }) // Add only one method
lodash.mixin({ get: require('lodash/set') })
lodash.mixin(require('lodash/array')) // Add all Array methods
const db = low('db.json', { storage }, lodash) I'm not yet settled on the API for lowdb. Maybe it's possible to require even less than |
Had no luck. This is what I tried: import low from 'lowdb/lib/_index';
import storage from 'lowdb/lib/file-async';
import lodash from 'lodash/core';
import lodashUtil from 'lodash/util'; // Should have `runInContext` func
lodash.mixin(lodashUtil);
const db = low('...', { storage }, lodash); And the error I get is |
Good to know, thank you. I tried with I'll release |
Getting there ;) there's 2 new "modes" in |
Ah cool. I ended up switching to electron-storage but I'll definitely take another look at lowdb when I'm working on a new project that needs persistence. Thanks for the great work! 👍 |
Is it already documented? |
Hi @bgbraga,
You can also use plain JavaScript functions with it too. There's also |
Done in v2 :) |
Just want to run this idea by you. I love
lowdb
but I have no need for thelodash
features at the moment so it just adds a ton of weight for me.What would you think about releasing the core
lowdb
as a separate module and the currentlowdb
can simply wrap the new core lib inlodash
.If that doesn't appeal to you then how about exposing a way for us to use
lowdb
without relying onlodash
? This might be as simple as adding anindex.light.js
which provides a mocked empty version oflodash
.These are just ideas, feel free to close this and keep doing what you're doing because
lowdb
is awesome! 👍The text was updated successfully, but these errors were encountered: