@pisell/pisellos 0.0.24 → 0.0.25

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.
@@ -12,6 +12,7 @@ export declare class AccountListModule extends BaseModule implements Module {
12
12
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
13
13
  addAccount(account: Account): Promise<void>;
14
14
  updateAccount(id: string, updates: Account): Promise<void>;
15
+ updateAccountListById(id: string | number, updates: Account): Promise<void>;
15
16
  removeAccount(id: string): Promise<void>;
16
17
  getAccounts(): AccountModule[];
17
18
  getAccount(id: string): AccountModule | null;
@@ -200,21 +200,48 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
200
200
  return updateAccount;
201
201
  }()
202
202
  }, {
203
- key: "removeAccount",
203
+ key: "updateAccountListById",
204
204
  value: function () {
205
- var _removeAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(id) {
206
- var index;
205
+ var _updateAccountListById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(id, updates) {
207
206
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
208
207
  while (1) switch (_context4.prev = _context4.next) {
209
208
  case 0:
210
- _context4.prev = 0;
209
+ this.store.accountList = this.store.accountList.map(function (account) {
210
+ if (account.id === id) {
211
+ return updates;
212
+ }
213
+ return account;
214
+ });
215
+ this.core.effects.emit("".concat(this.name, ":changed"), {
216
+ value: this.store.accountList
217
+ });
218
+ case 2:
219
+ case "end":
220
+ return _context4.stop();
221
+ }
222
+ }, _callee4, this);
223
+ }));
224
+ function updateAccountListById(_x6, _x7) {
225
+ return _updateAccountListById.apply(this, arguments);
226
+ }
227
+ return updateAccountListById;
228
+ }()
229
+ }, {
230
+ key: "removeAccount",
231
+ value: function () {
232
+ var _removeAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
233
+ var index;
234
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
235
+ while (1) switch (_context5.prev = _context5.next) {
236
+ case 0:
237
+ _context5.prev = 0;
211
238
  this.store.isLoading = true;
212
239
  this.store.error = null;
213
240
  index = this.store.accounts.findIndex(function (a) {
214
241
  return a.getId() === id;
215
242
  });
216
243
  if (!(index === -1)) {
217
- _context4.next = 6;
244
+ _context5.next = 6;
218
245
  break;
219
246
  }
220
247
  throw new Error("Account with id ".concat(id, " not found"));
@@ -224,28 +251,28 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
224
251
  this.store.accountList = this.store.accountList.filter(function (account) {
225
252
  return account.id !== id;
226
253
  });
227
- _context4.next = 11;
254
+ _context5.next = 11;
228
255
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
229
256
  case 11:
230
- _context4.next = 18;
257
+ _context5.next = 18;
231
258
  break;
232
259
  case 13:
233
- _context4.prev = 13;
234
- _context4.t0 = _context4["catch"](0);
235
- this.store.error = _context4.t0 instanceof Error ? _context4.t0.message : 'Failed to remove account';
236
- _context4.next = 18;
260
+ _context5.prev = 13;
261
+ _context5.t0 = _context5["catch"](0);
262
+ this.store.error = _context5.t0 instanceof Error ? _context5.t0.message : 'Failed to remove account';
263
+ _context5.next = 18;
237
264
  return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
238
265
  case 18:
239
- _context4.prev = 18;
266
+ _context5.prev = 18;
240
267
  this.store.isLoading = false;
241
- return _context4.finish(18);
268
+ return _context5.finish(18);
242
269
  case 21:
243
270
  case "end":
244
- return _context4.stop();
271
+ return _context5.stop();
245
272
  }
246
- }, _callee4, this, [[0, 13, 18, 21]]);
273
+ }, _callee5, this, [[0, 13, 18, 21]]);
247
274
  }));
248
- function removeAccount(_x6) {
275
+ function removeAccount(_x8) {
249
276
  return _removeAccount.apply(this, arguments);
250
277
  }
251
278
  return removeAccount;
@@ -265,34 +292,34 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
265
292
  }, {
266
293
  key: "clearAccounts",
267
294
  value: function () {
268
- var _clearAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
269
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
270
- while (1) switch (_context5.prev = _context5.next) {
295
+ var _clearAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
296
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
297
+ while (1) switch (_context6.prev = _context6.next) {
271
298
  case 0:
272
- _context5.prev = 0;
299
+ _context6.prev = 0;
273
300
  this.store.isLoading = true;
274
301
  this.store.error = null;
275
302
  this.store.accounts = [];
276
- _context5.next = 6;
303
+ _context6.next = 6;
277
304
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
278
305
  case 6:
279
- _context5.next = 13;
306
+ _context6.next = 13;
280
307
  break;
281
308
  case 8:
282
- _context5.prev = 8;
283
- _context5.t0 = _context5["catch"](0);
284
- this.store.error = _context5.t0 instanceof Error ? _context5.t0.message : 'Failed to clear accounts';
285
- _context5.next = 13;
309
+ _context6.prev = 8;
310
+ _context6.t0 = _context6["catch"](0);
311
+ this.store.error = _context6.t0 instanceof Error ? _context6.t0.message : 'Failed to clear accounts';
312
+ _context6.next = 13;
286
313
  return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
287
314
  case 13:
288
- _context5.prev = 13;
315
+ _context6.prev = 13;
289
316
  this.store.isLoading = false;
290
- return _context5.finish(13);
317
+ return _context6.finish(13);
291
318
  case 16:
292
319
  case "end":
293
- return _context5.stop();
320
+ return _context6.stop();
294
321
  }
295
- }, _callee5, this, [[0, 8, 13, 16]]);
322
+ }, _callee6, this, [[0, 8, 13, 16]]);
296
323
  }));
297
324
  function clearAccounts() {
298
325
  return _clearAccounts.apply(this, arguments);
@@ -485,9 +485,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
485
485
  case 0:
486
486
  account = this.store.accountList.getAccount(accountId);
487
487
  if (!account) {
488
- _context11.next = 7;
488
+ _context11.next = 8;
489
489
  break;
490
490
  }
491
+ this.store.accountList.updateAccountListById(account.getId(), accountInfo);
491
492
  account.setAccountInfo(accountInfo);
492
493
  // 然后去购物车,把原先关联了 holder_id 为 accountId 的商品,替换为 holder_id = accountInfo.id
493
494
  cartItems = this.store.cart.getItems();
@@ -499,11 +500,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
499
500
  });
500
501
  }
501
502
  });
502
- _context11.next = 8;
503
+ _context11.next = 9;
503
504
  break;
504
- case 7:
505
- throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
506
505
  case 8:
506
+ throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
507
+ case 9:
507
508
  case "end":
508
509
  return _context11.stop();
509
510
  }
@@ -12,6 +12,7 @@ export declare class AccountListModule extends BaseModule implements Module {
12
12
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
13
13
  addAccount(account: Account): Promise<void>;
14
14
  updateAccount(id: string, updates: Account): Promise<void>;
15
+ updateAccountListById(id: string | number, updates: Account): Promise<void>;
15
16
  removeAccount(id: string): Promise<void>;
16
17
  getAccounts(): AccountModule[];
17
18
  getAccount(id: string): AccountModule | null;
@@ -109,6 +109,15 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
109
109
  this.store.isLoading = false;
110
110
  }
111
111
  }
112
+ async updateAccountListById(id, updates) {
113
+ this.store.accountList = this.store.accountList.map((account) => {
114
+ if (account.id === id) {
115
+ return updates;
116
+ }
117
+ return account;
118
+ });
119
+ this.core.effects.emit(`${this.name}:changed`, { value: this.store.accountList });
120
+ }
112
121
  async removeAccount(id) {
113
122
  try {
114
123
  this.store.isLoading = true;
@@ -238,6 +238,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
238
238
  async setLoginAccount(accountId, accountInfo) {
239
239
  const account = this.store.accountList.getAccount(accountId);
240
240
  if (account) {
241
+ this.store.accountList.updateAccountListById(account.getId(), accountInfo);
241
242
  account.setAccountInfo(accountInfo);
242
243
  const cartItems = this.store.cart.getItems();
243
244
  cartItems.forEach((item) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.24",
4
+ "version": "0.0.25",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",