@akanjs/store 0.9.60-canary.5 → 0.9.60-canary.7

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.
@@ -556,18 +556,23 @@ const makeActions = (refName, slices) => {
556
556
  const model = await fetch[names.model](id, { onError });
557
557
  this.set({ [names.model]: model, [names.modelViewAt]: /* @__PURE__ */ new Date(), [names.modelLoading]: false });
558
558
  },
559
- [names.setModel]: function(fullOrLightModel) {
559
+ [names.setModel]: function(...fullOrLightModels) {
560
560
  const currentState = this.get();
561
+ if (fullOrLightModels.length === 0)
562
+ return;
563
+ const firstModel = fullOrLightModels[0];
561
564
  const model = currentState[names.model];
562
- const isFull = fullOrLightModel instanceof modelRef;
565
+ const isFull = firstModel instanceof modelRef;
563
566
  if (isFull) {
564
- const crystalizedModel = cnst.crystalize(fullOrLightModel);
567
+ const crystalizedModel = cnst.crystalize(firstModel);
565
568
  this.set({ [names.model]: crystalizedModel });
566
- } else if (model?.id === fullOrLightModel.id) {
567
- const crystalizedModel = cnst.crystalize({ ...model, ...fullOrLightModel });
569
+ } else if (model?.id === firstModel.id) {
570
+ const crystalizedModel = cnst.crystalize({ ...model, ...firstModel });
568
571
  this.set({ [names.model]: crystalizedModel });
569
572
  }
570
- const lightModel = cnst.lightCrystalize(fullOrLightModel);
573
+ const lightModels = fullOrLightModels.map(
574
+ (fullOrLightModel) => cnst.lightCrystalize(fullOrLightModel)
575
+ );
571
576
  slices.forEach(({ sliceName }) => {
572
577
  const namesOfSlice = {
573
578
  modelList: sliceName.replace(names.model, names.modelList),
@@ -575,9 +580,14 @@ const makeActions = (refName, slices) => {
575
580
  };
576
581
  const modelList = currentState[namesOfSlice.modelList];
577
582
  const modelListLoading = currentState[namesOfSlice.modelListLoading];
578
- if (modelListLoading || !modelList.has(lightModel.id))
583
+ if (modelListLoading)
579
584
  return;
580
- this.set({ [namesOfSlice.modelList]: modelList.set(lightModel).save() });
585
+ lightModels.forEach((lightModel) => {
586
+ if (!modelList.has(lightModel.id))
587
+ return;
588
+ modelList.set(lightModel);
589
+ });
590
+ this.set({ [namesOfSlice.modelList]: modelList.save() });
581
591
  });
582
592
  },
583
593
  [names.resetModel]: function(model) {
@@ -543,18 +543,23 @@ const makeActions = (refName, slices) => {
543
543
  const model = await fetch[names.model](id, { onError });
544
544
  this.set({ [names.model]: model, [names.modelViewAt]: /* @__PURE__ */ new Date(), [names.modelLoading]: false });
545
545
  },
546
- [names.setModel]: function(fullOrLightModel) {
546
+ [names.setModel]: function(...fullOrLightModels) {
547
547
  const currentState = this.get();
548
+ if (fullOrLightModels.length === 0)
549
+ return;
550
+ const firstModel = fullOrLightModels[0];
548
551
  const model = currentState[names.model];
549
- const isFull = fullOrLightModel instanceof modelRef;
552
+ const isFull = firstModel instanceof modelRef;
550
553
  if (isFull) {
551
- const crystalizedModel = cnst.crystalize(fullOrLightModel);
554
+ const crystalizedModel = cnst.crystalize(firstModel);
552
555
  this.set({ [names.model]: crystalizedModel });
553
- } else if (model?.id === fullOrLightModel.id) {
554
- const crystalizedModel = cnst.crystalize({ ...model, ...fullOrLightModel });
556
+ } else if (model?.id === firstModel.id) {
557
+ const crystalizedModel = cnst.crystalize({ ...model, ...firstModel });
555
558
  this.set({ [names.model]: crystalizedModel });
556
559
  }
557
- const lightModel = cnst.lightCrystalize(fullOrLightModel);
560
+ const lightModels = fullOrLightModels.map(
561
+ (fullOrLightModel) => cnst.lightCrystalize(fullOrLightModel)
562
+ );
558
563
  slices.forEach(({ sliceName }) => {
559
564
  const namesOfSlice = {
560
565
  modelList: sliceName.replace(names.model, names.modelList),
@@ -562,9 +567,14 @@ const makeActions = (refName, slices) => {
562
567
  };
563
568
  const modelList = currentState[namesOfSlice.modelList];
564
569
  const modelListLoading = currentState[namesOfSlice.modelListLoading];
565
- if (modelListLoading || !modelList.has(lightModel.id))
570
+ if (modelListLoading)
566
571
  return;
567
- this.set({ [namesOfSlice.modelList]: modelList.set(lightModel).save() });
572
+ lightModels.forEach((lightModel) => {
573
+ if (!modelList.has(lightModel.id))
574
+ return;
575
+ modelList.set(lightModel);
576
+ });
577
+ this.set({ [namesOfSlice.modelList]: modelList.save() });
568
578
  });
569
579
  },
570
580
  [names.resetModel]: function(model) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/store",
3
- "version": "0.9.60-canary.5",
3
+ "version": "0.9.60-canary.7",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -136,7 +136,7 @@ type BaseAction<T extends string, Input, Full extends {
136
136
  modal?: string | null;
137
137
  } & FetchPolicy) => Promise<void>;
138
138
  } & {
139
- [K in `set${_CapitalizedT}`]: (model: Full | Light) => void;
139
+ [K in `set${_CapitalizedT}`]: (...models: (Full | Light)[]) => void;
140
140
  } & {
141
141
  [K in `reset${_CapitalizedT}`]: (model?: Full) => void;
142
142
  };