@ejfdelgado/ejflab-common 1.16.7 → 1.16.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/MyTuples.js +14 -6
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.16.7",
4
+ "version": "1.16.9",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
package/src/MyTuples.js CHANGED
@@ -4,6 +4,15 @@ const { SimpleObj } = require("./SimpleObj");
4
4
  const TAMANIO_ALEATORIO = 10;
5
5
  const MAX_BUFFER_CHANGES = 50;
6
6
 
7
+ const assureSorted = (batch) => {
8
+ const compFun = (a, b) => {
9
+ return a.k.length - b.k.length;
10
+ };
11
+ batch['*'].sort(compFun);
12
+ batch['-'].sort(compFun);
13
+ batch['+'].sort(compFun);
14
+ };
15
+
7
16
  const fakeProcessor = ({ min = 500, max = 1000 }) => {
8
17
  return new Promise((resolve) => {
9
18
  const tiempo = min + Math.random() * (max - min);
@@ -327,6 +336,10 @@ class MyTuples {
327
336
  },
328
337
  affect: (batch, listenerKeys = [], callback = null) => {
329
338
  const tuplas1 = MyTuples.getTuples(JSON.parse(myFreeze));
339
+
340
+ // assure changes are sorted
341
+ assureSorted(batch);
342
+
330
343
  const llavesBorrar = batch["-"];
331
344
  const llavesNuevasModificadas = batch["*"].concat(batch["+"]);
332
345
 
@@ -420,12 +433,7 @@ class MyTuples {
420
433
  }
421
434
  }
422
435
 
423
- const compFun = (a, b) => {
424
- return a.k.length - b.k.length;
425
- };
426
- batch['*'].sort(compFun);
427
- batch['-'].sort(compFun);
428
- batch['+'].sort(compFun);
436
+ assureSorted(batch);
429
437
 
430
438
  batch.total = batch['*'].length + batch['-'].length + batch['+'].length;
431
439
  if (batch.total > 0) {