@bbn/bbn 1.0.187 → 1.0.189

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.
@@ -8,9 +8,9 @@
8
8
  *
9
9
  * @param {String} requestId
10
10
  * @param {Promise} prom
11
- * @param {Object} source
11
+ * @param {Object} aborter
12
12
  *
13
13
  * @returns {Number} The timestamp (in ms)
14
14
  */
15
- declare const _addLoader: (requestId: any, prom: any, source: any) => number;
15
+ declare const _addLoader: (requestId: any, prom: any, aborter: any) => number;
16
16
  export { _addLoader };
@@ -9,11 +9,11 @@ import { substr } from '../string/substr.js';
9
9
  *
10
10
  * @param {String} requestId
11
11
  * @param {Promise} prom
12
- * @param {Object} source
12
+ * @param {Object} aborter
13
13
  *
14
14
  * @returns {Number} The timestamp (in ms)
15
15
  */
16
- var _addLoader = function (requestId, prom, source) {
16
+ var _addLoader = function (requestId, prom, aborter) {
17
17
  /** @var {Number} tst Current timestamp */
18
18
  var tst = new Date().getTime();
19
19
  /** @var {String} url The original URL (part of requestId before : and md5) */
@@ -23,7 +23,7 @@ var _addLoader = function (requestId, prom, source) {
23
23
  key: requestId,
24
24
  url: url,
25
25
  loader: prom,
26
- source: source,
26
+ aborter: aborter,
27
27
  loading: true,
28
28
  error: false,
29
29
  abort: false,
@@ -23,14 +23,11 @@ import { getLoader } from './getLoader.js';
23
23
  */
24
24
  var abort = function (requestId) {
25
25
  var loader = getLoader(requestId);
26
- if (loader && loader.source) {
27
- //_deleteLoader(requestId);
28
- loader.source.cancel('Operation canceled by the user.');
26
+ if (loader === null || loader === void 0 ? void 0 : loader.aborter) {
27
+ loader.aborter.abort('Operation canceled by the user.');
29
28
  }
30
- /*
31
- else {
29
+ else {
32
30
  throw new Error("Impossible to find the loader " + requestId);
33
- }
34
- */
31
+ }
35
32
  };
36
33
  export { abort };
@@ -107,11 +107,10 @@ var ajax = function (url, datatype, data, success, failure, abort) {
107
107
  if (bbn.env.token) {
108
108
  extend(data || {}, { _bbn_token: bbn.env.token });
109
109
  }
110
- var cancelToken = axios.CancelToken;
111
- var source = cancelToken.source();
110
+ var aborter = new AbortController();
112
111
  var options = {
113
112
  responseType: datatype,
114
- cancelToken: source.token,
113
+ signal: aborter.signal
115
114
  };
116
115
  if (datatype === "text") {
117
116
  options['headers'] = {
@@ -164,7 +163,7 @@ var ajax = function (url, datatype, data, success, failure, abort) {
164
163
  }
165
164
  }
166
165
  });
167
- var tst_1 = _addLoader(requestId_1, loader_1, source);
166
+ var tst_1 = _addLoader(requestId_1, loader_1, aborter);
168
167
  bbn.fn.defaultStartLoadingFunction(url, tst_1, data, requestId_1);
169
168
  return loader_1;
170
169
  }
@@ -1,5 +1,7 @@
1
1
  import { isArray } from '../type/isArray.js';
2
2
  import { hash } from '../string/hash.js';
3
+ import { isSame } from '../type/isSame.js';
4
+ import { search } from './search.js';
3
5
  var mutateArray = function (a1, a2) {
4
6
  if (!isArray(a1, a2)) {
5
7
  throw new TypeError('mutateArray can only be called with arrays');
@@ -17,10 +19,11 @@ var mutateArray = function (a1, a2) {
17
19
  a1.splice(i, 1);
18
20
  }
19
21
  }
20
- var _loop_1 = function (j) {
21
- if (j >= a1.length || hash(a1[j]) !== hash(a1Ordered[j])) {
22
+ // Insert or move items to match the order of a2
23
+ for (var j = 0; j < a1Ordered.length; j++) {
24
+ if ((j >= a1.length) || !isSame(a1[j], a1Ordered[j])) {
22
25
  // Find the index of the item in a1, if it exists
23
- var indexInA1 = a1.findIndex(function (item) { return hash(item) === hash(a1Ordered[j]); });
26
+ var indexInA1 = search(a1, a1Ordered[j]);
24
27
  if (indexInA1 !== -1) {
25
28
  // Move the item to the correct position if it already exists in a1
26
29
  var itemToMove = a1.splice(indexInA1, 1)[0];
@@ -31,10 +34,6 @@ var mutateArray = function (a1, a2) {
31
34
  a1.splice(j, 0, a1Ordered[j]);
32
35
  }
33
36
  }
34
- };
35
- // Insert or move items to match the order of a2
36
- for (var j = 0; j < a1Ordered.length; j++) {
37
- _loop_1(j);
38
37
  }
39
38
  // If a1 has extra items at the end (not present in a2), remove them
40
39
  if (a1.length > a1Ordered.length) {
package/dist/fn.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  declare const fn: {
2
- _addLoader: (requestId: any, prom: any, source: any) => number;
2
+ _addLoader: (requestId: any, prom: any, aborter: any) => number;
3
3
  _compareValues: (a: any, b: any, prop: any, dir?: string) => 0 | 1 | -1;
4
4
  _deleteLoader: (requestId: any, res?: any, isAbort?: boolean) => boolean;
5
5
  abort: (requestId: any) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.187",
3
+ "version": "1.0.189",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",