fp.js 597 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var flow = require('lodash/flow');
  3. var get = require('lodash/get');
  4. var set = require('lodash/set');
  5. var common = require('./common');
  6. module.exports = function (adapter) {
  7. function db(path, defaultValue) {
  8. function getValue(funcs) {
  9. var result = get(db.getState(), path, defaultValue);
  10. return flow(funcs)(result);
  11. }
  12. getValue.write = function () {
  13. var result = getValue.apply(undefined, arguments);
  14. set(db.getState(), path, result);
  15. return db.write();
  16. };
  17. return getValue;
  18. }
  19. return common.init(db, '__state__', adapter);
  20. };