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