@knotx/data 0.5.0 → 0.5.2

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
@@ -27,6 +27,7 @@ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !==
27
27
  class DataManager {
28
28
  constructor(tag) {
29
29
  this.tag = tag;
30
+ __publicField$1(this, "isInit$", new rxjs.BehaviorSubject(false));
30
31
  __publicField$1(this, "operations$", new rxjs.Subject());
31
32
  __publicField$1(this, "operationPipes$", new rxjs.BehaviorSubject({
32
33
  transform: [],
@@ -46,6 +47,10 @@ class DataManager {
46
47
  __publicField$1(this, "mapVersion$", new rxjs.BehaviorSubject(0));
47
48
  __publicField$1(this, "_patchVersionUpdating", false);
48
49
  __publicField$1(this, "_mapVersionUpdating", false);
50
+ __publicField$1(this, "_scheduler", setTimeout);
51
+ }
52
+ get isInit() {
53
+ return this.isInit$.value;
49
54
  }
50
55
  get version() {
51
56
  return this.patchVersion$.value + this.mapVersion$.value;
@@ -110,6 +115,9 @@ class DataManager {
110
115
  operators.map(({ dataMap, operations }) => this.applyOperation(dataMap, { type: "batch", operations }))
111
116
  ).subscribe(this.dataMap$);
112
117
  this.dispatch({ type: "batch", operations: initialDataList.map((data) => ({ type: "add", data })), isInit: true });
118
+ this._scheduler(() => {
119
+ this.isInit$.next(true);
120
+ });
113
121
  }
114
122
  getOperations$() {
115
123
  return this.operations$.asObservable();
@@ -262,7 +270,7 @@ class DataManager {
262
270
  }
263
271
  return dataMap;
264
272
  }
265
- updateVersion(operation, scheduler = setTimeout) {
273
+ updateVersion(operation, scheduler = this._scheduler) {
266
274
  if (this.isPatchOperation(operation)) {
267
275
  if (this._patchVersionUpdating) {
268
276
  return;
package/dist/index.d.cts CHANGED
@@ -70,6 +70,7 @@ interface DataDraftOperation<T extends IData = IData> {
70
70
  type DataOperation<T extends IData = IData> = DataAddOperation<T> | DataRemoveOperation<T> | DataUpdateOperation<T> | DataBatchOperation<T> | DataStartDraftOperation<T> | DataCommitDraftOperation<T> | DataDiscardDraftOperation<T> | DataDraftOperation<T>;
71
71
  declare class DataManager<TData extends IData = IData, TTag extends string = any> {
72
72
  readonly tag: TTag;
73
+ private isInit$;
73
74
  private operations$;
74
75
  private operationPipes$;
75
76
  private drafts$;
@@ -83,9 +84,11 @@ declare class DataManager<TData extends IData = IData, TTag extends string = any
83
84
  * 数据版本号,用于标识数据的变化,数据增删时,mapVersion 会递增
84
85
  */
85
86
  readonly mapVersion$: BehaviorSubject<number>;
87
+ get isInit(): boolean;
86
88
  get version(): number;
87
89
  private _patchVersionUpdating;
88
90
  private _mapVersionUpdating;
91
+ private _scheduler;
89
92
  constructor(tag: TTag);
90
93
  getDataList$(): Observable<TData[]>;
91
94
  getDataList(): TData[];
package/dist/index.d.mts CHANGED
@@ -70,6 +70,7 @@ interface DataDraftOperation<T extends IData = IData> {
70
70
  type DataOperation<T extends IData = IData> = DataAddOperation<T> | DataRemoveOperation<T> | DataUpdateOperation<T> | DataBatchOperation<T> | DataStartDraftOperation<T> | DataCommitDraftOperation<T> | DataDiscardDraftOperation<T> | DataDraftOperation<T>;
71
71
  declare class DataManager<TData extends IData = IData, TTag extends string = any> {
72
72
  readonly tag: TTag;
73
+ private isInit$;
73
74
  private operations$;
74
75
  private operationPipes$;
75
76
  private drafts$;
@@ -83,9 +84,11 @@ declare class DataManager<TData extends IData = IData, TTag extends string = any
83
84
  * 数据版本号,用于标识数据的变化,数据增删时,mapVersion 会递增
84
85
  */
85
86
  readonly mapVersion$: BehaviorSubject<number>;
87
+ get isInit(): boolean;
86
88
  get version(): number;
87
89
  private _patchVersionUpdating;
88
90
  private _mapVersionUpdating;
91
+ private _scheduler;
89
92
  constructor(tag: TTag);
90
93
  getDataList$(): Observable<TData[]>;
91
94
  getDataList(): TData[];
package/dist/index.d.ts CHANGED
@@ -70,6 +70,7 @@ interface DataDraftOperation<T extends IData = IData> {
70
70
  type DataOperation<T extends IData = IData> = DataAddOperation<T> | DataRemoveOperation<T> | DataUpdateOperation<T> | DataBatchOperation<T> | DataStartDraftOperation<T> | DataCommitDraftOperation<T> | DataDiscardDraftOperation<T> | DataDraftOperation<T>;
71
71
  declare class DataManager<TData extends IData = IData, TTag extends string = any> {
72
72
  readonly tag: TTag;
73
+ private isInit$;
73
74
  private operations$;
74
75
  private operationPipes$;
75
76
  private drafts$;
@@ -83,9 +84,11 @@ declare class DataManager<TData extends IData = IData, TTag extends string = any
83
84
  * 数据版本号,用于标识数据的变化,数据增删时,mapVersion 会递增
84
85
  */
85
86
  readonly mapVersion$: BehaviorSubject<number>;
87
+ get isInit(): boolean;
86
88
  get version(): number;
87
89
  private _patchVersionUpdating;
88
90
  private _mapVersionUpdating;
91
+ private _scheduler;
89
92
  constructor(tag: TTag);
90
93
  getDataList$(): Observable<TData[]>;
91
94
  getDataList(): TData[];
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { cloneDeep } from 'lodash-es';
2
- import { Subject, BehaviorSubject, pipe } from 'rxjs';
2
+ import { BehaviorSubject, Subject, pipe } from 'rxjs';
3
3
  import { map, distinctUntilChanged, tap, scan } from 'rxjs/operators';
4
4
 
5
5
  var __defProp$1 = Object.defineProperty;
@@ -25,6 +25,7 @@ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !==
25
25
  class DataManager {
26
26
  constructor(tag) {
27
27
  this.tag = tag;
28
+ __publicField$1(this, "isInit$", new BehaviorSubject(false));
28
29
  __publicField$1(this, "operations$", new Subject());
29
30
  __publicField$1(this, "operationPipes$", new BehaviorSubject({
30
31
  transform: [],
@@ -44,6 +45,10 @@ class DataManager {
44
45
  __publicField$1(this, "mapVersion$", new BehaviorSubject(0));
45
46
  __publicField$1(this, "_patchVersionUpdating", false);
46
47
  __publicField$1(this, "_mapVersionUpdating", false);
48
+ __publicField$1(this, "_scheduler", setTimeout);
49
+ }
50
+ get isInit() {
51
+ return this.isInit$.value;
47
52
  }
48
53
  get version() {
49
54
  return this.patchVersion$.value + this.mapVersion$.value;
@@ -108,6 +113,9 @@ class DataManager {
108
113
  map(({ dataMap, operations }) => this.applyOperation(dataMap, { type: "batch", operations }))
109
114
  ).subscribe(this.dataMap$);
110
115
  this.dispatch({ type: "batch", operations: initialDataList.map((data) => ({ type: "add", data })), isInit: true });
116
+ this._scheduler(() => {
117
+ this.isInit$.next(true);
118
+ });
111
119
  }
112
120
  getOperations$() {
113
121
  return this.operations$.asObservable();
@@ -260,7 +268,7 @@ class DataManager {
260
268
  }
261
269
  return dataMap;
262
270
  }
263
- updateVersion(operation, scheduler = setTimeout) {
271
+ updateVersion(operation, scheduler = this._scheduler) {
264
272
  if (this.isPatchOperation(operation)) {
265
273
  if (this._patchVersionUpdating) {
266
274
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/data",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Data for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -33,9 +33,9 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/lodash-es": "^4.17.12",
36
- "@knotx/build-config": "0.5.0",
37
- "@knotx/eslint-config": "0.5.0",
38
- "@knotx/typescript-config": "0.5.0"
36
+ "@knotx/build-config": "0.5.2",
37
+ "@knotx/eslint-config": "0.5.2",
38
+ "@knotx/typescript-config": "0.5.2"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "unbuild",