Skip to content
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

Suggesting an autosave option #28

Closed
fritx opened this issue Nov 29, 2014 · 7 comments
Closed

Suggesting an autosave option #28

fritx opened this issue Nov 29, 2014 · 7 comments

Comments

@fritx
Copy link

fritx commented Nov 29, 2014

// Compose every function with fn
function composeAll(obj, fn) {
  for (var key in obj) {
    if (_.isFunction(obj[key])) {
      obj[key] = _.compose(fn, obj[key])
    }
  }
}

Hey, I doubt the composing on all functions including irrelevant ones (like isRegExp)
Shall we pick out the ones?
Or give it an autosave option which defaults to true, like:

var db = low(filename, { autosave: false })
@typicode
Copy link
Owner

typicode commented Dec 2, 2014

Picking out the ones irrelevant, why not, it'll improve performances. However, when Node 0.12 will be out (no date though), it should be possible to listen to object changes with Object.observe so I don't know if it's very useful to implement right now.

Regarding the autosave, you can already but it's not very beautiful:

var db = low() // no filename, so there's no autosave
fs.writeFileSync(filename, JSON.stringify(db.object))

I think about making something like what you suggested:

var db = low(filename, { autosave: false })
db.save()
// or
var db = low()
db.save(filename)

@fritx
Copy link
Author

fritx commented Dec 2, 2014

Oh you're right.. :)
If you're not free, I'm glad to PR

@typicode
Copy link
Owner

typicode commented Dec 2, 2014

It's okay, thanks for the offer and the feedback :)
I think I'll release today.

@typicode
Copy link
Owner

typicode commented Dec 2, 2014

Just published v0.6.0 :)
It includes autosave option and I've added db.saveSync() for more flexibility.

var db = low(filename, { autosave: false })
db.saveSync()
var db = low()
db.saveSync(filename)

Both examples will do the same.

@fritx
Copy link
Author

fritx commented Dec 3, 2014

👍 I see the change, async defaults to true too, thanks

@fritx fritx closed this as completed Dec 3, 2014
@typicode
Copy link
Owner

typicode commented Feb 3, 2015

Hi,

Just as an update, I've released 0.7.0 and now it only writes to disk when db has changed (not composing every functions anymore :)).

Also, it has been updated to lodash 3.0.0.

@fritx
Copy link
Author

fritx commented Feb 4, 2015

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants