@veloceapps/sdk 10.0.0-0 → 10.0.0-10

Sign up to get free protection for your applications and to get access to all the features.
@@ -441,7 +441,8 @@ class FlowStateService {
441
441
  this.EXECUTION_BUFFER_TIME = 100;
442
442
  this.executedFunctions = {};
443
443
  this.stateId$ = new BehaviorSubject(null);
444
- this._hasStatefulUnsavedChanges = true;
444
+ this.initialStatefulData = {};
445
+ this.trackedStatefulChangesMap = new Map();
445
446
  this.processors = {};
446
447
  this.subscriptions = {};
447
448
  this.flowStore = {};
@@ -524,7 +525,7 @@ class FlowStateService {
524
525
  }
525
526
  get hasUnsavedChanges() {
526
527
  return this.getFlowSafe().properties.stateful
527
- ? this._hasStatefulUnsavedChanges
528
+ ? Array.from(this.trackedStatefulChangesMap.values()).some(Boolean)
528
529
  : this.quoteDraftService.hasUnsavedChanges;
529
530
  }
530
531
  get stateId() {
@@ -589,6 +590,9 @@ class FlowStateService {
589
590
  data$: new BehaviorSubject(this.NOT_INITIALIZED),
590
591
  };
591
592
  this.subscriptions[requestId] = subscription;
593
+ if (options === null || options === void 0 ? void 0 : options.trackedChanges) {
594
+ this.trackedStatefulChangesMap.set(requestId, false);
595
+ }
592
596
  if (!(options === null || options === void 0 ? void 0 : options.cold)) {
593
597
  this.executeRequest$(request).subscribe();
594
598
  }
@@ -603,7 +607,11 @@ class FlowStateService {
603
607
  save$() {
604
608
  if (this.getFlowSafe().properties.stateful) {
605
609
  if (this.stateId$.value) {
606
- return this.flowStateApiService.save(this.stateId$.value);
610
+ return this.flowStateApiService.save(this.stateId$.value).pipe(tap$1(() => {
611
+ Array.from(this.trackedStatefulChangesMap.keys()).forEach(key => {
612
+ this.trackedStatefulChangesMap.set(key, false);
613
+ });
614
+ }));
607
615
  }
608
616
  }
609
617
  else {
@@ -684,6 +692,7 @@ class FlowStateService {
684
692
  }
685
693
  const subscription$ = (_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$;
686
694
  if (subscription$ && subscription$.value !== selectorResult) {
695
+ this.checkStatefulChanges(requestId, selectorResult);
687
696
  subscription$.next(selectorResult);
688
697
  }
689
698
  });
@@ -936,6 +945,15 @@ class FlowStateService {
936
945
  });
937
946
  return request;
938
947
  }
948
+ checkStatefulChanges(requestId, selectorResult) {
949
+ if (this.trackedStatefulChangesMap.has(requestId)) {
950
+ if (!this.initialStatefulData[requestId]) {
951
+ this.initialStatefulData[requestId] = selectorResult;
952
+ }
953
+ const hasChanges = !isEqual(this.initialStatefulData[requestId], selectorResult);
954
+ this.trackedStatefulChangesMap.set(requestId, hasChanges);
955
+ }
956
+ }
939
957
  }
940
958
  FlowStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, deps: [{ token: ContextService }, { token: QuoteDraftService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.ConfigurationProcessorsApiService }, { token: i1.FlowStateApiService }, { token: i1.QuoteApiService }, { token: i6.ToastService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
941
959
  FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService });
@@ -2042,6 +2060,7 @@ class ConfigurationStateService {
2042
2060
  this.configurationStore = {};
2043
2061
  this.executionInProgress$ = new BehaviorSubject(false);
2044
2062
  this.statefulRequestStream$ = new Subject();
2063
+ this.statelessExecutionRequest$ = null;
2045
2064
  this.statefulExecutionRequest$ = this.initBufferedRequest$();
2046
2065
  }
2047
2066
  get isExecutionInProgress$() {
@@ -2089,7 +2108,15 @@ class ConfigurationStateService {
2089
2108
  actions: [{ name: actionName, inputData }],
2090
2109
  };
2091
2110
  const request = this.execToRequest(exec);
2092
- return this.executeRequest$(request);
2111
+ const executionRequest$ = this.executeRequest$(request);
2112
+ if (this.isStatefulConfiguration) {
2113
+ return executionRequest$;
2114
+ }
2115
+ // prevent parallel configuration requests in stateless mode
2116
+ if (!this.statelessExecutionRequest$) {
2117
+ this.statelessExecutionRequest$ = executionRequest$.pipe(shareReplay$1(), take$1(1), finalize(() => (this.statelessExecutionRequest$ = null)));
2118
+ }
2119
+ return this.statelessExecutionRequest$;
2093
2120
  }
2094
2121
  select$(selectorName, inputData = {}) {
2095
2122
  const requestId = UUID.UUID();