@veloceapps/sdk 8.0.0-193 → 8.0.0-195

Sign up to get free protection for your applications and to get access to all the features.
@@ -2038,11 +2038,15 @@ class ConfigurationStateService {
2038
2038
  this.isInitialized$ = new BehaviorSubject(false);
2039
2039
  this.canceledConfiguration$ = new Subject();
2040
2040
  this.NOT_INITIALIZED = Symbol();
2041
+ this.EXECUTION_BUFFER_TIME = 100;
2041
2042
  this.executedFunctions = {};
2042
2043
  this.stateId = null;
2043
2044
  this.ownerId = '';
2044
2045
  this.subscriptions = {};
2045
2046
  this.configurationStore = {};
2047
+ this.statefulExecutionInProgress$ = new BehaviorSubject(false);
2048
+ this.statefulRequestStream$ = new Subject();
2049
+ this.statefulExecutionRequest$ = this.initBufferedRequest$();
2046
2050
  }
2047
2051
  init$() {
2048
2052
  let request$;
@@ -2272,14 +2276,34 @@ class ConfigurationStateService {
2272
2276
  return throwError(() => error);
2273
2277
  }));
2274
2278
  }
2275
- executeStateful$(request) {
2276
- if (!this.flowStateService.stateId || !this.stateId) {
2277
- return of();
2278
- }
2279
- return this.flowStateApiService.executeConfiguration(this.flowStateService.stateId, this.stateId, request).pipe(tap$1(response => {
2280
- this.stateId = response.stateId;
2279
+ initBufferedRequest$() {
2280
+ return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap(requests => {
2281
+ if (!this.flowStateService.stateId || !this.stateId) {
2282
+ throw 'Stateful session is not initialized';
2283
+ }
2284
+ // merge buffered requests
2285
+ const request = {
2286
+ actions: requests.flatMap(({ actions }) => actions).filter(isDefined),
2287
+ selectors: requests
2288
+ .map(({ selectors }) => selectors)
2289
+ .filter(isDefined)
2290
+ .reduce((acc, selectorsMap) => Object.assign(acc, selectorsMap), {}),
2291
+ };
2292
+ this.statefulExecutionInProgress$.next(true);
2293
+ return this.flowStateApiService.executeConfiguration(this.flowStateService.stateId, this.stateId, request);
2294
+ }), tap$1(({ stateId }) => (this.stateId = stateId)), share(), tap$1(() => this.statefulExecutionInProgress$.next(false)), catchError(e => {
2295
+ this.statefulExecutionInProgress$.next(false);
2296
+ return throwError(() => e);
2281
2297
  }));
2282
2298
  }
2299
+ executeStateful$(request) {
2300
+ return this.statefulExecutionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
2301
+ // make sure stream switches to statefulExecutionRequest$ before pushing an execution request
2302
+ combineLatest([
2303
+ this.statefulExecutionRequest$,
2304
+ of(undefined).pipe(tap$1(() => this.statefulRequestStream$.next(request))),
2305
+ ])), map$1(([response]) => response), take$1(1));
2306
+ }
2283
2307
  executeActionScript(request, processor) {
2284
2308
  const { actions } = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer ?? {};
2285
2309
  const configurationProcessor = actions?.find(action => action.apiName === processor.apiName);