@koalarx/ui 13.2.5 → 13.2.8

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.
@@ -15,7 +15,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';
15
15
  import * as i2$1 from '@angular/router';
16
16
  import { NavigationError, NavigationEnd, NavigationCancel, NavigationStart, RouterModule } from '@angular/router';
17
17
  import * as i7 from '@angular/material/core';
18
- import { BehaviorSubject, interval, Observable } from 'rxjs';
18
+ import { BehaviorSubject, interval, Observable, skipWhile } from 'rxjs';
19
19
  import jwt from 'jwt-decode';
20
20
  import * as i4 from '@koalarx/ui/menu';
21
21
  import { menuStateSubject } from '@koalarx/ui/menu';
@@ -1244,20 +1244,38 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1244
1244
  }], ctorParameters: function () { return [{ type: i1$2.HttpClient }, { type: KoalaOAuth2Service }]; } });
1245
1245
 
1246
1246
  class KoalaApiRequesterCache {
1247
- static setInCache(cache) {
1248
- const index = koala(this.cache).array().getIndex('name', cache.name);
1249
- if (index >= 0) {
1250
- this.cache[index] = cache;
1251
- }
1252
- else {
1253
- this.cache.push(cache);
1247
+ static createCache(name) {
1248
+ if (!this.hasCache(name)) {
1249
+ this.cache.push({
1250
+ name,
1251
+ data: new BehaviorSubject(undefined)
1252
+ });
1254
1253
  }
1255
1254
  }
1256
- static getCache(name) {
1255
+ static setDataInCache(name, data) {
1256
+ this.getCacheSubject(name)?.next(data);
1257
+ }
1258
+ static getCacheSubject(name) {
1257
1259
  return this.cache.find(item => item.name === name)?.data;
1258
1260
  }
1261
+ static getCacheAsObservable(name) {
1262
+ return new Observable(observe => {
1263
+ this.getCacheSubject(name)
1264
+ .pipe(skipWhile(value => value === undefined))
1265
+ .subscribe({
1266
+ next: value => {
1267
+ observe.next(value);
1268
+ observe.complete();
1269
+ },
1270
+ error: err => {
1271
+ observe.error(err);
1272
+ observe.complete();
1273
+ }
1274
+ });
1275
+ });
1276
+ }
1259
1277
  static hasCache(name) {
1260
- return !!this.getCache(name);
1278
+ return !!this.getCacheSubject(name);
1261
1279
  }
1262
1280
  }
1263
1281
  KoalaApiRequesterCache.cache = [];
@@ -1322,23 +1340,18 @@ class KoalaApiRequesterBase {
1322
1340
  return filter ?? null;
1323
1341
  }
1324
1342
  request(method, url, data = {}) {
1325
- this.startCache(url);
1343
+ if (this.enableCache && KoalaApiRequesterCache.hasCache(url)) {
1344
+ return KoalaApiRequesterCache.getCacheAsObservable(url);
1345
+ }
1346
+ KoalaApiRequesterCache.createCache(url);
1326
1347
  return this.koalaService
1327
1348
  .request(method, url, data)
1328
1349
  .pipe(map(response => {
1329
1350
  if (this.enableCache)
1330
- KoalaApiRequesterCache.setInCache({ name: url, data: response });
1351
+ KoalaApiRequesterCache.setDataInCache(url, response);
1331
1352
  return response;
1332
1353
  }));
1333
1354
  }
1334
- startCache(endpoint) {
1335
- if (this.enableCache && KoalaApiRequesterCache.hasCache(endpoint)) {
1336
- return new Observable(observe => {
1337
- observe.next(KoalaApiRequesterCache.getCache(endpoint));
1338
- observe.complete();
1339
- });
1340
- }
1341
- }
1342
1355
  }
1343
1356
 
1344
1357
  class KoalaRequestService {
@@ -1436,5 +1449,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1436
1449
  * Generated bundle index. Do not edit.
1437
1450
  */
1438
1451
 
1439
- export { KOALA_LOADER_SUBJECT, KoalaApiRequesterBase, KoalaApiRequesterService, KoalaClientError, KoalaEnvironment, KoalaErrorsHelper, KoalaLanguageHelper, KoalaLoaderService, KoalaNotFoundError, KoalaOAuth2Service, KoalaOauthConfig, KoalaPageModule, KoalaParameterHashLocationStrategy, KoalaRequestHeaderHelper, KoalaRequestService, KoalaResponseFactory, KoalaSuccessError, KoalaTokenService, KoalaUnhautorizedError, LoaderBarPageComponent, NgxKoalaModule, NotificationComponent, PageComponent };
1452
+ export { KOALA_LOADER_SUBJECT, KoalaApiRequesterBase, KoalaApiRequesterCache, KoalaApiRequesterService, KoalaClientError, KoalaEnvironment, KoalaErrorsHelper, KoalaLanguageHelper, KoalaLoaderService, KoalaNotFoundError, KoalaOAuth2Service, KoalaOauthConfig, KoalaPageModule, KoalaParameterHashLocationStrategy, KoalaRequestHeaderHelper, KoalaRequestService, KoalaResponseFactory, KoalaSuccessError, KoalaTokenService, KoalaUnhautorizedError, LoaderBarPageComponent, NgxKoalaModule, NotificationComponent, PageComponent };
1440
1453
  //# sourceMappingURL=koalarx-ui-core.mjs.map