@knotx/data 0.2.8 → 0.2.9

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.
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const lodashEs = require('lodash-es');
3
4
  const rxjs = require('rxjs');
4
5
  const operators = require('rxjs/operators');
5
6
 
@@ -139,7 +140,7 @@ class DataManager {
139
140
  dryRun(operation) {
140
141
  switch (operation.type) {
141
142
  case "commitDraft": {
142
- const dataMap = this.applyOperation(new Map(this.dataMap$.value), __spreadProps(__spreadValues$1({}, operation), {
143
+ const dataMap = this.applyOperation(new Map(this.dataMap$.value.entries().map(([key, val]) => [key, lodashEs.cloneDeep(val)])), __spreadProps(__spreadValues$1({}, operation), {
143
144
  isDryRun: true
144
145
  }));
145
146
  return dataMap;
@@ -173,7 +174,9 @@ class DataManager {
173
174
  case "startDraft": {
174
175
  const draftDataMap$ = new rxjs.BehaviorSubject(/* @__PURE__ */ new Map());
175
176
  this.drafts$.next(this.drafts$.value.set(operation.draftId, draftDataMap$));
176
- this.currentDraftDataMap$.next(draftDataMap$.value);
177
+ if (!operation.isSilent) {
178
+ this.currentDraftDataMap$.next(draftDataMap$.value);
179
+ }
177
180
  break;
178
181
  }
179
182
  case "draftOperation": {
@@ -199,7 +202,9 @@ class DataManager {
199
202
  }
200
203
  }
201
204
  }), operation.operation);
202
- this.currentDraftDataMap$.next(draftDataMap.value);
205
+ if (this.currentDraftDataMap$.value === draftDataMap.value) {
206
+ this.currentDraftDataMap$.next(draftDataMap.value);
207
+ }
203
208
  }
204
209
  break;
205
210
  }
@@ -249,7 +254,7 @@ class DataManager {
249
254
  }
250
255
  return dataMap;
251
256
  }
252
- updateVersion(operation, scheduler = queueMicrotask) {
257
+ updateVersion(operation, scheduler = requestAnimationFrame) {
253
258
  if (this.isPatchOperation(operation)) {
254
259
  if (this._patchVersionUpdating) {
255
260
  return;
package/dist/index.d.cts CHANGED
@@ -44,6 +44,7 @@ interface DataBatchOperation<T extends IData = IData> {
44
44
  interface DataStartDraftOperation<_T extends IData = IData> {
45
45
  type: 'startDraft';
46
46
  draftId: string;
47
+ isSilent?: boolean;
47
48
  }
48
49
  interface DataCommitDraftOperation<_T extends IData = IData> {
49
50
  type: 'commitDraft';
package/dist/index.d.mts CHANGED
@@ -44,6 +44,7 @@ interface DataBatchOperation<T extends IData = IData> {
44
44
  interface DataStartDraftOperation<_T extends IData = IData> {
45
45
  type: 'startDraft';
46
46
  draftId: string;
47
+ isSilent?: boolean;
47
48
  }
48
49
  interface DataCommitDraftOperation<_T extends IData = IData> {
49
50
  type: 'commitDraft';
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ interface DataBatchOperation<T extends IData = IData> {
44
44
  interface DataStartDraftOperation<_T extends IData = IData> {
45
45
  type: 'startDraft';
46
46
  draftId: string;
47
+ isSilent?: boolean;
47
48
  }
48
49
  interface DataCommitDraftOperation<_T extends IData = IData> {
49
50
  type: 'commitDraft';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { cloneDeep } from 'lodash-es';
1
2
  import { Subject, BehaviorSubject, pipe } from 'rxjs';
2
3
  import { map, distinctUntilChanged, tap, scan } from 'rxjs/operators';
3
4
 
@@ -137,7 +138,7 @@ class DataManager {
137
138
  dryRun(operation) {
138
139
  switch (operation.type) {
139
140
  case "commitDraft": {
140
- const dataMap = this.applyOperation(new Map(this.dataMap$.value), __spreadProps(__spreadValues$1({}, operation), {
141
+ const dataMap = this.applyOperation(new Map(this.dataMap$.value.entries().map(([key, val]) => [key, cloneDeep(val)])), __spreadProps(__spreadValues$1({}, operation), {
141
142
  isDryRun: true
142
143
  }));
143
144
  return dataMap;
@@ -171,7 +172,9 @@ class DataManager {
171
172
  case "startDraft": {
172
173
  const draftDataMap$ = new BehaviorSubject(/* @__PURE__ */ new Map());
173
174
  this.drafts$.next(this.drafts$.value.set(operation.draftId, draftDataMap$));
174
- this.currentDraftDataMap$.next(draftDataMap$.value);
175
+ if (!operation.isSilent) {
176
+ this.currentDraftDataMap$.next(draftDataMap$.value);
177
+ }
175
178
  break;
176
179
  }
177
180
  case "draftOperation": {
@@ -197,7 +200,9 @@ class DataManager {
197
200
  }
198
201
  }
199
202
  }), operation.operation);
200
- this.currentDraftDataMap$.next(draftDataMap.value);
203
+ if (this.currentDraftDataMap$.value === draftDataMap.value) {
204
+ this.currentDraftDataMap$.next(draftDataMap.value);
205
+ }
201
206
  }
202
207
  break;
203
208
  }
@@ -247,7 +252,7 @@ class DataManager {
247
252
  }
248
253
  return dataMap;
249
254
  }
250
- updateVersion(operation, scheduler = queueMicrotask) {
255
+ updateVersion(operation, scheduler = requestAnimationFrame) {
251
256
  if (this.isPatchOperation(operation)) {
252
257
  if (this._patchVersionUpdating) {
253
258
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/data",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Data for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -28,12 +28,14 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
+ "lodash-es": "^4.17.21",
31
32
  "rxjs": "^7.8.1"
32
33
  },
33
34
  "devDependencies": {
34
- "@knotx/build-config": "0.2.8",
35
- "@knotx/eslint-config": "0.2.8",
36
- "@knotx/typescript-config": "0.2.8"
35
+ "@types/lodash-es": "^4.17.12",
36
+ "@knotx/build-config": "0.2.9",
37
+ "@knotx/eslint-config": "0.2.9",
38
+ "@knotx/typescript-config": "0.2.9"
37
39
  },
38
40
  "scripts": {
39
41
  "build": "unbuild",