@pisell/pisellos 0.0.19 → 0.0.20

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.
@@ -1,7 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { AccountModule, Account } from '../Account';
3
3
  import { BaseModule } from '../BaseModule';
4
- import { AccountListState } from './types';
5
4
  export declare class AccountListModule extends BaseModule implements Module {
6
5
  protected defaultName: string;
7
6
  protected defaultVersion: string;
@@ -17,7 +16,6 @@ export declare class AccountListModule extends BaseModule implements Module {
17
16
  getAccounts(): AccountModule[];
18
17
  getAccount(id: string): AccountModule | null;
19
18
  clearAccounts(): Promise<void>;
20
- getState(): AccountListState;
21
19
  setActiveAccount(id: string | number): void;
22
20
  getActiveAccount(): AccountModule | null;
23
21
  storeChange(): void;
@@ -1,6 +1,4 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
2
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
3
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
4
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -23,6 +21,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
23
21
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
22
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
23
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
24
+ import { cloneDeep } from 'lodash-es';
26
25
  import { AccountModule } from "../Account";
27
26
  import { BaseModule } from "../BaseModule";
28
27
  import { AccountListHooks } from "./types";
@@ -62,14 +61,14 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
62
61
  case 0:
63
62
  this.core = core;
64
63
  this.store = options === null || options === void 0 ? void 0 : options.store;
65
- this.store.accounts = [];
66
- this.store.accountList = [];
67
64
  if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.accountList)) {
68
- recordList = options.initialState.accountList || [];
65
+ recordList = cloneDeep(options.initialState.accountList || []);
66
+ this.store.accounts = [];
69
67
  recordList.forEach(function (account) {
70
68
  _this2.addAccount(account);
71
69
  });
72
70
  } else {
71
+ this.store.accounts = [];
73
72
  this.store.accountList = [];
74
73
  }
75
74
  if (options !== null && options !== void 0 && (_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
@@ -79,7 +78,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
79
78
  if (options !== null && options !== void 0 && (_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
80
79
  this.fatherModule = options.otherParams.fatherModule;
81
80
  }
82
- case 7:
81
+ case 5:
83
82
  case "end":
84
83
  return _context.stop();
85
84
  }
@@ -113,7 +112,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
113
112
  accountModule = new AccountModule("account_".concat(account.id));
114
113
  this.core.registerModule(accountModule);
115
114
  accountModule.setAccountInfo(account);
116
- this.store.accounts = [].concat(_toConsumableArray(this.store.accounts), [accountModule]);
115
+ this.store.accounts = [].concat(_toConsumableArray(this.store.accounts || []), [accountModule]);
117
116
  _context2.next = 13;
118
117
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
119
118
  case 13:
@@ -221,7 +220,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
221
220
  throw new Error("Account with id ".concat(id, " not found"));
222
221
  case 6:
223
222
  this.store.accounts[index].destory();
224
- this.store.accounts = [].concat(_toConsumableArray(this.store.accounts.slice(0, index)), _toConsumableArray(this.store.accounts.slice(index + 1)));
223
+ this.store.accounts = [].concat(_toConsumableArray((this.store.accounts || []).slice(0, index)), _toConsumableArray((this.store.accounts || []).slice(index + 1)));
225
224
  this.store.accountList = this.store.accountList.filter(function (account) {
226
225
  return account.id !== id;
227
226
  });
@@ -254,7 +253,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
254
253
  }, {
255
254
  key: "getAccounts",
256
255
  value: function getAccounts() {
257
- return _toConsumableArray(this.store.accounts);
256
+ return _toConsumableArray(this.store.accounts || []);
258
257
  }
259
258
  }, {
260
259
  key: "getAccount",
@@ -300,11 +299,6 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
300
299
  }
301
300
  return clearAccounts;
302
301
  }()
303
- }, {
304
- key: "getState",
305
- value: function getState() {
306
- return _objectSpread({}, this.store);
307
- }
308
302
  }, {
309
303
  key: "setActiveAccount",
310
304
  value: function setActiveAccount(id) {
@@ -331,7 +325,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
331
325
  cacheId: this.cacheId,
332
326
  fatherModule: this.fatherModule,
333
327
  store: this.store,
334
- cacheKey: ['accounts', 'accountList']
328
+ cacheKey: ['accountList']
335
329
  });
336
330
  }
337
331
  }
@@ -34,5 +34,4 @@ export interface AccountListModuleAPI {
34
34
  getAccount: (id: string) => AccountModule | null;
35
35
  clearAccounts: () => Promise<void>;
36
36
  addAccounts: (accounts: AccountModule[]) => Promise<void>;
37
- getState: () => AccountListState;
38
37
  }
@@ -1,7 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { AccountModule, Account } from '../Account';
3
3
  import { BaseModule } from '../BaseModule';
4
- import { AccountListState } from './types';
5
4
  export declare class AccountListModule extends BaseModule implements Module {
6
5
  protected defaultName: string;
7
6
  protected defaultVersion: string;
@@ -17,7 +16,6 @@ export declare class AccountListModule extends BaseModule implements Module {
17
16
  getAccounts(): AccountModule[];
18
17
  getAccount(id: string): AccountModule | null;
19
18
  clearAccounts(): Promise<void>;
20
- getState(): AccountListState;
21
19
  setActiveAccount(id: string | number): void;
22
20
  getActiveAccount(): AccountModule | null;
23
21
  storeChange(): void;
@@ -22,6 +22,7 @@ __export(AccountList_exports, {
22
22
  AccountListModule: () => AccountListModule
23
23
  });
24
24
  module.exports = __toCommonJS(AccountList_exports);
25
+ var import_lodash_es = require("lodash-es");
25
26
  var import_Account = require("../Account");
26
27
  var import_BaseModule = require("../BaseModule");
27
28
  var import_types = require("./types");
@@ -44,14 +45,14 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
44
45
  var _a, _b, _c;
45
46
  this.core = core;
46
47
  this.store = options == null ? void 0 : options.store;
47
- this.store.accounts = [];
48
- this.store.accountList = [];
49
48
  if (Array.isArray((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.accountList)) {
50
- const recordList = options.initialState.accountList || [];
49
+ const recordList = (0, import_lodash_es.cloneDeep)(options.initialState.accountList || []);
50
+ this.store.accounts = [];
51
51
  recordList.forEach((account) => {
52
52
  this.addAccount(account);
53
53
  });
54
54
  } else {
55
+ this.store.accounts = [];
55
56
  this.store.accountList = [];
56
57
  }
57
58
  if ((_b = options == null ? void 0 : options.otherParams) == null ? void 0 : _b.cacheId) {
@@ -74,7 +75,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
74
75
  const accountModule = new import_Account.AccountModule(`account_${account.id}`);
75
76
  this.core.registerModule(accountModule);
76
77
  accountModule.setAccountInfo(account);
77
- this.store.accounts = [...this.store.accounts, accountModule];
78
+ this.store.accounts = [...this.store.accounts || [], accountModule];
78
79
  await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
79
80
  if (this.store.accounts.length === 1) {
80
81
  this.setActiveAccount(accountModule.getId());
@@ -118,8 +119,8 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
118
119
  }
119
120
  this.store.accounts[index].destory();
120
121
  this.store.accounts = [
121
- ...this.store.accounts.slice(0, index),
122
- ...this.store.accounts.slice(index + 1)
122
+ ...(this.store.accounts || []).slice(0, index),
123
+ ...(this.store.accounts || []).slice(index + 1)
123
124
  ];
124
125
  this.store.accountList = this.store.accountList.filter((account) => account.id !== id);
125
126
  await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
@@ -131,7 +132,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
131
132
  }
132
133
  }
133
134
  getAccounts() {
134
- return [...this.store.accounts];
135
+ return [...this.store.accounts || []];
135
136
  }
136
137
  getAccount(id) {
137
138
  return this.store.accounts.find((account) => account.getId() === id) || null;
@@ -149,9 +150,6 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
149
150
  this.store.isLoading = false;
150
151
  }
151
152
  }
152
- getState() {
153
- return { ...this.store };
154
- }
155
153
  setActiveAccount(id) {
156
154
  this.store.accounts.forEach((account) => {
157
155
  if (account.getId() === id) {
@@ -166,7 +164,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
166
164
  }
167
165
  storeChange() {
168
166
  if (this.openCache) {
169
- this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store: this.store, cacheKey: ["accounts", "accountList"] });
167
+ this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store: this.store, cacheKey: ["accountList"] });
170
168
  }
171
169
  }
172
170
  };
@@ -34,5 +34,4 @@ export interface AccountListModuleAPI {
34
34
  getAccount: (id: string) => AccountModule | null;
35
35
  clearAccounts: () => Promise<void>;
36
36
  addAccounts: (accounts: AccountModule[]) => Promise<void>;
37
- getState: () => AccountListState;
38
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.19",
4
+ "version": "0.0.20",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",