pubo-node 1.0.131 → 1.0.137

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.
@@ -139,8 +139,9 @@ var fs_1 = require("fs");
139
139
  var pubo_utils_1 = require("pubo-utils");
140
140
  var uuid_1 = require("uuid");
141
141
  var cluster = require('cluster');
142
+ // 主线程的实现
142
143
  var Manager = /** @class */function () {
143
- function Manager(path) {
144
+ function Manager(path, defaultState) {
144
145
  var _this = this;
145
146
  this._state = {};
146
147
  this.queue = new pubo_utils_1.SyncQueue();
@@ -169,6 +170,7 @@ var Manager = /** @class */function () {
169
170
  payload = _a.sent();
170
171
  return [3 /*break*/, 4];
171
172
  case 2:
173
+ if (!(message.type === 'set')) return [3 /*break*/, 4];
172
174
  return [4 /*yield*/, this.setState(message.payload)];
173
175
  case 3:
174
176
  payload = _a.sent();
@@ -220,6 +222,7 @@ var Manager = /** @class */function () {
220
222
  });
221
223
  };
222
224
  Manager.prototype.restore = function () {
225
+ var _a;
223
226
  try {
224
227
  var buf = (0, fs_1.readFileSync)(this.path);
225
228
  this._state = JSON.parse(buf.toString());
@@ -230,7 +233,7 @@ var Manager = /** @class */function () {
230
233
  recursive: true
231
234
  });
232
235
  }
233
- this._state = {};
236
+ this.setState((_a = this.defaultState) !== null && _a !== void 0 ? _a : {});
234
237
  }
235
238
  };
236
239
  Manager.prototype.getState = function () {
@@ -257,6 +260,7 @@ var Manager = /** @class */function () {
257
260
 
258
261
  return Manager;
259
262
  }();
263
+ // work 线程的实现
260
264
  var Worker = /** @class */function () {
261
265
  function Worker(path) {
262
266
  this.callback = {};
@@ -318,13 +322,8 @@ var Worker = /** @class */function () {
318
322
  }();
319
323
  var JsonStorage = /** @class */function () {
320
324
  function JsonStorage(path, options) {
321
- if (options === void 0) {
322
- options = {
323
- initialState: null
324
- };
325
- }
326
325
  if (cluster.isPrimary) {
327
- this.instance = new Manager(path);
326
+ this.instance = new Manager(path, options.defaultState);
328
327
  } else {
329
328
  this.instance = new Worker(path);
330
329
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-node",
3
- "version": "1.0.131",
3
+ "version": "1.0.137",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "pubo-utils": "^1.0.129",
25
25
  "tree-kill": "^1.2.2"
26
26
  },
27
- "gitHead": "7b0e1e2da74f408b6a1746a866780673eada6c8f",
27
+ "gitHead": "07377a440e5cf7e69bdeb5e646e96b9437e9bb2f",
28
28
  "devDependencies": {
29
29
  "@babel/cli": "^7.10.1",
30
30
  "@babel/core": "^7.10.2",