@knotx/data 0.2.7 → 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 +10 -5
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -5
- package/package.json +6 -4
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
|
|
|
@@ -108,7 +109,7 @@ class DataManager {
|
|
|
108
109
|
operators.tap(({ operations }) => this.updateVersion({ type: "batch", operations })),
|
|
109
110
|
operators.map(({ dataMap, operations }) => this.applyOperation(dataMap, { type: "batch", operations }))
|
|
110
111
|
).subscribe(this.dataMap$);
|
|
111
|
-
this.
|
|
112
|
+
this.dispatch({ type: "batch", operations: initialDataList.map((data) => ({ type: "add", data })), isInit: true });
|
|
112
113
|
}
|
|
113
114
|
getOperations$() {
|
|
114
115
|
return this.operations$.asObservable();
|
|
@@ -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
|
-
|
|
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$.
|
|
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 =
|
|
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
|
|
|
@@ -106,7 +107,7 @@ class DataManager {
|
|
|
106
107
|
tap(({ operations }) => this.updateVersion({ type: "batch", operations })),
|
|
107
108
|
map(({ dataMap, operations }) => this.applyOperation(dataMap, { type: "batch", operations }))
|
|
108
109
|
).subscribe(this.dataMap$);
|
|
109
|
-
this.
|
|
110
|
+
this.dispatch({ type: "batch", operations: initialDataList.map((data) => ({ type: "add", data })), isInit: true });
|
|
110
111
|
}
|
|
111
112
|
getOperations$() {
|
|
112
113
|
return this.operations$.asObservable();
|
|
@@ -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
|
-
|
|
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$.
|
|
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 =
|
|
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.
|
|
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
|
-
"@
|
|
35
|
-
"@knotx/
|
|
36
|
-
"@knotx/
|
|
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",
|