-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (39 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*!
* base-store <https://github.com/jonschlinkert/base-store>
*
* Copyright (c) 2015-2016, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var utils = require('./utils');
module.exports = function(name, config) {
if (typeof name !== 'string') {
config = name;
name = undefined;
}
return function plugin(app) {
if (!utils.isValid(app)) return;
// if `name` is not passed, get the project name
if (typeof name === 'undefined') {
name = utils.project(process.cwd());
}
var opts = utils.extend({}, config, app.options.store);
this.define('store', utils.store(name, opts));
/**
* Bubble up a few events to `app`
*/
this.store.on('set', function(key, val) {
app.emit('store.set', key, val);
app.emit('store', 'set', key, val);
});
this.store.on('get', function(key, val) {
app.emit('store.get', key, val);
app.emit('store', 'get', key, val);
});
this.store.on('del', function(key, val) {
app.emit('store.del', key, val);
app.emit('store', 'del', key, val);
});
return plugin;
};
};