vis-data 7.1.0 → 7.1.3
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/declarations/data-interface.d.ts +1 -28
- package/declarations/data-interface.d.ts.map +1 -1
- package/declarations/data-pipe.d.ts +5 -9
- package/declarations/data-pipe.d.ts.map +1 -1
- package/declarations/data-set-check.d.ts +0 -1
- package/declarations/data-set-check.d.ts.map +1 -1
- package/declarations/data-set-part.d.ts +1 -1
- package/declarations/data-set-part.d.ts.map +1 -1
- package/declarations/data-set.d.ts +4 -17
- package/declarations/data-set.d.ts.map +1 -1
- package/declarations/data-stream.d.ts +1 -17
- package/declarations/data-stream.d.ts.map +1 -1
- package/declarations/data-view-check.d.ts +0 -1
- package/declarations/data-view-check.d.ts.map +1 -1
- package/declarations/data-view.d.ts +4 -2
- package/declarations/data-view.d.ts.map +1 -1
- package/declarations/queue.d.ts +3 -2
- package/declarations/queue.d.ts.map +1 -1
- package/dist/esm.js +7435 -3483
- package/dist/esm.js.map +1 -1
- package/dist/umd.js +11969 -8016
- package/dist/umd.js.map +1 -1
- package/esnext/esm/vis-data.js +162 -266
- package/esnext/esm/vis-data.js.map +1 -1
- package/esnext/esm/vis-data.min.js +3 -17
- package/esnext/esm/vis-data.min.js.map +1 -1
- package/esnext/umd/vis-data.js +2009 -2115
- package/esnext/umd/vis-data.js.map +1 -1
- package/esnext/umd/vis-data.min.js +3 -18
- package/esnext/umd/vis-data.min.js.map +1 -1
- package/package.json +75 -27
- package/peer/esm/vis-data.js +7428 -3475
- package/peer/esm/vis-data.js.map +1 -1
- package/peer/esm/vis-data.min.js +8 -41
- package/peer/esm/vis-data.min.js.map +1 -1
- package/peer/umd/vis-data.js +11928 -7975
- package/peer/umd/vis-data.js.map +1 -1
- package/peer/umd/vis-data.min.js +9 -42
- package/peer/umd/vis-data.min.js.map +1 -1
- package/standalone/esm/vis-data.js +7428 -3475
- package/standalone/esm/vis-data.js.map +1 -1
- package/standalone/esm/vis-data.min.js +8 -41
- package/standalone/esm/vis-data.min.js.map +1 -1
- package/standalone/umd/vis-data.js +11928 -7975
- package/standalone/umd/vis-data.js.map +1 -1
- package/standalone/umd/vis-data.min.js +9 -42
- package/standalone/umd/vis-data.min.js.map +1 -1
package/esnext/esm/vis-data.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Manage unstructured data using DataSet. Add, update, and remove data, and listen for changes in the data.
|
|
6
6
|
*
|
|
7
|
-
* @version 7.1.
|
|
8
|
-
* @date
|
|
7
|
+
* @version 7.1.3
|
|
8
|
+
* @date 2022-03-02T13:02:54.265Z
|
|
9
9
|
*
|
|
10
10
|
* @copyright (c) 2011-2017 Almende B.V, http://almende.com
|
|
11
11
|
* @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
|
|
@@ -28,42 +28,10 @@ import { pureDeepObjectAssign } from 'vis-util/esnext/esm/vis-util.js';
|
|
|
28
28
|
export { DELETE } from 'vis-util/esnext/esm/vis-util.js';
|
|
29
29
|
import { v4 } from 'uuid';
|
|
30
30
|
|
|
31
|
-
/*! *****************************************************************************
|
|
32
|
-
Copyright (c) Microsoft Corporation.
|
|
33
|
-
|
|
34
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
35
|
-
purpose with or without fee is hereby granted.
|
|
36
|
-
|
|
37
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
38
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
39
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
40
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
41
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
42
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
43
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
44
|
-
***************************************************************************** */
|
|
45
|
-
|
|
46
|
-
function __classPrivateFieldGet(receiver, privateMap) {
|
|
47
|
-
if (!privateMap.has(receiver)) {
|
|
48
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
49
|
-
}
|
|
50
|
-
return privateMap.get(receiver);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
54
|
-
if (!privateMap.has(receiver)) {
|
|
55
|
-
throw new TypeError("attempted to set private field on non-instance");
|
|
56
|
-
}
|
|
57
|
-
privateMap.set(receiver, value);
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
var _transformers_1;
|
|
62
31
|
/**
|
|
63
32
|
* Create new data pipe.
|
|
64
33
|
*
|
|
65
34
|
* @param from - The source data set or data view.
|
|
66
|
-
*
|
|
67
35
|
* @remarks
|
|
68
36
|
* Example usage:
|
|
69
37
|
* ```typescript
|
|
@@ -90,7 +58,6 @@ var _transformers_1;
|
|
|
90
58
|
*
|
|
91
59
|
* pipe.start();
|
|
92
60
|
* ```
|
|
93
|
-
*
|
|
94
61
|
* @returns A factory whose methods can be used to configure the pipe.
|
|
95
62
|
*/
|
|
96
63
|
function createNewDataPipeFrom(from) {
|
|
@@ -150,7 +117,6 @@ class SimpleDataPipe {
|
|
|
150
117
|
* Apply the transformers to the items.
|
|
151
118
|
*
|
|
152
119
|
* @param items - The items to be transformed.
|
|
153
|
-
*
|
|
154
120
|
* @returns The transformed items.
|
|
155
121
|
*/
|
|
156
122
|
_transformItems(items) {
|
|
@@ -215,18 +181,17 @@ class DataPipeUnderConstruction {
|
|
|
215
181
|
* Array transformers used to transform items within the pipe. This is typed
|
|
216
182
|
* as any for the sake of simplicity.
|
|
217
183
|
*/
|
|
218
|
-
|
|
184
|
+
this._transformers = [];
|
|
219
185
|
}
|
|
220
186
|
/**
|
|
221
187
|
* Filter the items.
|
|
222
188
|
*
|
|
223
189
|
* @param callback - A filtering function that returns true if given item
|
|
224
190
|
* should be piped and false if not.
|
|
225
|
-
*
|
|
226
191
|
* @returns This factory for further configuration.
|
|
227
192
|
*/
|
|
228
193
|
filter(callback) {
|
|
229
|
-
|
|
194
|
+
this._transformers.push((input) => input.filter(callback));
|
|
230
195
|
return this;
|
|
231
196
|
}
|
|
232
197
|
/**
|
|
@@ -234,14 +199,12 @@ class DataPipeUnderConstruction {
|
|
|
234
199
|
*
|
|
235
200
|
* @param callback - A mapping function that takes a source item and returns
|
|
236
201
|
* corresponding mapped item.
|
|
237
|
-
*
|
|
238
202
|
* @typeParam TI - Target item type.
|
|
239
203
|
* @typeParam TP - Target item type's id property name.
|
|
240
|
-
*
|
|
241
204
|
* @returns This factory for further configuration.
|
|
242
205
|
*/
|
|
243
206
|
map(callback) {
|
|
244
|
-
|
|
207
|
+
this._transformers.push((input) => input.map(callback));
|
|
245
208
|
return this;
|
|
246
209
|
}
|
|
247
210
|
/**
|
|
@@ -249,42 +212,36 @@ class DataPipeUnderConstruction {
|
|
|
249
212
|
*
|
|
250
213
|
* @param callback - A mapping function that takes a source item and returns
|
|
251
214
|
* an array of corresponding mapped items.
|
|
252
|
-
*
|
|
253
215
|
* @typeParam TI - Target item type.
|
|
254
216
|
* @typeParam TP - Target item type's id property name.
|
|
255
|
-
*
|
|
256
217
|
* @returns This factory for further configuration.
|
|
257
218
|
*/
|
|
258
219
|
flatMap(callback) {
|
|
259
|
-
|
|
220
|
+
this._transformers.push((input) => input.flatMap(callback));
|
|
260
221
|
return this;
|
|
261
222
|
}
|
|
262
223
|
/**
|
|
263
224
|
* Connect this pipe to given data set.
|
|
264
225
|
*
|
|
265
226
|
* @param target - The data set that will receive the items from this pipe.
|
|
266
|
-
*
|
|
267
227
|
* @returns The pipe connected between given data sets and performing
|
|
268
228
|
* configured transformation on the processed items.
|
|
269
229
|
*/
|
|
270
230
|
to(target) {
|
|
271
|
-
return new SimpleDataPipe(this._source,
|
|
231
|
+
return new SimpleDataPipe(this._source, this._transformers, target);
|
|
272
232
|
}
|
|
273
|
-
}
|
|
274
|
-
_transformers_1 = new WeakMap();
|
|
233
|
+
}
|
|
275
234
|
|
|
276
235
|
/**
|
|
277
236
|
* Determine whether a value can be used as an id.
|
|
278
237
|
*
|
|
279
238
|
* @param value - Input value of unknown type.
|
|
280
|
-
*
|
|
281
239
|
* @returns True if the value is valid id, false otherwise.
|
|
282
240
|
*/
|
|
283
241
|
function isId(value) {
|
|
284
242
|
return typeof value === "string" || typeof value === "number";
|
|
285
243
|
}
|
|
286
244
|
|
|
287
|
-
var _queue, _timeout, _extended;
|
|
288
245
|
/**
|
|
289
246
|
* A queue.
|
|
290
247
|
*
|
|
@@ -297,9 +254,9 @@ class Queue {
|
|
|
297
254
|
* @param options - Queue configuration.
|
|
298
255
|
*/
|
|
299
256
|
constructor(options) {
|
|
300
|
-
_queue
|
|
301
|
-
_timeout
|
|
302
|
-
_extended
|
|
257
|
+
this._queue = [];
|
|
258
|
+
this._timeout = null;
|
|
259
|
+
this._extended = null;
|
|
303
260
|
// options
|
|
304
261
|
this.delay = null;
|
|
305
262
|
this.max = Infinity;
|
|
@@ -325,7 +282,6 @@ class Queue {
|
|
|
325
282
|
*
|
|
326
283
|
* @param object - The object to be extended.
|
|
327
284
|
* @param options - Additional options.
|
|
328
|
-
*
|
|
329
285
|
* @returns The created queue.
|
|
330
286
|
*/
|
|
331
287
|
static extend(object, options) {
|
|
@@ -354,10 +310,10 @@ class Queue {
|
|
|
354
310
|
queue.replace(object, name);
|
|
355
311
|
}
|
|
356
312
|
}
|
|
357
|
-
|
|
313
|
+
queue._extended = {
|
|
358
314
|
object: object,
|
|
359
315
|
methods: methods,
|
|
360
|
-
}
|
|
316
|
+
};
|
|
361
317
|
return queue;
|
|
362
318
|
}
|
|
363
319
|
/**
|
|
@@ -365,9 +321,9 @@ class Queue {
|
|
|
365
321
|
*/
|
|
366
322
|
destroy() {
|
|
367
323
|
this.flush();
|
|
368
|
-
if (
|
|
369
|
-
const object =
|
|
370
|
-
const methods =
|
|
324
|
+
if (this._extended) {
|
|
325
|
+
const object = this._extended.object;
|
|
326
|
+
const methods = this._extended.methods;
|
|
371
327
|
for (let i = 0; i < methods.length; i++) {
|
|
372
328
|
const method = methods[i];
|
|
373
329
|
if (method.original) {
|
|
@@ -379,7 +335,7 @@ class Queue {
|
|
|
379
335
|
delete object[method.name];
|
|
380
336
|
}
|
|
381
337
|
}
|
|
382
|
-
|
|
338
|
+
this._extended = null;
|
|
383
339
|
}
|
|
384
340
|
}
|
|
385
341
|
/**
|
|
@@ -411,10 +367,10 @@ class Queue {
|
|
|
411
367
|
*/
|
|
412
368
|
queue(entry) {
|
|
413
369
|
if (typeof entry === "function") {
|
|
414
|
-
|
|
370
|
+
this._queue.push({ fn: entry });
|
|
415
371
|
}
|
|
416
372
|
else {
|
|
417
|
-
|
|
373
|
+
this._queue.push(entry);
|
|
418
374
|
}
|
|
419
375
|
this._flushIfNeeded();
|
|
420
376
|
}
|
|
@@ -423,32 +379,30 @@ class Queue {
|
|
|
423
379
|
*/
|
|
424
380
|
_flushIfNeeded() {
|
|
425
381
|
// flush when the maximum is exceeded.
|
|
426
|
-
if (
|
|
382
|
+
if (this._queue.length > this.max) {
|
|
427
383
|
this.flush();
|
|
428
384
|
}
|
|
429
385
|
// flush after a period of inactivity when a delay is configured
|
|
430
|
-
if (
|
|
431
|
-
clearTimeout(
|
|
432
|
-
|
|
386
|
+
if (this._timeout != null) {
|
|
387
|
+
clearTimeout(this._timeout);
|
|
388
|
+
this._timeout = null;
|
|
433
389
|
}
|
|
434
390
|
if (this.queue.length > 0 && typeof this.delay === "number") {
|
|
435
|
-
|
|
391
|
+
this._timeout = setTimeout(() => {
|
|
436
392
|
this.flush();
|
|
437
|
-
}, this.delay)
|
|
393
|
+
}, this.delay);
|
|
438
394
|
}
|
|
439
395
|
}
|
|
440
396
|
/**
|
|
441
397
|
* Flush all queued calls
|
|
442
398
|
*/
|
|
443
399
|
flush() {
|
|
444
|
-
|
|
400
|
+
this._queue.splice(0).forEach((entry) => {
|
|
445
401
|
entry.fn.apply(entry.context || entry.fn, entry.args || []);
|
|
446
402
|
});
|
|
447
403
|
}
|
|
448
|
-
}
|
|
449
|
-
_queue = new WeakMap(), _timeout = new WeakMap(), _extended = new WeakMap();
|
|
404
|
+
}
|
|
450
405
|
|
|
451
|
-
var _subscribers;
|
|
452
406
|
/**
|
|
453
407
|
* [[DataSet]] code that can be reused in [[DataView]] or other similar implementations of [[DataInterface]].
|
|
454
408
|
*
|
|
@@ -457,12 +411,12 @@ var _subscribers;
|
|
|
457
411
|
*/
|
|
458
412
|
class DataSetPart {
|
|
459
413
|
constructor() {
|
|
460
|
-
_subscribers
|
|
414
|
+
this._subscribers = {
|
|
461
415
|
"*": [],
|
|
462
416
|
add: [],
|
|
463
417
|
remove: [],
|
|
464
418
|
update: [],
|
|
465
|
-
}
|
|
419
|
+
};
|
|
466
420
|
/**
|
|
467
421
|
* @deprecated Use on instead (PS: DataView.subscribe === DataView.on).
|
|
468
422
|
*/
|
|
@@ -483,7 +437,7 @@ class DataSetPart {
|
|
|
483
437
|
if (event === "*") {
|
|
484
438
|
throw new Error("Cannot trigger event *");
|
|
485
439
|
}
|
|
486
|
-
[...
|
|
440
|
+
[...this._subscribers[event], ...this._subscribers["*"]].forEach((subscriber) => {
|
|
487
441
|
subscriber(event, payload, senderId != null ? senderId : null);
|
|
488
442
|
});
|
|
489
443
|
}
|
|
@@ -491,13 +445,12 @@ class DataSetPart {
|
|
|
491
445
|
* Subscribe to an event, add an event listener.
|
|
492
446
|
*
|
|
493
447
|
* @remarks Non-function callbacks are ignored.
|
|
494
|
-
*
|
|
495
448
|
* @param event - Event name.
|
|
496
449
|
* @param callback - Callback method.
|
|
497
450
|
*/
|
|
498
451
|
on(event, callback) {
|
|
499
452
|
if (typeof callback === "function") {
|
|
500
|
-
|
|
453
|
+
this._subscribers[event].push(callback);
|
|
501
454
|
}
|
|
502
455
|
// @TODO: Maybe throw for invalid callbacks?
|
|
503
456
|
}
|
|
@@ -505,17 +458,14 @@ class DataSetPart {
|
|
|
505
458
|
* Unsubscribe from an event, remove an event listener.
|
|
506
459
|
*
|
|
507
460
|
* @remarks If the same callback was subscribed more than once **all** occurences will be removed.
|
|
508
|
-
*
|
|
509
461
|
* @param event - Event name.
|
|
510
462
|
* @param callback - Callback method.
|
|
511
463
|
*/
|
|
512
464
|
off(event, callback) {
|
|
513
|
-
|
|
465
|
+
this._subscribers[event] = this._subscribers[event].filter((subscriber) => subscriber !== callback);
|
|
514
466
|
}
|
|
515
|
-
}
|
|
516
|
-
_subscribers = new WeakMap();
|
|
467
|
+
}
|
|
517
468
|
|
|
518
|
-
var _pairs;
|
|
519
469
|
/**
|
|
520
470
|
* Data stream
|
|
521
471
|
*
|
|
@@ -523,7 +473,6 @@ var _pairs;
|
|
|
523
473
|
* [[DataStream]] offers an always up to date stream of items from a [[DataSet]] or [[DataView]].
|
|
524
474
|
* That means that the stream is evaluated at the time of iteration, conversion to another data type or when [[cache]] is called, not when the [[DataStream]] was created.
|
|
525
475
|
* Multiple invocations of for example [[toItemArray]] may yield different results (if the data source like for example [[DataSet]] gets modified).
|
|
526
|
-
*
|
|
527
476
|
* @typeParam Item - The item type this stream is going to work with.
|
|
528
477
|
*/
|
|
529
478
|
class DataStream {
|
|
@@ -533,14 +482,13 @@ class DataStream {
|
|
|
533
482
|
* @param pairs - The id, item pairs.
|
|
534
483
|
*/
|
|
535
484
|
constructor(pairs) {
|
|
536
|
-
_pairs
|
|
537
|
-
__classPrivateFieldSet(this, _pairs, pairs);
|
|
485
|
+
this._pairs = pairs;
|
|
538
486
|
}
|
|
539
487
|
/**
|
|
540
488
|
* Return an iterable of key, value pairs for every entry in the stream.
|
|
541
489
|
*/
|
|
542
|
-
*[
|
|
543
|
-
for (const [id, item] of
|
|
490
|
+
*[Symbol.iterator]() {
|
|
491
|
+
for (const [id, item] of this._pairs) {
|
|
544
492
|
yield [id, item];
|
|
545
493
|
}
|
|
546
494
|
}
|
|
@@ -548,7 +496,7 @@ class DataStream {
|
|
|
548
496
|
* Return an iterable of key, value pairs for every entry in the stream.
|
|
549
497
|
*/
|
|
550
498
|
*entries() {
|
|
551
|
-
for (const [id, item] of
|
|
499
|
+
for (const [id, item] of this._pairs) {
|
|
552
500
|
yield [id, item];
|
|
553
501
|
}
|
|
554
502
|
}
|
|
@@ -556,7 +504,7 @@ class DataStream {
|
|
|
556
504
|
* Return an iterable of keys in the stream.
|
|
557
505
|
*/
|
|
558
506
|
*keys() {
|
|
559
|
-
for (const [id] of
|
|
507
|
+
for (const [id] of this._pairs) {
|
|
560
508
|
yield id;
|
|
561
509
|
}
|
|
562
510
|
}
|
|
@@ -564,7 +512,7 @@ class DataStream {
|
|
|
564
512
|
* Return an iterable of values in the stream.
|
|
565
513
|
*/
|
|
566
514
|
*values() {
|
|
567
|
-
for (const [, item] of
|
|
515
|
+
for (const [, item] of this._pairs) {
|
|
568
516
|
yield item;
|
|
569
517
|
}
|
|
570
518
|
}
|
|
@@ -573,45 +521,41 @@ class DataStream {
|
|
|
573
521
|
*
|
|
574
522
|
* @remarks
|
|
575
523
|
* The array may contain duplicities.
|
|
576
|
-
*
|
|
577
524
|
* @returns The array with all ids from this stream.
|
|
578
525
|
*/
|
|
579
526
|
toIdArray() {
|
|
580
|
-
return [...
|
|
527
|
+
return [...this._pairs].map((pair) => pair[0]);
|
|
581
528
|
}
|
|
582
529
|
/**
|
|
583
530
|
* Return an array containing all the items in this stream.
|
|
584
531
|
*
|
|
585
532
|
* @remarks
|
|
586
533
|
* The array may contain duplicities.
|
|
587
|
-
*
|
|
588
534
|
* @returns The array with all items from this stream.
|
|
589
535
|
*/
|
|
590
536
|
toItemArray() {
|
|
591
|
-
return [...
|
|
537
|
+
return [...this._pairs].map((pair) => pair[1]);
|
|
592
538
|
}
|
|
593
539
|
/**
|
|
594
540
|
* Return an array containing all the entries in this stream.
|
|
595
541
|
*
|
|
596
542
|
* @remarks
|
|
597
543
|
* The array may contain duplicities.
|
|
598
|
-
*
|
|
599
544
|
* @returns The array with all entries from this stream.
|
|
600
545
|
*/
|
|
601
546
|
toEntryArray() {
|
|
602
|
-
return [...
|
|
547
|
+
return [...this._pairs];
|
|
603
548
|
}
|
|
604
549
|
/**
|
|
605
550
|
* Return an object map containing all the items in this stream accessible by ids.
|
|
606
551
|
*
|
|
607
552
|
* @remarks
|
|
608
553
|
* In case of duplicate ids (coerced to string so `7 == '7'`) the last encoutered appears in the returned object.
|
|
609
|
-
*
|
|
610
554
|
* @returns The object map of all id → item pairs from this stream.
|
|
611
555
|
*/
|
|
612
556
|
toObjectMap() {
|
|
613
557
|
const map = Object.create(null);
|
|
614
|
-
for (const [id, item] of
|
|
558
|
+
for (const [id, item] of this._pairs) {
|
|
615
559
|
map[id] = item;
|
|
616
560
|
}
|
|
617
561
|
return map;
|
|
@@ -622,7 +566,7 @@ class DataStream {
|
|
|
622
566
|
* @returns The map of all id → item pairs from this stream.
|
|
623
567
|
*/
|
|
624
568
|
toMap() {
|
|
625
|
-
return new Map(
|
|
569
|
+
return new Map(this._pairs);
|
|
626
570
|
}
|
|
627
571
|
/**
|
|
628
572
|
* Return a set containing all the (unique) ids in this stream.
|
|
@@ -660,24 +604,21 @@ class DataStream {
|
|
|
660
604
|
* ds.clear()
|
|
661
605
|
* chachedStream // Still has all the items.
|
|
662
606
|
* ```
|
|
663
|
-
*
|
|
664
607
|
* @returns A new [[DataStream]] with cached items (detached from the original [[DataSet]]).
|
|
665
608
|
*/
|
|
666
609
|
cache() {
|
|
667
|
-
return new DataStream([...
|
|
610
|
+
return new DataStream([...this._pairs]);
|
|
668
611
|
}
|
|
669
612
|
/**
|
|
670
613
|
* Get the distinct values of given property.
|
|
671
614
|
*
|
|
672
615
|
* @param callback - The function that picks and possibly converts the property.
|
|
673
|
-
*
|
|
674
616
|
* @typeParam T - The type of the distinct value.
|
|
675
|
-
*
|
|
676
617
|
* @returns A set of all distinct properties.
|
|
677
618
|
*/
|
|
678
619
|
distinct(callback) {
|
|
679
620
|
const set = new Set();
|
|
680
|
-
for (const [id, item] of
|
|
621
|
+
for (const [id, item] of this._pairs) {
|
|
681
622
|
set.add(callback(item, id));
|
|
682
623
|
}
|
|
683
624
|
return set;
|
|
@@ -686,11 +627,10 @@ class DataStream {
|
|
|
686
627
|
* Filter the items of the stream.
|
|
687
628
|
*
|
|
688
629
|
* @param callback - The function that decides whether an item will be included.
|
|
689
|
-
*
|
|
690
630
|
* @returns A new data stream with the filtered items.
|
|
691
631
|
*/
|
|
692
632
|
filter(callback) {
|
|
693
|
-
const pairs =
|
|
633
|
+
const pairs = this._pairs;
|
|
694
634
|
return new DataStream({
|
|
695
635
|
*[Symbol.iterator]() {
|
|
696
636
|
for (const [id, item] of pairs) {
|
|
@@ -707,7 +647,7 @@ class DataStream {
|
|
|
707
647
|
* @param callback - The function that will be invoked for each item.
|
|
708
648
|
*/
|
|
709
649
|
forEach(callback) {
|
|
710
|
-
for (const [id, item] of
|
|
650
|
+
for (const [id, item] of this._pairs) {
|
|
711
651
|
callback(item, id);
|
|
712
652
|
}
|
|
713
653
|
}
|
|
@@ -715,13 +655,11 @@ class DataStream {
|
|
|
715
655
|
* Map the items into a different type.
|
|
716
656
|
*
|
|
717
657
|
* @param callback - The function that does the conversion.
|
|
718
|
-
*
|
|
719
658
|
* @typeParam Mapped - The type of the item after mapping.
|
|
720
|
-
*
|
|
721
659
|
* @returns A new data stream with the mapped items.
|
|
722
660
|
*/
|
|
723
661
|
map(callback) {
|
|
724
|
-
const pairs =
|
|
662
|
+
const pairs = this._pairs;
|
|
725
663
|
return new DataStream({
|
|
726
664
|
*[Symbol.iterator]() {
|
|
727
665
|
for (const [id, item] of pairs) {
|
|
@@ -734,11 +672,10 @@ class DataStream {
|
|
|
734
672
|
* Get the item with the maximum value of given property.
|
|
735
673
|
*
|
|
736
674
|
* @param callback - The function that picks and possibly converts the property.
|
|
737
|
-
*
|
|
738
675
|
* @returns The item with the maximum if found otherwise null.
|
|
739
676
|
*/
|
|
740
677
|
max(callback) {
|
|
741
|
-
const iter =
|
|
678
|
+
const iter = this._pairs[Symbol.iterator]();
|
|
742
679
|
let curr = iter.next();
|
|
743
680
|
if (curr.done) {
|
|
744
681
|
return null;
|
|
@@ -759,11 +696,10 @@ class DataStream {
|
|
|
759
696
|
* Get the item with the minimum value of given property.
|
|
760
697
|
*
|
|
761
698
|
* @param callback - The function that picks and possibly converts the property.
|
|
762
|
-
*
|
|
763
699
|
* @returns The item with the minimum if found otherwise null.
|
|
764
700
|
*/
|
|
765
701
|
min(callback) {
|
|
766
|
-
const iter =
|
|
702
|
+
const iter = this._pairs[Symbol.iterator]();
|
|
767
703
|
let curr = iter.next();
|
|
768
704
|
if (curr.done) {
|
|
769
705
|
return null;
|
|
@@ -785,13 +721,11 @@ class DataStream {
|
|
|
785
721
|
*
|
|
786
722
|
* @param callback - The function that does the reduction.
|
|
787
723
|
* @param accumulator - The initial value of the accumulator.
|
|
788
|
-
*
|
|
789
724
|
* @typeParam T - The type of the accumulated value.
|
|
790
|
-
*
|
|
791
725
|
* @returns The reduced value.
|
|
792
726
|
*/
|
|
793
727
|
reduce(callback, accumulator) {
|
|
794
|
-
for (const [id, item] of
|
|
728
|
+
for (const [id, item] of this._pairs) {
|
|
795
729
|
accumulator = callback(accumulator, item, id);
|
|
796
730
|
}
|
|
797
731
|
return accumulator;
|
|
@@ -800,30 +734,25 @@ class DataStream {
|
|
|
800
734
|
* Sort the items.
|
|
801
735
|
*
|
|
802
736
|
* @param callback - Item comparator.
|
|
803
|
-
*
|
|
804
737
|
* @returns A new stream with sorted items.
|
|
805
738
|
*/
|
|
806
739
|
sort(callback) {
|
|
807
740
|
return new DataStream({
|
|
808
|
-
[Symbol.iterator]: () => [...
|
|
741
|
+
[Symbol.iterator]: () => [...this._pairs]
|
|
809
742
|
.sort(([idA, itemA], [idB, itemB]) => callback(itemA, itemB, idA, idB))[Symbol.iterator](),
|
|
810
743
|
});
|
|
811
744
|
}
|
|
812
745
|
}
|
|
813
746
|
|
|
814
|
-
var _options, _data, _idProp, _queue$1;
|
|
815
747
|
/**
|
|
816
748
|
* Add an id to given item if it doesn't have one already.
|
|
817
749
|
*
|
|
818
750
|
* @remarks
|
|
819
751
|
* The item will be modified.
|
|
820
|
-
*
|
|
821
752
|
* @param item - The item that will have an id after a call to this function.
|
|
822
753
|
* @param idProp - The key of the id property.
|
|
823
|
-
*
|
|
824
754
|
* @typeParam Item - Item type that may or may not have an id.
|
|
825
755
|
* @typeParam IdProp - Name of the property that contains the id.
|
|
826
|
-
*
|
|
827
756
|
* @returns true
|
|
828
757
|
*/
|
|
829
758
|
function ensureFullItem(item, idProp) {
|
|
@@ -901,20 +830,16 @@ class DataSet extends DataSetPart {
|
|
|
901
830
|
*/
|
|
902
831
|
constructor(data, options) {
|
|
903
832
|
super();
|
|
904
|
-
|
|
905
|
-
_data.set(this, void 0);
|
|
906
|
-
_idProp.set(this, void 0);
|
|
907
|
-
_queue$1.set(this, null);
|
|
833
|
+
this._queue = null;
|
|
908
834
|
// correctly read optional arguments
|
|
909
835
|
if (data && !Array.isArray(data)) {
|
|
910
836
|
options = data;
|
|
911
837
|
data = [];
|
|
912
838
|
}
|
|
913
|
-
|
|
914
|
-
|
|
839
|
+
this._options = options || {};
|
|
840
|
+
this._data = new Map(); // map with data indexed by id
|
|
915
841
|
this.length = 0; // number of items in the DataSet
|
|
916
|
-
|
|
917
|
-
this, _idProp, __classPrivateFieldGet(this, _options).fieldId || "id"); // name of the field containing id
|
|
842
|
+
this._idProp = this._options.fieldId || "id"; // name of the field containing id
|
|
918
843
|
// add initial data when provided
|
|
919
844
|
if (data && data.length) {
|
|
920
845
|
this.add(data);
|
|
@@ -923,7 +848,7 @@ class DataSet extends DataSetPart {
|
|
|
923
848
|
}
|
|
924
849
|
/** @inheritDoc */
|
|
925
850
|
get idProp() {
|
|
926
|
-
return
|
|
851
|
+
return this._idProp;
|
|
927
852
|
}
|
|
928
853
|
/**
|
|
929
854
|
* Set new options.
|
|
@@ -934,20 +859,20 @@ class DataSet extends DataSetPart {
|
|
|
934
859
|
if (options && options.queue !== undefined) {
|
|
935
860
|
if (options.queue === false) {
|
|
936
861
|
// delete queue if loaded
|
|
937
|
-
if (
|
|
938
|
-
|
|
939
|
-
|
|
862
|
+
if (this._queue) {
|
|
863
|
+
this._queue.destroy();
|
|
864
|
+
this._queue = null;
|
|
940
865
|
}
|
|
941
866
|
}
|
|
942
867
|
else {
|
|
943
868
|
// create queue and update its options
|
|
944
|
-
if (!
|
|
945
|
-
|
|
869
|
+
if (!this._queue) {
|
|
870
|
+
this._queue = Queue.extend(this, {
|
|
946
871
|
replace: ["add", "update", "remove"],
|
|
947
|
-
})
|
|
872
|
+
});
|
|
948
873
|
}
|
|
949
874
|
if (options.queue && typeof options.queue === "object") {
|
|
950
|
-
|
|
875
|
+
this._queue.setOptions(options.queue);
|
|
951
876
|
}
|
|
952
877
|
}
|
|
953
878
|
}
|
|
@@ -975,9 +900,7 @@ class DataSet extends DataSetPart {
|
|
|
975
900
|
*
|
|
976
901
|
* @param data - Items to be added (ids will be generated if missing).
|
|
977
902
|
* @param senderId - Sender id.
|
|
978
|
-
*
|
|
979
903
|
* @returns addedIds - Array with the ids (generated if not present) of the added items.
|
|
980
|
-
*
|
|
981
904
|
* @throws When an item with the same id as any of the added items already exists.
|
|
982
905
|
*/
|
|
983
906
|
add(data, senderId) {
|
|
@@ -985,8 +908,8 @@ class DataSet extends DataSetPart {
|
|
|
985
908
|
let id;
|
|
986
909
|
if (Array.isArray(data)) {
|
|
987
910
|
// Array
|
|
988
|
-
const idsToAdd = data.map((d) => d[
|
|
989
|
-
if (idsToAdd.some((id) =>
|
|
911
|
+
const idsToAdd = data.map((d) => d[this._idProp]);
|
|
912
|
+
if (idsToAdd.some((id) => this._data.has(id))) {
|
|
990
913
|
throw new Error("A duplicate id was found in the parameter array.");
|
|
991
914
|
}
|
|
992
915
|
for (let i = 0, len = data.length; i < len; i++) {
|
|
@@ -1036,12 +959,9 @@ class DataSet extends DataSetPart {
|
|
|
1036
959
|
*
|
|
1037
960
|
* ## Warning for TypeScript users
|
|
1038
961
|
* This method may introduce partial items into the data set. Use add or updateOnly instead for better type safety.
|
|
1039
|
-
*
|
|
1040
962
|
* @param data - Items to be updated (if the id is already present) or added (if the id is missing).
|
|
1041
963
|
* @param senderId - Sender id.
|
|
1042
|
-
*
|
|
1043
964
|
* @returns updatedIds - The ids of the added (these may be newly generated if there was no id in the item from the data) or updated items.
|
|
1044
|
-
*
|
|
1045
965
|
* @throws When the supplied data is neither an item nor an array of items.
|
|
1046
966
|
*/
|
|
1047
967
|
update(data, senderId) {
|
|
@@ -1049,12 +969,12 @@ class DataSet extends DataSetPart {
|
|
|
1049
969
|
const updatedIds = [];
|
|
1050
970
|
const oldData = [];
|
|
1051
971
|
const updatedData = [];
|
|
1052
|
-
const idProp =
|
|
972
|
+
const idProp = this._idProp;
|
|
1053
973
|
const addOrUpdate = (item) => {
|
|
1054
974
|
const origId = item[idProp];
|
|
1055
|
-
if (origId != null &&
|
|
975
|
+
if (origId != null && this._data.has(origId)) {
|
|
1056
976
|
const fullItem = item; // it has an id, therefore it is a fullitem
|
|
1057
|
-
const oldItem = Object.assign({},
|
|
977
|
+
const oldItem = Object.assign({}, this._data.get(origId));
|
|
1058
978
|
// update item
|
|
1059
979
|
const id = this._updateItem(fullItem);
|
|
1060
980
|
updatedIds.push(id);
|
|
@@ -1130,12 +1050,9 @@ class DataSet extends DataSetPart {
|
|
|
1130
1050
|
*
|
|
1131
1051
|
* console.log(ids) // [2]
|
|
1132
1052
|
* ```
|
|
1133
|
-
*
|
|
1134
1053
|
* @param data - Updates (the id and optionally other props) to the items in this data set.
|
|
1135
1054
|
* @param senderId - Sender id.
|
|
1136
|
-
*
|
|
1137
1055
|
* @returns updatedIds - The ids of the updated items.
|
|
1138
|
-
*
|
|
1139
1056
|
* @throws When the supplied data is neither an item nor an array of items, when the ids are missing.
|
|
1140
1057
|
*/
|
|
1141
1058
|
updateOnly(data, senderId) {
|
|
@@ -1144,16 +1061,16 @@ class DataSet extends DataSetPart {
|
|
|
1144
1061
|
}
|
|
1145
1062
|
const updateEventData = data
|
|
1146
1063
|
.map((update) => {
|
|
1147
|
-
const oldData =
|
|
1064
|
+
const oldData = this._data.get(update[this._idProp]);
|
|
1148
1065
|
if (oldData == null) {
|
|
1149
1066
|
throw new Error("Updating non-existent items is not allowed.");
|
|
1150
1067
|
}
|
|
1151
1068
|
return { oldData, update };
|
|
1152
1069
|
})
|
|
1153
1070
|
.map(({ oldData, update }) => {
|
|
1154
|
-
const id = oldData[
|
|
1071
|
+
const id = oldData[this._idProp];
|
|
1155
1072
|
const updatedData = pureDeepObjectAssign(oldData, update);
|
|
1156
|
-
|
|
1073
|
+
this._data.set(id, updatedData);
|
|
1157
1074
|
return {
|
|
1158
1075
|
id,
|
|
1159
1076
|
oldData: oldData,
|
|
@@ -1223,7 +1140,7 @@ class DataSet extends DataSetPart {
|
|
|
1223
1140
|
// convert items
|
|
1224
1141
|
if (id != null) {
|
|
1225
1142
|
// return a single item
|
|
1226
|
-
item =
|
|
1143
|
+
item = this._data.get(id);
|
|
1227
1144
|
if (item && filter && !filter(item)) {
|
|
1228
1145
|
item = undefined;
|
|
1229
1146
|
}
|
|
@@ -1231,7 +1148,7 @@ class DataSet extends DataSetPart {
|
|
|
1231
1148
|
else if (ids != null) {
|
|
1232
1149
|
// return a subset of items
|
|
1233
1150
|
for (let i = 0, len = ids.length; i < len; i++) {
|
|
1234
|
-
item =
|
|
1151
|
+
item = this._data.get(ids[i]);
|
|
1235
1152
|
if (item != null && (!filter || filter(item))) {
|
|
1236
1153
|
items.push(item);
|
|
1237
1154
|
}
|
|
@@ -1239,10 +1156,10 @@ class DataSet extends DataSetPart {
|
|
|
1239
1156
|
}
|
|
1240
1157
|
else {
|
|
1241
1158
|
// return all items
|
|
1242
|
-
itemIds = [...
|
|
1159
|
+
itemIds = [...this._data.keys()];
|
|
1243
1160
|
for (let i = 0, len = itemIds.length; i < len; i++) {
|
|
1244
1161
|
itemId = itemIds[i];
|
|
1245
|
-
item =
|
|
1162
|
+
item = this._data.get(itemId);
|
|
1246
1163
|
if (item != null && (!filter || filter(item))) {
|
|
1247
1164
|
items.push(item);
|
|
1248
1165
|
}
|
|
@@ -1271,7 +1188,7 @@ class DataSet extends DataSetPart {
|
|
|
1271
1188
|
const resultant = items[i];
|
|
1272
1189
|
// @TODO: Shoudn't this be this._fieldId?
|
|
1273
1190
|
// result[resultant.id] = resultant
|
|
1274
|
-
const id = resultant[
|
|
1191
|
+
const id = resultant[this._idProp];
|
|
1275
1192
|
result[id] = resultant;
|
|
1276
1193
|
}
|
|
1277
1194
|
return result;
|
|
@@ -1279,7 +1196,7 @@ class DataSet extends DataSetPart {
|
|
|
1279
1196
|
else {
|
|
1280
1197
|
if (id != null) {
|
|
1281
1198
|
// a single item
|
|
1282
|
-
return item
|
|
1199
|
+
return item ?? null;
|
|
1283
1200
|
}
|
|
1284
1201
|
else {
|
|
1285
1202
|
// just return our array
|
|
@@ -1289,7 +1206,7 @@ class DataSet extends DataSetPart {
|
|
|
1289
1206
|
}
|
|
1290
1207
|
/** @inheritDoc */
|
|
1291
1208
|
getIds(options) {
|
|
1292
|
-
const data =
|
|
1209
|
+
const data = this._data;
|
|
1293
1210
|
const filter = options && options.filter;
|
|
1294
1211
|
const order = options && options.order;
|
|
1295
1212
|
const itemIds = [...data.keys()];
|
|
@@ -1301,23 +1218,23 @@ class DataSet extends DataSetPart {
|
|
|
1301
1218
|
const items = [];
|
|
1302
1219
|
for (let i = 0, len = itemIds.length; i < len; i++) {
|
|
1303
1220
|
const id = itemIds[i];
|
|
1304
|
-
const item =
|
|
1221
|
+
const item = this._data.get(id);
|
|
1305
1222
|
if (item != null && filter(item)) {
|
|
1306
1223
|
items.push(item);
|
|
1307
1224
|
}
|
|
1308
1225
|
}
|
|
1309
1226
|
this._sort(items, order);
|
|
1310
1227
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
1311
|
-
ids.push(items[i][
|
|
1228
|
+
ids.push(items[i][this._idProp]);
|
|
1312
1229
|
}
|
|
1313
1230
|
}
|
|
1314
1231
|
else {
|
|
1315
1232
|
// create unordered list
|
|
1316
1233
|
for (let i = 0, len = itemIds.length; i < len; i++) {
|
|
1317
1234
|
const id = itemIds[i];
|
|
1318
|
-
const item =
|
|
1235
|
+
const item = this._data.get(id);
|
|
1319
1236
|
if (item != null && filter(item)) {
|
|
1320
|
-
ids.push(item[
|
|
1237
|
+
ids.push(item[this._idProp]);
|
|
1321
1238
|
}
|
|
1322
1239
|
}
|
|
1323
1240
|
}
|
|
@@ -1333,7 +1250,7 @@ class DataSet extends DataSetPart {
|
|
|
1333
1250
|
}
|
|
1334
1251
|
this._sort(items, order);
|
|
1335
1252
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
1336
|
-
ids.push(items[i][
|
|
1253
|
+
ids.push(items[i][this._idProp]);
|
|
1337
1254
|
}
|
|
1338
1255
|
}
|
|
1339
1256
|
else {
|
|
@@ -1342,7 +1259,7 @@ class DataSet extends DataSetPart {
|
|
|
1342
1259
|
const id = itemIds[i];
|
|
1343
1260
|
const item = data.get(id);
|
|
1344
1261
|
if (item != null) {
|
|
1345
|
-
ids.push(item[
|
|
1262
|
+
ids.push(item[this._idProp]);
|
|
1346
1263
|
}
|
|
1347
1264
|
}
|
|
1348
1265
|
}
|
|
@@ -1356,14 +1273,14 @@ class DataSet extends DataSetPart {
|
|
|
1356
1273
|
/** @inheritDoc */
|
|
1357
1274
|
forEach(callback, options) {
|
|
1358
1275
|
const filter = options && options.filter;
|
|
1359
|
-
const data =
|
|
1276
|
+
const data = this._data;
|
|
1360
1277
|
const itemIds = [...data.keys()];
|
|
1361
1278
|
if (options && options.order) {
|
|
1362
1279
|
// execute forEach on ordered list
|
|
1363
1280
|
const items = this.get(options);
|
|
1364
1281
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
1365
1282
|
const item = items[i];
|
|
1366
|
-
const id = item[
|
|
1283
|
+
const id = item[this._idProp];
|
|
1367
1284
|
callback(item, id);
|
|
1368
1285
|
}
|
|
1369
1286
|
}
|
|
@@ -1371,7 +1288,7 @@ class DataSet extends DataSetPart {
|
|
|
1371
1288
|
// unordered
|
|
1372
1289
|
for (let i = 0, len = itemIds.length; i < len; i++) {
|
|
1373
1290
|
const id = itemIds[i];
|
|
1374
|
-
const item =
|
|
1291
|
+
const item = this._data.get(id);
|
|
1375
1292
|
if (item != null && (!filter || filter(item))) {
|
|
1376
1293
|
callback(item, id);
|
|
1377
1294
|
}
|
|
@@ -1382,12 +1299,12 @@ class DataSet extends DataSetPart {
|
|
|
1382
1299
|
map(callback, options) {
|
|
1383
1300
|
const filter = options && options.filter;
|
|
1384
1301
|
const mappedItems = [];
|
|
1385
|
-
const data =
|
|
1302
|
+
const data = this._data;
|
|
1386
1303
|
const itemIds = [...data.keys()];
|
|
1387
1304
|
// convert and filter items
|
|
1388
1305
|
for (let i = 0, len = itemIds.length; i < len; i++) {
|
|
1389
1306
|
const id = itemIds[i];
|
|
1390
|
-
const item =
|
|
1307
|
+
const item = this._data.get(id);
|
|
1391
1308
|
if (item != null && (!filter || filter(item))) {
|
|
1392
1309
|
mappedItems.push(callback(item, id));
|
|
1393
1310
|
}
|
|
@@ -1403,9 +1320,7 @@ class DataSet extends DataSetPart {
|
|
|
1403
1320
|
*
|
|
1404
1321
|
* @param item - The item whose fields should be filtered.
|
|
1405
1322
|
* @param fields - The names of the fields that will be kept.
|
|
1406
|
-
*
|
|
1407
1323
|
* @typeParam K - Field name type.
|
|
1408
|
-
*
|
|
1409
1324
|
* @returns The item without any additional fields.
|
|
1410
1325
|
*/
|
|
1411
1326
|
_filterFields(item, fields) {
|
|
@@ -1427,7 +1342,6 @@ class DataSet extends DataSetPart {
|
|
|
1427
1342
|
*
|
|
1428
1343
|
* @param items - Items to be sorted in place.
|
|
1429
1344
|
* @param order - A field name or custom sort function.
|
|
1430
|
-
*
|
|
1431
1345
|
* @typeParam T - The type of the items in the items array.
|
|
1432
1346
|
*/
|
|
1433
1347
|
_sort(items, order) {
|
|
@@ -1475,7 +1389,6 @@ class DataSet extends DataSetPart {
|
|
|
1475
1389
|
*
|
|
1476
1390
|
* @param id - One or more items or ids of items to be removed.
|
|
1477
1391
|
* @param senderId - Sender id.
|
|
1478
|
-
*
|
|
1479
1392
|
* @returns The ids of the removed items.
|
|
1480
1393
|
*/
|
|
1481
1394
|
remove(id, senderId) {
|
|
@@ -1486,7 +1399,7 @@ class DataSet extends DataSetPart {
|
|
|
1486
1399
|
for (let i = 0, len = ids.length; i < len; i++) {
|
|
1487
1400
|
const item = this._remove(ids[i]);
|
|
1488
1401
|
if (item) {
|
|
1489
|
-
const itemId = item[
|
|
1402
|
+
const itemId = item[this._idProp];
|
|
1490
1403
|
if (itemId != null) {
|
|
1491
1404
|
removedIds.push(itemId);
|
|
1492
1405
|
removedItems.push(item);
|
|
@@ -1502,7 +1415,6 @@ class DataSet extends DataSetPart {
|
|
|
1502
1415
|
* Remove an item by its id or reference.
|
|
1503
1416
|
*
|
|
1504
1417
|
* @param id - Id of an item or the item itself.
|
|
1505
|
-
*
|
|
1506
1418
|
* @returns The removed item if removed, null otherwise.
|
|
1507
1419
|
*/
|
|
1508
1420
|
_remove(id) {
|
|
@@ -1514,12 +1426,12 @@ class DataSet extends DataSetPart {
|
|
|
1514
1426
|
ident = id;
|
|
1515
1427
|
}
|
|
1516
1428
|
else if (id && typeof id === "object") {
|
|
1517
|
-
ident = id[
|
|
1429
|
+
ident = id[this._idProp]; // look for the identifier field using ._idProp
|
|
1518
1430
|
}
|
|
1519
1431
|
// do the removing if the item is found
|
|
1520
|
-
if (ident != null &&
|
|
1521
|
-
const item =
|
|
1522
|
-
|
|
1432
|
+
if (ident != null && this._data.has(ident)) {
|
|
1433
|
+
const item = this._data.get(ident) || null;
|
|
1434
|
+
this._data.delete(ident);
|
|
1523
1435
|
--this.length;
|
|
1524
1436
|
return item;
|
|
1525
1437
|
}
|
|
@@ -1531,16 +1443,15 @@ class DataSet extends DataSetPart {
|
|
|
1531
1443
|
* After the items are removed, the [[DataSet]] will trigger an event `remove` for all removed items. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
|
|
1532
1444
|
*
|
|
1533
1445
|
* @param senderId - Sender id.
|
|
1534
|
-
*
|
|
1535
1446
|
* @returns removedIds - The ids of all removed items.
|
|
1536
1447
|
*/
|
|
1537
1448
|
clear(senderId) {
|
|
1538
|
-
const ids = [...
|
|
1449
|
+
const ids = [...this._data.keys()];
|
|
1539
1450
|
const items = [];
|
|
1540
1451
|
for (let i = 0, len = ids.length; i < len; i++) {
|
|
1541
|
-
items.push(
|
|
1452
|
+
items.push(this._data.get(ids[i]));
|
|
1542
1453
|
}
|
|
1543
|
-
|
|
1454
|
+
this._data.clear();
|
|
1544
1455
|
this.length = 0;
|
|
1545
1456
|
this._trigger("remove", { items: ids, oldData: items }, senderId);
|
|
1546
1457
|
return ids;
|
|
@@ -1549,13 +1460,12 @@ class DataSet extends DataSetPart {
|
|
|
1549
1460
|
* Find the item with maximum value of a specified field.
|
|
1550
1461
|
*
|
|
1551
1462
|
* @param field - Name of the property that should be searched for max value.
|
|
1552
|
-
*
|
|
1553
1463
|
* @returns Item containing max value, or null if no items.
|
|
1554
1464
|
*/
|
|
1555
1465
|
max(field) {
|
|
1556
1466
|
let max = null;
|
|
1557
1467
|
let maxField = null;
|
|
1558
|
-
for (const item of
|
|
1468
|
+
for (const item of this._data.values()) {
|
|
1559
1469
|
const itemField = item[field];
|
|
1560
1470
|
if (typeof itemField === "number" &&
|
|
1561
1471
|
(maxField == null || itemField > maxField)) {
|
|
@@ -1569,13 +1479,12 @@ class DataSet extends DataSetPart {
|
|
|
1569
1479
|
* Find the item with minimum value of a specified field.
|
|
1570
1480
|
*
|
|
1571
1481
|
* @param field - Name of the property that should be searched for min value.
|
|
1572
|
-
*
|
|
1573
1482
|
* @returns Item containing min value, or null if no items.
|
|
1574
1483
|
*/
|
|
1575
1484
|
min(field) {
|
|
1576
1485
|
let min = null;
|
|
1577
1486
|
let minField = null;
|
|
1578
|
-
for (const item of
|
|
1487
|
+
for (const item of this._data.values()) {
|
|
1579
1488
|
const itemField = item[field];
|
|
1580
1489
|
if (typeof itemField === "number" &&
|
|
1581
1490
|
(minField == null || itemField < minField)) {
|
|
@@ -1589,11 +1498,10 @@ class DataSet extends DataSetPart {
|
|
|
1589
1498
|
* Find all distinct values of a specified field
|
|
1590
1499
|
*
|
|
1591
1500
|
* @param prop - The property name whose distinct values should be returned.
|
|
1592
|
-
*
|
|
1593
1501
|
* @returns Unordered array containing all distinct values. Items without specified property are ignored.
|
|
1594
1502
|
*/
|
|
1595
1503
|
distinct(prop) {
|
|
1596
|
-
const data =
|
|
1504
|
+
const data = this._data;
|
|
1597
1505
|
const itemIds = [...data.keys()];
|
|
1598
1506
|
const values = [];
|
|
1599
1507
|
let count = 0;
|
|
@@ -1619,18 +1527,17 @@ class DataSet extends DataSetPart {
|
|
|
1619
1527
|
* Add a single item. Will fail when an item with the same id already exists.
|
|
1620
1528
|
*
|
|
1621
1529
|
* @param item - A new item to be added.
|
|
1622
|
-
*
|
|
1623
1530
|
* @returns Added item's id. An id is generated when it is not present in the item.
|
|
1624
1531
|
*/
|
|
1625
1532
|
_addItem(item) {
|
|
1626
|
-
const fullItem = ensureFullItem(item,
|
|
1627
|
-
const id = fullItem[
|
|
1533
|
+
const fullItem = ensureFullItem(item, this._idProp);
|
|
1534
|
+
const id = fullItem[this._idProp];
|
|
1628
1535
|
// check whether this id is already taken
|
|
1629
|
-
if (
|
|
1536
|
+
if (this._data.has(id)) {
|
|
1630
1537
|
// item already exists
|
|
1631
1538
|
throw new Error("Cannot add item: item with id " + id + " already exists");
|
|
1632
1539
|
}
|
|
1633
|
-
|
|
1540
|
+
this._data.set(id, fullItem);
|
|
1634
1541
|
++this.length;
|
|
1635
1542
|
return id;
|
|
1636
1543
|
}
|
|
@@ -1639,28 +1546,27 @@ class DataSet extends DataSetPart {
|
|
|
1639
1546
|
* Will fail when the item has no id, or when there does not exist an item with the same id.
|
|
1640
1547
|
*
|
|
1641
1548
|
* @param update - The new item
|
|
1642
|
-
*
|
|
1643
1549
|
* @returns The id of the updated item.
|
|
1644
1550
|
*/
|
|
1645
1551
|
_updateItem(update) {
|
|
1646
|
-
const id = update[
|
|
1552
|
+
const id = update[this._idProp];
|
|
1647
1553
|
if (id == null) {
|
|
1648
1554
|
throw new Error("Cannot update item: item has no id (item: " +
|
|
1649
1555
|
JSON.stringify(update) +
|
|
1650
1556
|
")");
|
|
1651
1557
|
}
|
|
1652
|
-
const item =
|
|
1558
|
+
const item = this._data.get(id);
|
|
1653
1559
|
if (!item) {
|
|
1654
1560
|
// item doesn't exist
|
|
1655
1561
|
throw new Error("Cannot update item: no item with id " + id + " found");
|
|
1656
1562
|
}
|
|
1657
|
-
|
|
1563
|
+
this._data.set(id, { ...item, ...update });
|
|
1658
1564
|
return id;
|
|
1659
1565
|
}
|
|
1660
1566
|
/** @inheritDoc */
|
|
1661
1567
|
stream(ids) {
|
|
1662
1568
|
if (ids) {
|
|
1663
|
-
const data =
|
|
1569
|
+
const data = this._data;
|
|
1664
1570
|
return new DataStream({
|
|
1665
1571
|
*[Symbol.iterator]() {
|
|
1666
1572
|
for (const id of ids) {
|
|
@@ -1674,14 +1580,12 @@ class DataSet extends DataSetPart {
|
|
|
1674
1580
|
}
|
|
1675
1581
|
else {
|
|
1676
1582
|
return new DataStream({
|
|
1677
|
-
[Symbol.iterator]:
|
|
1583
|
+
[Symbol.iterator]: this._data.entries.bind(this._data),
|
|
1678
1584
|
});
|
|
1679
1585
|
}
|
|
1680
1586
|
}
|
|
1681
|
-
}
|
|
1682
|
-
_options = new WeakMap(), _data = new WeakMap(), _idProp = new WeakMap(), _queue$1 = new WeakMap();
|
|
1587
|
+
}
|
|
1683
1588
|
|
|
1684
|
-
var _listener, _data$1, _ids, _options$1;
|
|
1685
1589
|
/**
|
|
1686
1590
|
* DataView
|
|
1687
1591
|
*
|
|
@@ -1738,12 +1642,9 @@ class DataView extends DataSetPart {
|
|
|
1738
1642
|
super();
|
|
1739
1643
|
/** @inheritDoc */
|
|
1740
1644
|
this.length = 0;
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
_options$1.set(this, void 0);
|
|
1745
|
-
__classPrivateFieldSet(this, _options$1, options || {});
|
|
1746
|
-
__classPrivateFieldSet(this, _listener, this._onEvent.bind(this));
|
|
1645
|
+
this._ids = new Set(); // ids of the items currently in memory (just contains a boolean true)
|
|
1646
|
+
this._options = options || {};
|
|
1647
|
+
this._listener = this._onEvent.bind(this);
|
|
1747
1648
|
this.setData(data);
|
|
1748
1649
|
}
|
|
1749
1650
|
/** @inheritDoc */
|
|
@@ -1756,7 +1657,6 @@ class DataView extends DataSetPart {
|
|
|
1756
1657
|
* Set a data source for the view.
|
|
1757
1658
|
*
|
|
1758
1659
|
* @param data - The instance containing data (directly or indirectly).
|
|
1759
|
-
*
|
|
1760
1660
|
* @remarks
|
|
1761
1661
|
* Note that when the data view is bound to a data set it won't be garbage
|
|
1762
1662
|
* collected unless the data set is too. Use `dataView.setData(null)` or
|
|
@@ -1764,35 +1664,35 @@ class DataView extends DataSetPart {
|
|
|
1764
1664
|
* reference.
|
|
1765
1665
|
*/
|
|
1766
1666
|
setData(data) {
|
|
1767
|
-
if (
|
|
1667
|
+
if (this._data) {
|
|
1768
1668
|
// unsubscribe from current dataset
|
|
1769
|
-
if (
|
|
1770
|
-
|
|
1669
|
+
if (this._data.off) {
|
|
1670
|
+
this._data.off("*", this._listener);
|
|
1771
1671
|
}
|
|
1772
1672
|
// trigger a remove of all items in memory
|
|
1773
|
-
const ids =
|
|
1774
|
-
const items =
|
|
1775
|
-
|
|
1673
|
+
const ids = this._data.getIds({ filter: this._options.filter });
|
|
1674
|
+
const items = this._data.get(ids);
|
|
1675
|
+
this._ids.clear();
|
|
1776
1676
|
this.length = 0;
|
|
1777
1677
|
this._trigger("remove", { items: ids, oldData: items });
|
|
1778
1678
|
}
|
|
1779
1679
|
if (data != null) {
|
|
1780
|
-
|
|
1680
|
+
this._data = data;
|
|
1781
1681
|
// trigger an add of all added items
|
|
1782
|
-
const ids =
|
|
1682
|
+
const ids = this._data.getIds({ filter: this._options.filter });
|
|
1783
1683
|
for (let i = 0, len = ids.length; i < len; i++) {
|
|
1784
1684
|
const id = ids[i];
|
|
1785
|
-
|
|
1685
|
+
this._ids.add(id);
|
|
1786
1686
|
}
|
|
1787
1687
|
this.length = ids.length;
|
|
1788
1688
|
this._trigger("add", { items: ids });
|
|
1789
1689
|
}
|
|
1790
1690
|
else {
|
|
1791
|
-
|
|
1691
|
+
this._data = new DataSet();
|
|
1792
1692
|
}
|
|
1793
1693
|
// subscribe to new dataset
|
|
1794
|
-
if (
|
|
1795
|
-
|
|
1694
|
+
if (this._data.on) {
|
|
1695
|
+
this._data.on("*", this._listener);
|
|
1796
1696
|
}
|
|
1797
1697
|
}
|
|
1798
1698
|
/**
|
|
@@ -1800,10 +1700,10 @@ class DataView extends DataSetPart {
|
|
|
1800
1700
|
* Useful when the DataView has a filter function containing a variable parameter.
|
|
1801
1701
|
*/
|
|
1802
1702
|
refresh() {
|
|
1803
|
-
const ids =
|
|
1804
|
-
filter:
|
|
1703
|
+
const ids = this._data.getIds({
|
|
1704
|
+
filter: this._options.filter,
|
|
1805
1705
|
});
|
|
1806
|
-
const oldIds = [...
|
|
1706
|
+
const oldIds = [...this._ids];
|
|
1807
1707
|
const newIds = {};
|
|
1808
1708
|
const addedIds = [];
|
|
1809
1709
|
const removedIds = [];
|
|
@@ -1812,15 +1712,15 @@ class DataView extends DataSetPart {
|
|
|
1812
1712
|
for (let i = 0, len = ids.length; i < len; i++) {
|
|
1813
1713
|
const id = ids[i];
|
|
1814
1714
|
newIds[id] = true;
|
|
1815
|
-
if (!
|
|
1715
|
+
if (!this._ids.has(id)) {
|
|
1816
1716
|
addedIds.push(id);
|
|
1817
|
-
|
|
1717
|
+
this._ids.add(id);
|
|
1818
1718
|
}
|
|
1819
1719
|
}
|
|
1820
1720
|
// check for removals
|
|
1821
1721
|
for (let i = 0, len = oldIds.length; i < len; i++) {
|
|
1822
1722
|
const id = oldIds[i];
|
|
1823
|
-
const item =
|
|
1723
|
+
const item = this._data.get(id);
|
|
1824
1724
|
if (item == null) {
|
|
1825
1725
|
// @TODO: Investigate.
|
|
1826
1726
|
// Doesn't happen during tests or examples.
|
|
@@ -1831,7 +1731,7 @@ class DataView extends DataSetPart {
|
|
|
1831
1731
|
else if (!newIds[id]) {
|
|
1832
1732
|
removedIds.push(id);
|
|
1833
1733
|
removedItems.push(item);
|
|
1834
|
-
|
|
1734
|
+
this._ids.delete(id);
|
|
1835
1735
|
}
|
|
1836
1736
|
}
|
|
1837
1737
|
this.length += addedIds.length - removedIds.length;
|
|
@@ -1845,7 +1745,7 @@ class DataView extends DataSetPart {
|
|
|
1845
1745
|
}
|
|
1846
1746
|
/** @inheritDoc */
|
|
1847
1747
|
get(first, second) {
|
|
1848
|
-
if (
|
|
1748
|
+
if (this._data == null) {
|
|
1849
1749
|
return null;
|
|
1850
1750
|
}
|
|
1851
1751
|
// parse the arguments
|
|
@@ -1859,9 +1759,9 @@ class DataView extends DataSetPart {
|
|
|
1859
1759
|
options = first;
|
|
1860
1760
|
}
|
|
1861
1761
|
// extend the options with the default options and provided options
|
|
1862
|
-
const viewOptions = Object.assign({},
|
|
1762
|
+
const viewOptions = Object.assign({}, this._options, options);
|
|
1863
1763
|
// create a combined filter method when needed
|
|
1864
|
-
const thisFilter =
|
|
1764
|
+
const thisFilter = this._options.filter;
|
|
1865
1765
|
const optionsFilter = options && options.filter;
|
|
1866
1766
|
if (thisFilter && optionsFilter) {
|
|
1867
1767
|
viewOptions.filter = (item) => {
|
|
@@ -1869,16 +1769,16 @@ class DataView extends DataSetPart {
|
|
|
1869
1769
|
};
|
|
1870
1770
|
}
|
|
1871
1771
|
if (ids == null) {
|
|
1872
|
-
return
|
|
1772
|
+
return this._data.get(viewOptions);
|
|
1873
1773
|
}
|
|
1874
1774
|
else {
|
|
1875
|
-
return
|
|
1775
|
+
return this._data.get(ids, viewOptions);
|
|
1876
1776
|
}
|
|
1877
1777
|
}
|
|
1878
1778
|
/** @inheritDoc */
|
|
1879
1779
|
getIds(options) {
|
|
1880
|
-
if (
|
|
1881
|
-
const defaultFilter =
|
|
1780
|
+
if (this._data.length) {
|
|
1781
|
+
const defaultFilter = this._options.filter;
|
|
1882
1782
|
const optionsFilter = options != null ? options.filter : null;
|
|
1883
1783
|
let filter;
|
|
1884
1784
|
if (optionsFilter) {
|
|
@@ -1894,7 +1794,7 @@ class DataView extends DataSetPart {
|
|
|
1894
1794
|
else {
|
|
1895
1795
|
filter = defaultFilter;
|
|
1896
1796
|
}
|
|
1897
|
-
return
|
|
1797
|
+
return this._data.getIds({
|
|
1898
1798
|
filter: filter,
|
|
1899
1799
|
order: options && options.order,
|
|
1900
1800
|
});
|
|
@@ -1905,8 +1805,8 @@ class DataView extends DataSetPart {
|
|
|
1905
1805
|
}
|
|
1906
1806
|
/** @inheritDoc */
|
|
1907
1807
|
forEach(callback, options) {
|
|
1908
|
-
if (
|
|
1909
|
-
const defaultFilter =
|
|
1808
|
+
if (this._data) {
|
|
1809
|
+
const defaultFilter = this._options.filter;
|
|
1910
1810
|
const optionsFilter = options && options.filter;
|
|
1911
1811
|
let filter;
|
|
1912
1812
|
if (optionsFilter) {
|
|
@@ -1922,7 +1822,7 @@ class DataView extends DataSetPart {
|
|
|
1922
1822
|
else {
|
|
1923
1823
|
filter = defaultFilter;
|
|
1924
1824
|
}
|
|
1925
|
-
|
|
1825
|
+
this._data.forEach(callback, {
|
|
1926
1826
|
filter: filter,
|
|
1927
1827
|
order: options && options.order,
|
|
1928
1828
|
});
|
|
@@ -1930,8 +1830,8 @@ class DataView extends DataSetPart {
|
|
|
1930
1830
|
}
|
|
1931
1831
|
/** @inheritDoc */
|
|
1932
1832
|
map(callback, options) {
|
|
1933
|
-
if (
|
|
1934
|
-
const defaultFilter =
|
|
1833
|
+
if (this._data) {
|
|
1834
|
+
const defaultFilter = this._options.filter;
|
|
1935
1835
|
const optionsFilter = options && options.filter;
|
|
1936
1836
|
let filter;
|
|
1937
1837
|
if (optionsFilter) {
|
|
@@ -1947,7 +1847,7 @@ class DataView extends DataSetPart {
|
|
|
1947
1847
|
else {
|
|
1948
1848
|
filter = defaultFilter;
|
|
1949
1849
|
}
|
|
1950
|
-
return
|
|
1850
|
+
return this._data.map(callback, {
|
|
1951
1851
|
filter: filter,
|
|
1952
1852
|
order: options && options.order,
|
|
1953
1853
|
});
|
|
@@ -1958,12 +1858,12 @@ class DataView extends DataSetPart {
|
|
|
1958
1858
|
}
|
|
1959
1859
|
/** @inheritDoc */
|
|
1960
1860
|
getDataSet() {
|
|
1961
|
-
return
|
|
1861
|
+
return this._data.getDataSet();
|
|
1962
1862
|
}
|
|
1963
1863
|
/** @inheritDoc */
|
|
1964
1864
|
stream(ids) {
|
|
1965
|
-
return
|
|
1966
|
-
[Symbol.iterator]:
|
|
1865
|
+
return this._data.stream(ids || {
|
|
1866
|
+
[Symbol.iterator]: this._ids.keys.bind(this._ids),
|
|
1967
1867
|
});
|
|
1968
1868
|
}
|
|
1969
1869
|
/**
|
|
@@ -1975,9 +1875,8 @@ class DataView extends DataSetPart {
|
|
|
1975
1875
|
* already. It's stricter version of `dataView.setData(null)`.
|
|
1976
1876
|
*/
|
|
1977
1877
|
dispose() {
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
__classPrivateFieldGet(this, _data$1).off("*", __classPrivateFieldGet(this, _listener));
|
|
1878
|
+
if (this._data?.off) {
|
|
1879
|
+
this._data.off("*", this._listener);
|
|
1981
1880
|
}
|
|
1982
1881
|
const message = "This data view has already been disposed of.";
|
|
1983
1882
|
const replacement = {
|
|
@@ -2001,7 +1900,7 @@ class DataView extends DataSetPart {
|
|
|
2001
1900
|
* @param senderId - Id supplied by the sender.
|
|
2002
1901
|
*/
|
|
2003
1902
|
_onEvent(event, params, senderId) {
|
|
2004
|
-
if (!params || !params.items || !
|
|
1903
|
+
if (!params || !params.items || !this._data) {
|
|
2005
1904
|
return;
|
|
2006
1905
|
}
|
|
2007
1906
|
const ids = params.items;
|
|
@@ -2018,7 +1917,7 @@ class DataView extends DataSetPart {
|
|
|
2018
1917
|
const id = ids[i];
|
|
2019
1918
|
const item = this.get(id);
|
|
2020
1919
|
if (item) {
|
|
2021
|
-
|
|
1920
|
+
this._ids.add(id);
|
|
2022
1921
|
addedIds.push(id);
|
|
2023
1922
|
}
|
|
2024
1923
|
}
|
|
@@ -2030,19 +1929,19 @@ class DataView extends DataSetPart {
|
|
|
2030
1929
|
const id = ids[i];
|
|
2031
1930
|
const item = this.get(id);
|
|
2032
1931
|
if (item) {
|
|
2033
|
-
if (
|
|
1932
|
+
if (this._ids.has(id)) {
|
|
2034
1933
|
updatedIds.push(id);
|
|
2035
1934
|
updatedItems.push(params.data[i]);
|
|
2036
1935
|
oldItems.push(params.oldData[i]);
|
|
2037
1936
|
}
|
|
2038
1937
|
else {
|
|
2039
|
-
|
|
1938
|
+
this._ids.add(id);
|
|
2040
1939
|
addedIds.push(id);
|
|
2041
1940
|
}
|
|
2042
1941
|
}
|
|
2043
1942
|
else {
|
|
2044
|
-
if (
|
|
2045
|
-
|
|
1943
|
+
if (this._ids.has(id)) {
|
|
1944
|
+
this._ids.delete(id);
|
|
2046
1945
|
removedIds.push(id);
|
|
2047
1946
|
removedItems.push(params.oldData[i]);
|
|
2048
1947
|
}
|
|
@@ -2053,8 +1952,8 @@ class DataView extends DataSetPart {
|
|
|
2053
1952
|
// filter the ids of the removed items
|
|
2054
1953
|
for (let i = 0, len = ids.length; i < len; i++) {
|
|
2055
1954
|
const id = ids[i];
|
|
2056
|
-
if (
|
|
2057
|
-
|
|
1955
|
+
if (this._ids.has(id)) {
|
|
1956
|
+
this._ids.delete(id);
|
|
2058
1957
|
removedIds.push(id);
|
|
2059
1958
|
removedItems.push(params.oldData[i]);
|
|
2060
1959
|
}
|
|
@@ -2072,15 +1971,13 @@ class DataView extends DataSetPart {
|
|
|
2072
1971
|
this._trigger("remove", { items: removedIds, oldData: removedItems }, senderId);
|
|
2073
1972
|
}
|
|
2074
1973
|
}
|
|
2075
|
-
}
|
|
2076
|
-
_listener = new WeakMap(), _data$1 = new WeakMap(), _ids = new WeakMap(), _options$1 = new WeakMap();
|
|
1974
|
+
}
|
|
2077
1975
|
|
|
2078
1976
|
/**
|
|
2079
1977
|
* Check that given value is compatible with Vis Data Set interface.
|
|
2080
1978
|
*
|
|
2081
1979
|
* @param idProp - The expected property to contain item id.
|
|
2082
1980
|
* @param v - The value to be tested.
|
|
2083
|
-
*
|
|
2084
1981
|
* @returns True if all expected values and methods match, false otherwise.
|
|
2085
1982
|
*/
|
|
2086
1983
|
function isDataSetLike(idProp, v) {
|
|
@@ -2112,7 +2009,6 @@ function isDataSetLike(idProp, v) {
|
|
|
2112
2009
|
*
|
|
2113
2010
|
* @param idProp - The expected property to contain item id.
|
|
2114
2011
|
* @param v - The value to be tested.
|
|
2115
|
-
*
|
|
2116
2012
|
* @returns True if all expected values and methods match, false otherwise.
|
|
2117
2013
|
*/
|
|
2118
2014
|
function isDataViewLike(idProp, v) {
|