ee-core 1.5.2-beta.1 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/addon/window/index.js +91 -91
  4. package/bin/tools.js +18 -18
  5. package/config/config.default.js +287 -280
  6. package/core/index.js +12 -12
  7. package/core/lib/ee.js +218 -218
  8. package/core/lib/loader/context_loader.js +106 -106
  9. package/core/lib/loader/ee_loader.js +461 -457
  10. package/core/lib/loader/file_loader.js +325 -325
  11. package/core/lib/loader/mixin/addon.js +32 -32
  12. package/core/lib/loader/mixin/config.js +135 -135
  13. package/core/lib/loader/mixin/controller.js +125 -124
  14. package/core/lib/loader/mixin/service.js +28 -28
  15. package/core/lib/utils/base_context_class.js +34 -34
  16. package/core/lib/utils/function.js +30 -0
  17. package/core/lib/utils/index.js +127 -127
  18. package/core/lib/utils/sequencify.js +59 -59
  19. package/core/lib/utils/timing.js +77 -77
  20. package/index.js +49 -49
  21. package/lib/appLoader.js +48 -53
  22. package/lib/application.js +85 -84
  23. package/lib/baseApp.js +114 -131
  24. package/lib/eeApp.js +325 -359
  25. package/{lib/constant.js → module/const/index.js} +12 -9
  26. package/{lib/httpclient.js → module/httpclient/index.js} +170 -136
  27. package/module/jobs/child/forkProcess.js +99 -0
  28. package/module/jobs/child/index.js +33 -0
  29. package/module/jobs/index.js +55 -0
  30. package/module/jobs/renderer/index.js +140 -0
  31. package/module/jobs/renderer/loadView.js +40 -0
  32. package/module/loader/index.js +78 -0
  33. package/module/log/index.js +53 -0
  34. package/module/log/logger.js +61 -0
  35. package/module/message/index.js +13 -0
  36. package/module/message/ipcMain.js +160 -0
  37. package/module/message/ipcRender.js +0 -0
  38. package/{lib → module}/socket/httpServer.js +142 -142
  39. package/{lib → module}/socket/io.js +23 -23
  40. package/{lib → module}/socket/ipcServer.js +106 -108
  41. package/{lib → module}/socket/socketClient.js +51 -50
  42. package/{lib → module}/socket/socketServer.js +77 -76
  43. package/module/socket/start.js +22 -0
  44. package/{lib → module}/storage/index.js +35 -34
  45. package/module/storage/jsondb/adapters/Base.js +14 -0
  46. package/module/storage/jsondb/adapters/FileSync.js +32 -0
  47. package/{lib/storage/lowdb → module/storage/jsondb}/main.js +42 -46
  48. package/{lib/storage/lowdbStorage.js → module/storage/jsondbStorage.js} +98 -99
  49. package/{lib → module}/storage/sqliteStorage.js +123 -127
  50. package/module/utils/copyto.js +161 -0
  51. package/module/utils/helper.js +117 -0
  52. package/module/utils/index.js +120 -0
  53. package/module/utils/json.js +72 -0
  54. package/module/utils/ps.js +175 -0
  55. package/{utils → module/utils}/wrap.js +35 -37
  56. package/package.json +44 -48
  57. package/tools/encrypt.js +274 -274
  58. package/tools/replaceDist.js +61 -61
  59. package/utils/index.js +128 -246
  60. package/lib/logger.js +0 -47
  61. package/lib/socket/start.js +0 -22
  62. package/lib/storage/lowdb/adapters/Base.js +0 -15
  63. package/lib/storage/lowdb/adapters/FileAsync.js +0 -41
  64. package/lib/storage/lowdb/adapters/FileSync.js +0 -39
  65. package/lib/storage/lowdb/adapters/LocalStorage.js +0 -20
  66. package/lib/storage/lowdb/adapters/Memory.js +0 -8
  67. package/lib/storage/lowdb/adapters/_stringify.js +0 -4
  68. package/lib/storage/lowdb/common.js +0 -33
  69. package/lib/storage/lowdb/fp.js +0 -23
  70. package/lib/storage/lowdb/is-promise.js +0 -6
  71. package/lib/storage/lowdb/nano.js +0 -5
  72. package/utils/common.js +0 -91
@@ -1,61 +1,61 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const fsPro = require('fs-extra');
6
-
7
- /**
8
- * 资源替换
9
- */
10
-
11
- module.exports = {
12
-
13
- /**
14
- * 执行
15
- */
16
- run () {
17
- console.log('[ee-core] [replace_dist] 开始移动资源');
18
- const homeDir = process.cwd();
19
-
20
- // argv
21
- let distDir = '';
22
- for (let i = 0; i < process.argv.length; i++) {
23
- let tmpArgv = process.argv[i]
24
- if (tmpArgv.indexOf('--dist_dir=') !== -1) {
25
- distDir = tmpArgv.substring(11)
26
- }
27
- }
28
-
29
- const fileExist = (filePath) => {
30
- try {
31
- return fs.statSync(filePath).isFile();
32
- } catch (err) {
33
- console.error('[ee-core] [replace_dist] ERROR ', err);
34
- return false;
35
- }
36
- };
37
-
38
- const sourceDir = path.join(homeDir, distDir);
39
- const sourceIndexFile = path.join(sourceDir, 'index.html');
40
-
41
- if (!fileExist(sourceIndexFile)) {
42
- console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
43
- return
44
- }
45
-
46
- // 复制到ee资源目录
47
- const eeResourceDir = path.join(homeDir, 'public', 'dist');
48
-
49
- // 清空历史资源
50
- fs.rmdirSync(eeResourceDir, {recursive: true});
51
- console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
52
-
53
- fsPro.copySync(sourceDir, eeResourceDir);
54
- console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
55
-
56
- console.log('[ee-core] [replace_dist] 结束');
57
- }
58
- }
59
-
60
-
61
-
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const fsPro = require('fs-extra');
6
+
7
+ /**
8
+ * 资源替换
9
+ */
10
+
11
+ module.exports = {
12
+
13
+ /**
14
+ * 执行
15
+ */
16
+ run () {
17
+ console.log('[ee-core] [replace_dist] 开始移动资源');
18
+ const homeDir = process.cwd();
19
+
20
+ // argv
21
+ let distDir = '';
22
+ for (let i = 0; i < process.argv.length; i++) {
23
+ let tmpArgv = process.argv[i]
24
+ if (tmpArgv.indexOf('--dist_dir=') !== -1) {
25
+ distDir = tmpArgv.substring(11)
26
+ }
27
+ }
28
+
29
+ const fileExist = (filePath) => {
30
+ try {
31
+ return fs.statSync(filePath).isFile();
32
+ } catch (err) {
33
+ console.error('[ee-core] [replace_dist] ERROR ', err);
34
+ return false;
35
+ }
36
+ };
37
+
38
+ const sourceDir = path.join(homeDir, distDir);
39
+ const sourceIndexFile = path.join(sourceDir, 'index.html');
40
+
41
+ if (!fileExist(sourceIndexFile)) {
42
+ console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
43
+ return
44
+ }
45
+
46
+ // 复制到ee资源目录
47
+ const eeResourceDir = path.join(homeDir, 'public', 'dist');
48
+
49
+ // 清空历史资源
50
+ fs.rmdirSync(eeResourceDir, {recursive: true});
51
+ console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
52
+
53
+ fsPro.copySync(sourceDir, eeResourceDir);
54
+ console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
55
+
56
+ console.log('[ee-core] [replace_dist] 结束');
57
+ }
58
+ }
59
+
60
+
61
+
package/utils/index.js CHANGED
@@ -1,247 +1,129 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const constant = require('../lib/constant');
5
- const convert = require('koa-convert');
6
- const is = require('is-type-of');
7
- const co = require('co');
8
- const utility = require('utility');
9
- const eis = require('electron-is');
10
- const utilsCommon = require('./common');
11
-
12
- /**
13
- * 创建文件夹
14
- */
15
- exports.mkdir = function (dirpath, dirname) {
16
- return utilsCommon.mkdir(dirpath, dirname);
17
- }
18
-
19
- /**
20
- * 修改文件权限
21
- */
22
- exports.chmodPath = function (path, mode) {
23
- return utilsCommon.chmodPath(path, mode);
24
- }
25
-
26
- /**
27
- * 获取项目根目录package.json
28
- */
29
- exports.getPackage = function() {
30
- const cdb = this.getCoreDB();
31
- const config = cdb.getItem('config');
32
- const json = utility.readJSONSync(path.join(config.homeDir, 'package.json'));
33
-
34
- return json;
35
- };
36
-
37
- /**
38
- * 获取 coredb
39
- */
40
- exports.getCoreDB = function() {
41
- const coreDB = require('../lib/storage/index').JsonDB.connection('system');
42
- return coreDB;
43
- }
44
-
45
- /**
46
- * 获取 当前环境
47
- */
48
- exports.getEnv = function() {
49
- const cdb = this.getCoreDB();
50
- const env = cdb.getItem('config').env;
51
-
52
- return env;
53
- }
54
-
55
- /**
56
- * 获取 ee配置
57
- */
58
- exports.getEeConfig = function() {
59
- const cdb = this.getCoreDB();
60
- const config = cdb.getItem('config');
61
-
62
- return config;
63
- }
64
-
65
- /**
66
- * 获取 数据库存储路径
67
- */
68
- exports.getStorageDir = function() {
69
- const cdb = this.getCoreDB();
70
- const env = cdb.getItem('config').env;
71
-
72
- const appDir = env === 'local' || env === 'unittest' ? this.getHomeDir() : this.getAppUserDataDir();
73
- const storageDir = path.join(appDir, 'data');
74
-
75
- return storageDir;
76
- }
77
-
78
- /**
79
- * 获取 应用程序数据目录 (开发环境时,为项目根目录)
80
- */
81
- exports.getAppUserDataDir = function() {
82
- const cdb = this.getCoreDB();
83
- const config = cdb.getItem('config');
84
- const env = config.env;
85
- const dir = env === 'local' || env === 'unittest' ? config.homeDir : config.appUserDataDir;
86
- return dir;
87
- }
88
-
89
- /**
90
- * 获取 日志目录
91
- */
92
- exports.getLogDir = function() {
93
- const cdb = this.getCoreDB();
94
- const logPath = cdb.getItem('config').logger.dir;
95
- return logPath;
96
- }
97
-
98
- /**
99
- * 获取 home目录
100
- */
101
- exports.getHomeDir = function() {
102
- const cdb = this.getCoreDB();
103
- const homePath = cdb.getItem('config').homeDir;
104
- return homePath;
105
- }
106
-
107
- /**
108
- * 获取 base目录
109
- */
110
- exports.getBaseDir = function() {
111
- const cdb = this.getCoreDB();
112
- const basePath = cdb.getItem('config').baseDir;
113
- return basePath;
114
- }
115
-
116
- /**
117
- * 获取 root目录
118
- */
119
- exports.getRootDir = function() {
120
- const cdb = this.getCoreDB();
121
- const rootPath = cdb.getItem('config').root;
122
- return rootPath;
123
- }
124
-
125
- /**
126
- * 获取 appUserData目录
127
- */
128
- exports.getAppUserDataDir = function() {
129
- const cdb = this.getCoreDB();
130
- const dataPath = cdb.getItem('config').appUserDataDir;
131
- return dataPath;
132
- }
133
-
134
- /**
135
- * 获取 app version
136
- */
137
- exports.getAppVersion = function() {
138
- const cdb = this.getCoreDB();
139
- const v = cdb.getItem('config').appVersion;
140
- return v;
141
- }
142
-
143
- /**
144
- * 获取 exec目录
145
- */
146
- exports.getExecDir = function() {
147
- const cdb = this.getCoreDB();
148
- const execPath = cdb.getItem('config').execDir;
149
- return execPath;
150
- }
151
-
152
- /**
153
- * 获取 插件配置
154
- */
155
- exports.getAddonConfig = function() {
156
- const cdb = this.getCoreDB();
157
- const cfg = cdb.getItem('config').addons;
158
- return cfg;
159
- }
160
-
161
- /**
162
- * 获取 mainServer配置
163
- */
164
- exports.getMainServerConfig = function() {
165
- const cdb = this.getCoreDB();
166
- const cfg = cdb.getItem('config').mainServer;
167
- return cfg;
168
- }
169
-
170
- /**
171
- * 获取 httpServer配置
172
- */
173
- exports.getHttpServerConfig = function() {
174
- const cdb = this.getCoreDB();
175
- const cfg = cdb.getItem('config').httpServer;
176
- return cfg;
177
- }
178
-
179
- /**
180
- * 获取 socketServer配置
181
- */
182
- exports.getSocketServerConfig = function() {
183
- const cdb = this.getCoreDB();
184
- const cfg = cdb.getItem('config').socketServer;
185
- return cfg;
186
- }
187
-
188
- /**
189
- * 获取 socketio port
190
- */
191
- exports.getSocketPort = function() {
192
- const cdb = this.getCoreDB();
193
- const port = cdb.getItem('config').socketServer.port;
194
- return parseInt(port);
195
- }
196
-
197
- /**
198
- * 获取 socket channel
199
- */
200
- exports.getSocketChannel = function() {
201
- return constant.socketIo.channel;
202
- }
203
-
204
- /**
205
- * 获取 额外资源目录
206
- */
207
- exports.getExtraResourcesDir = function() {
208
- const cdb = this.getCoreDB();
209
- const config = cdb.getItem('config');
210
- const execDir = config.execDir;
211
-
212
- // 资源路径不同
213
- let dir = '';
214
- if (config.isPackaged) {
215
- // 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
216
- // windows和MacOs不一样
217
- dir = path.join(execDir, "resources", "extraResources");
218
- if (eis.macOS()) {
219
- dir = path.join(execDir, "..", "Resources", "extraResources");
220
- }
221
- } else {
222
- // 打包前
223
- dir = path.join(execDir, "build", "extraResources");
224
- }
225
- return dir;
226
- }
227
-
228
- /**
229
- * 执行一个函数
230
- */
231
- exports.callFn = async function (fn, args, ctx) {
232
- args = args || [];
233
- if (!is.function(fn)) return;
234
- if (is.generatorFunction(fn)) fn = co.wrap(fn);
235
- return ctx ? fn.call(ctx, ...args) : fn(...args);
236
- }
237
-
238
- exports.middleware = function (fn) {
239
- return is.generatorFunction(fn) ? convert(fn) : fn;
240
- }
241
-
242
- /**
243
- * 版本号比较
244
- */
245
- exports.compareVersion = function (v1, v2) {
246
- return utilsCommon.compareVersion(v1, v2);
1
+ /**
2
+ * 该模块不在增加新功能,请使用 /module/utils/index 模块
3
+ */
4
+
5
+ const path = require('path');
6
+ const eis = require('electron-is');
7
+ const UtilsJson = require('../module/utils/json');
8
+ const UtilsPs = require('../module/utils/ps');
9
+ const UtilsHelper = require('../module/utils/helper');
10
+ const Copy = require('../module/utils/copyto');
11
+ const Storage = require('../module/storage');
12
+ const Constants = require('../module/const');
13
+
14
+ /**
15
+ * other module
16
+ */
17
+ Copy(UtilsPs)
18
+ .and(UtilsHelper)
19
+ .to(exports);
20
+
21
+ /**
22
+ * 获取项目根目录package.json
23
+ */
24
+ exports.getPackage = function() {
25
+ const json = UtilsJson.readSync(path.join(this.getHomeDir(), 'package.json'));
26
+
27
+ return json;
28
+ };
29
+
30
+ /**
31
+ * 获取 coredb
32
+ */
33
+ exports.getCoreDB = function() {
34
+ const coreDB = Storage.connection('system');
35
+ return coreDB;
36
+ }
37
+
38
+ /**
39
+ * 获取 ee配置
40
+ */
41
+ exports.getEeConfig = function() {
42
+ const cdb = this.getCoreDB();
43
+ const config = cdb.getItem('config');
44
+
45
+ return config;
46
+ }
47
+
48
+ /**
49
+ * 获取 app version
50
+ */
51
+ exports.getAppVersion = function() {
52
+ const cdb = this.getCoreDB();
53
+ const v = cdb.getItem('config').appVersion;
54
+ return v;
55
+ }
56
+
57
+ /**
58
+ * 获取 插件配置
59
+ */
60
+ exports.getAddonConfig = function() {
61
+ const cdb = this.getCoreDB();
62
+ const cfg = cdb.getItem('config').addons;
63
+ return cfg;
64
+ }
65
+
66
+ /**
67
+ * 获取 mainServer配置
68
+ */
69
+ exports.getMainServerConfig = function() {
70
+ const cdb = this.getCoreDB();
71
+ const cfg = cdb.getItem('config').mainServer;
72
+ return cfg;
73
+ }
74
+
75
+ /**
76
+ * 获取 httpServer配置
77
+ */
78
+ exports.getHttpServerConfig = function() {
79
+ const cdb = this.getCoreDB();
80
+ const cfg = cdb.getItem('config').httpServer;
81
+ return cfg;
82
+ }
83
+
84
+ /**
85
+ * 获取 socketServer配置
86
+ */
87
+ exports.getSocketServerConfig = function() {
88
+ const cdb = this.getCoreDB();
89
+ const cfg = cdb.getItem('config').socketServer;
90
+ return cfg;
91
+ }
92
+
93
+ /**
94
+ * 获取 socketio port
95
+ */
96
+ exports.getSocketPort = function() {
97
+ const cdb = this.getCoreDB();
98
+ const port = cdb.getItem('config').socketServer.port;
99
+ return parseInt(port);
100
+ }
101
+
102
+ /**
103
+ * 获取 socket channel
104
+ */
105
+ exports.getSocketChannel = function() {
106
+ return Constants.socketIo.channel;
107
+ }
108
+
109
+ /**
110
+ * 获取 额外资源目录
111
+ */
112
+ exports.getExtraResourcesDir = function() {
113
+ const execDir = this.getExecDir();
114
+
115
+ // 资源路径不同
116
+ let dir = '';
117
+ if (config.isPackaged) {
118
+ // 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
119
+ // windows和MacOs不一样
120
+ dir = path.join(execDir, "resources", "extraResources");
121
+ if (eis.macOS()) {
122
+ dir = path.join(execDir, "..", "Resources", "extraResources");
123
+ }
124
+ } else {
125
+ // 打包前
126
+ dir = path.join(execDir, "build", "extraResources");
127
+ }
128
+ return dir;
247
129
  }
package/lib/logger.js DELETED
@@ -1,47 +0,0 @@
1
- 'use strict';
2
-
3
- const debug = require('debug')('ee-core:logger');
4
- const Loggers = require('egg-logger').EggLoggers;
5
- const assert = require('assert');
6
-
7
- class Logger {
8
- constructor (config) {
9
- debug('Loaded logger');
10
- assert(Object.keys(config).length != 0, `logger config is null`);
11
- this.eggLogger = this.init(config);
12
- }
13
-
14
- /**
15
- * 单例
16
- */
17
- static getInstance (config = {}) {
18
- if (typeof this.instance === 'object') {
19
- return this.instance.eggLogger;
20
- }
21
-
22
- this.instance = new Logger(config);
23
-
24
- // 返回egg-logger实例
25
- return this.instance.eggLogger;
26
- }
27
-
28
- /**
29
- * 初始化模块
30
- */
31
- init(config) {
32
- const loggerConfig = config.logger;
33
- loggerConfig.type = 'application'; // application、agent
34
-
35
- if (config.env === 'prod' && loggerConfig.level === 'DEBUG' && !loggerConfig.allowDebugAtProd) {
36
- loggerConfig.level = 'INFO';
37
- }
38
-
39
- const loggers = new Loggers(config);
40
-
41
- loggers.coreLogger.info('[ee-core:logger] init all loggers with options: %j', loggerConfig);
42
-
43
- return loggers;
44
- };
45
- }
46
-
47
- module.exports = Logger;
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- const socketServer = require('./socketServer');
4
- const ipcServer = require('./ipcServer');
5
- const httpServer = require('./httpServer');
6
-
7
- /**
8
- * server
9
- */
10
- module.exports = (app) => {
11
-
12
- // 启动 socket server
13
- new socketServer(app);
14
-
15
- // 启动 http server
16
- new httpServer(app);
17
-
18
- // 启动 electron ipc server
19
- new ipcServer(app);
20
-
21
- }
22
-
@@ -1,15 +0,0 @@
1
- const stringify = require('./_stringify')
2
-
3
- class Base {
4
- constructor(
5
- source,
6
- { defaultValue = {}, serialize = stringify, deserialize = JSON.parse } = {}
7
- ) {
8
- this.source = source
9
- this.defaultValue = defaultValue
10
- this.serialize = serialize
11
- this.deserialize = deserialize
12
- }
13
- }
14
-
15
- module.exports = Base
@@ -1,41 +0,0 @@
1
- // Not using async/await on purpose to avoid adding regenerator-runtime
2
- // to lowdb dependencies
3
- const fs = require('graceful-fs')
4
- const pify = require('pify')
5
- const steno = require('steno')
6
- const Base = require('./Base')
7
-
8
- const readFile = pify(fs.readFile)
9
- const writeFile = pify(steno.writeFile)
10
-
11
- class FileAsync extends Base {
12
- read() {
13
- // fs.exists is deprecated but not fs.existsSync
14
- if (fs.existsSync(this.source)) {
15
- // Read database
16
- return readFile(this.source, 'utf-8')
17
- .then(data => {
18
- // Handle blank file
19
- const trimmed = data.trim()
20
- return trimmed ? this.deserialize(trimmed) : this.defaultValue
21
- })
22
- .catch(e => {
23
- if (e instanceof SyntaxError) {
24
- e.message = `Malformed JSON in file: ${this.source}\n${e.message}`
25
- }
26
- throw e
27
- })
28
- } else {
29
- // Initialize
30
- return writeFile(this.source, this.serialize(this.defaultValue)).then(
31
- () => this.defaultValue
32
- )
33
- }
34
- }
35
-
36
- write(data) {
37
- return writeFile(this.source, this.serialize(data))
38
- }
39
- }
40
-
41
- module.exports = FileAsync
@@ -1,39 +0,0 @@
1
- const fs = require('graceful-fs')
2
- const Base = require('./Base')
3
- const fileSystem = require('fs')
4
-
5
- //const readFile = fs.readFileSync
6
- const writeFile = fs.writeFileSync
7
-
8
- // Same code as in FileAsync, minus `await`
9
- class FileSync extends Base {
10
- read() {
11
- // fs.exists is deprecated but not fs.existsSync
12
- if (fs.existsSync(this.source)) {
13
- // Read database
14
- try {
15
- // 使用 fileSystem的readFileSync
16
- //const data = readFile(this.source, 'utf-8').trim()
17
- const data = fileSystem.readFileSync(this.source, {encoding: 'utf-8'})
18
-
19
- // Handle blank file
20
- return data ? this.deserialize(data) : this.defaultValue
21
- } catch (e) {
22
- if (e instanceof SyntaxError) {
23
- e.message = `Malformed JSON in file: ${this.source}\n${e.message}`
24
- }
25
- throw e
26
- }
27
- } else {
28
- // Initialize
29
- writeFile(this.source, this.serialize(this.defaultValue))
30
- return this.defaultValue
31
- }
32
- }
33
-
34
- write(data) {
35
- return writeFile(this.source, this.serialize(data))
36
- }
37
- }
38
-
39
- module.exports = FileSync
@@ -1,20 +0,0 @@
1
- /* global localStorage */
2
- const Base = require('./Base')
3
-
4
- class LocalStorage extends Base {
5
- read() {
6
- const data = localStorage.getItem(this.source)
7
- if (data) {
8
- return this.deserialize(data)
9
- } else {
10
- localStorage.setItem(this.source, this.serialize(this.defaultValue))
11
- return this.defaultValue
12
- }
13
- }
14
-
15
- write(data) {
16
- localStorage.setItem(this.source, this.serialize(data))
17
- }
18
- }
19
-
20
- module.exports = LocalStorage