scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

Persist changes in postValidate and preSave hooks to database [#43] #85

Closed caseyWebb closed 7 years ago

caseyWebb commented 7 years ago

Changes made in postValidate and preSave hooks were not being persisted; now they are :tada:

Also FWIW, besides semantics, there seems to me to be no noticeable between the two hooks.

This...

  // ...
  return Promise.all(that._getHookPromises('postValidate'));
}).then(function() {
  return Promise.all(that._getHookPromises('preSave'));
}).then(function() {
  // ...

could be changed to something like...

return Promise.all(_.compose(_.flatten, _.map)(['postValidate', 'preSave'], function(hookName) {
  return that._getHookPromises(hookName);
}))

...which isn't all that great, but can turn into this...

return Promise.all(_.flatMap(['postValidate', 'preSave'], (h) => this._getHookPromises(h)))

arrow funcs <3 fp & promises, their lack of lexical binding prevents the need for var that = this in nearly every case

[x-ref #43]

scottwrobinson commented 7 years ago

Looks good from what I can tell. Should have time to get to this tonight or tomorrow morning. Thanks for the PR!

caseyWebb commented 7 years ago

🍻