@dereekb/rxjs 10.1.30 → 11.0.0

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.
package/index.cjs.js CHANGED
@@ -1729,7 +1729,9 @@ function emitAfterDelay(value, delayTime) {
1729
1729
  }
1730
1730
 
1731
1731
  /**
1732
- * Equivalent to distinctUntilChanged() using isEqualObject()
1732
+ * Equivalent to distinctUntilChanged() using areEqualPOJOValues().
1733
+ *
1734
+ * The compared objects should only be POJOs or compatable with the areEqualPOJOValues() function.
1733
1735
  */
1734
1736
  function distinctUntilObjectValuesChanged() {
1735
1737
  return rxjs.distinctUntilChanged((a, b) => util.areEqualPOJOValues(a, b));
@@ -1749,6 +1751,7 @@ function filterIfObjectValuesUnchanged(input) {
1749
1751
  */
1750
1752
  class SubscriptionObject {
1751
1753
  constructor(sub) {
1754
+ this._subscription = void 0;
1752
1755
  if (sub) {
1753
1756
  this.setSub(sub);
1754
1757
  }
@@ -1780,13 +1783,14 @@ class SubscriptionObject {
1780
1783
  */
1781
1784
  class MultiSubscriptionObject {
1782
1785
  constructor(subs) {
1786
+ this._subscriptions = void 0;
1783
1787
  if (subs) {
1784
1788
  this.setSubs(subs);
1785
1789
  }
1786
1790
  }
1787
1791
  get hasSubscription() {
1788
- var _a;
1789
- return Boolean((_a = this._subscriptions) === null || _a === void 0 ? void 0 : _a.length);
1792
+ var _this$_subscriptions;
1793
+ return Boolean((_this$_subscriptions = this._subscriptions) == null ? void 0 : _this$_subscriptions.length);
1790
1794
  }
1791
1795
  set subscriptions(subs) {
1792
1796
  this.setSubs(subs);
@@ -1817,7 +1821,7 @@ class FilterSourceInstance {
1817
1821
  this._initialFilter = new rxjs.BehaviorSubject(undefined);
1818
1822
  this._defaultFilter = new rxjs.BehaviorSubject(undefined);
1819
1823
  this.defaultFilter$ = this._defaultFilter.pipe(switchMapMaybeObs());
1820
- this.initialFilter$ = rxjs.combineLatest([this._initialFilter, this._defaultFilter]).pipe(rxjs.map(([a, b]) => a !== null && a !== void 0 ? a : b), switchMapMaybeObs(), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
1824
+ this.initialFilter$ = rxjs.combineLatest([this._initialFilter, this._defaultFilter]).pipe(rxjs.map(([a, b]) => a != null ? a : b), switchMapMaybeObs(), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
1821
1825
  /**
1822
1826
  * filter$ uses the latest value from any filter.
1823
1827
  */
@@ -1914,6 +1918,9 @@ class FilterMap {
1914
1918
  }
1915
1919
  class FilterMapKeyInstance {
1916
1920
  constructor(dbxFilterMap, key) {
1921
+ this.dbxFilterMap = void 0;
1922
+ this.key = void 0;
1923
+ this.filter$ = void 0;
1917
1924
  this.dbxFilterMap = dbxFilterMap;
1918
1925
  this.key = key;
1919
1926
  this.filter$ = this.dbxFilterMap.filterForKey(this.key);
@@ -1927,13 +1934,15 @@ class FilterMapKeyInstance {
1927
1934
  }
1928
1935
  class FilterMapItem {
1929
1936
  constructor(dbxFilterMap, key) {
1930
- this.dbxFilterMap = dbxFilterMap;
1931
- this.key = key;
1937
+ this.dbxFilterMap = void 0;
1938
+ this.key = void 0;
1932
1939
  this._i = 0;
1933
1940
  this._source = new FilterSourceInstance();
1934
1941
  this._obs = new rxjs.BehaviorSubject([]);
1935
1942
  this.obs$ = this._obs.pipe(rxjs.switchMap(x => rxjs.merge(...x.map(y => y.obs))), rxjs.distinctUntilChanged());
1936
1943
  this.filter$ = this._source.initialFilter$;
1944
+ this.dbxFilterMap = dbxFilterMap;
1945
+ this.key = key;
1937
1946
  }
1938
1947
  setDefaultFilterObs(obs) {
1939
1948
  this._source.setDefaultFilter(obs);
@@ -3151,42 +3160,35 @@ $$1({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, {
3151
3160
  }
3152
3161
  });
3153
3162
 
3154
- /******************************************************************************
3155
- Copyright (c) Microsoft Corporation.
3156
-
3157
- Permission to use, copy, modify, and/or distribute this software for any
3158
- purpose with or without fee is hereby granted.
3159
-
3160
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3161
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3162
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3163
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3164
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3165
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3166
- PERFORMANCE OF THIS SOFTWARE.
3167
- ***************************************************************************** */
3168
-
3169
- function __awaiter(thisArg, _arguments, P, generator) {
3170
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3171
- return new (P || (P = Promise))(function (resolve, reject) {
3172
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3173
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3174
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3175
- step((generator = generator.apply(thisArg, _arguments || [])).next());
3176
- });
3177
- }
3178
-
3179
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3180
- var e = new Error(message);
3181
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3182
- };
3183
-
3184
3163
  /**
3185
3164
  * Creates an observable from the input iteration that checks both the hasNext$ and canLoadMore$ states.
3186
3165
  *
3187
3166
  * @param iteration
3188
3167
  * @returns
3189
3168
  */
3169
+
3170
+ function _async$2(f) {
3171
+ return function () {
3172
+ for (var args = [], i = 0; i < arguments.length; i++) {
3173
+ args[i] = arguments[i];
3174
+ }
3175
+ try {
3176
+ return Promise.resolve(f.apply(this, args));
3177
+ } catch (e) {
3178
+ return Promise.reject(e);
3179
+ }
3180
+ };
3181
+ } /**
3182
+ * Automatically calls next up to the current maxPageLoadLimit configured on the iterator.
3183
+ *
3184
+ * If no maximum limit is defined, uses the defaultLimit. If default limit is not defined or null, this will result in an error.
3185
+ *
3186
+ * The promise will reject with an error if an error is encountered.
3187
+ *
3188
+ * @param iterator
3189
+ * @param defaultLimit
3190
+ * @returns
3191
+ */
3190
3192
  function iterationHasNextAndCanLoadMore(iteration) {
3191
3193
  return iteration.canLoadMore$.pipe(rxjs.switchMap(canLoadMore => {
3192
3194
  if (canLoadMore) {
@@ -3196,21 +3198,10 @@ function iterationHasNextAndCanLoadMore(iteration) {
3196
3198
  }
3197
3199
  }), rxjs.shareReplay(1));
3198
3200
  }
3199
- /**
3200
- * Automatically calls next up to the current maxPageLoadLimit configured on the iterator.
3201
- *
3202
- * If no maximum limit is defined, uses the defaultLimit. If default limit is not defined or null, this will result in an error.
3203
- *
3204
- * The promise will reject with an error if an error is encountered.
3205
- *
3206
- * @param iterator
3207
- * @param defaultLimit
3208
- * @returns
3209
- */
3210
3201
  function iteratorNextPageUntilMaxPageLoadLimit(iterator, defaultLimit = 100) {
3211
3202
  return iteratorNextPageUntilPage(iterator, () => {
3212
- var _a;
3213
- const limit = (_a = iterator.maxPageLoadLimit) !== null && _a !== void 0 ? _a : defaultLimit;
3203
+ var _iterator$maxPageLoad;
3204
+ const limit = (_iterator$maxPageLoad = iterator.maxPageLoadLimit) != null ? _iterator$maxPageLoad : defaultLimit;
3214
3205
  if (util.isMaybeNot(limit)) {
3215
3206
  throw new Error('iteratorNextPageUntilMaxPageLoadLimit() failed. There was no maximum defined.');
3216
3207
  }
@@ -3229,9 +3220,9 @@ function iteratorNextPageUntilMaxPageLoadLimit(iterator, defaultLimit = 100) {
3229
3220
  function iteratorNextPageUntilPage(iteration, page) {
3230
3221
  const getPageLimit = util.asGetter(page);
3231
3222
  function checkPageLimit(page) {
3232
- var _a;
3223
+ var _iteration$maxPageLoa;
3233
3224
  const pageLimit = getPageLimit();
3234
- const maxLimit = Math.min(pageLimit, (_a = iteration.maxPageLoadLimit) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER);
3225
+ const maxLimit = Math.min(pageLimit, (_iteration$maxPageLoa = iteration.maxPageLoadLimit) != null ? _iteration$maxPageLoa : Number.MAX_SAFE_INTEGER);
3235
3226
  return page + 1 < maxLimit;
3236
3227
  }
3237
3228
  return new Promise((resolve, reject) => {
@@ -3239,11 +3230,11 @@ function iteratorNextPageUntilPage(iteration, page) {
3239
3230
  next: firstLatestPage => {
3240
3231
  const promise = util.performTaskLoop({
3241
3232
  initValue: firstLatestPage,
3242
- checkContinue: latestPage => __awaiter(this, void 0, void 0, function* () {
3233
+ checkContinue: _async$2(function (latestPage) {
3243
3234
  return rxjs.firstValueFrom(iterationHasNextAndCanLoadMore(iteration)).then(canLoadMore => canLoadMore && checkPageLimit(latestPage));
3244
3235
  }),
3245
- next: () => __awaiter(this, void 0, void 0, function* () {
3246
- return yield iteration.nextPage();
3236
+ next: _async$2(function () {
3237
+ return iteration.nextPage();
3247
3238
  })
3248
3239
  });
3249
3240
  resolve(promise);
@@ -3256,7 +3247,7 @@ function iteratorNextPageUntilPage(iteration, page) {
3256
3247
  }
3257
3248
 
3258
3249
  function distinctUntilArrayLengthChanges(inputGetArray) {
3259
- const getArray = inputGetArray !== null && inputGetArray !== void 0 ? inputGetArray : value => util.asArray(value);
3250
+ const getArray = inputGetArray != null ? inputGetArray : value => util.asArray(value);
3260
3251
  return rxjs.distinctUntilChanged((a, b) => a === b, x => getArray(x).length);
3261
3252
  }
3262
3253
  function scanIntoArray(config = {}) {
@@ -3303,7 +3294,7 @@ function scanBuildArray(init) {
3303
3294
  }
3304
3295
  }
3305
3296
  return acc;
3306
- }, seed !== null && seed !== void 0 ? seed : []), distinctUntilArrayLengthChanges(), rxjs.shareReplay(1));
3297
+ }, seed != null ? seed : []), distinctUntilArrayLengthChanges(), rxjs.shareReplay(1));
3307
3298
  });
3308
3299
  }
3309
3300
  // MARK: MapForEach
@@ -3322,7 +3313,7 @@ function mapForEach(forEach) {
3322
3313
  function mapEachAsync(mapFunction, config) {
3323
3314
  const {
3324
3315
  onlyFirst = false
3325
- } = config !== null && config !== void 0 ? config : {};
3316
+ } = config != null ? config : {};
3326
3317
  return rxjs.switchMap(values => {
3327
3318
  if (values.length) {
3328
3319
  const mappedObs = values.map(mapFunction);
@@ -3349,7 +3340,7 @@ function onMatchDelta(config) {
3349
3340
  to,
3350
3341
  requireConsecutive
3351
3342
  } = config;
3352
- const isMatch = inputIsSame !== null && inputIsSame !== void 0 ? inputIsSame : (a, b) => a === b;
3343
+ const isMatch = inputIsSame != null ? inputIsSame : (a, b) => a === b;
3353
3344
  return obs => {
3354
3345
  return obs.pipe(rxjs.scan((acc, next) => {
3355
3346
  let emit = false;
@@ -3726,7 +3717,7 @@ function scanCount(startAt = 0) {
3726
3717
  * @returns
3727
3718
  */
3728
3719
  function incrementingNumberTimer(config = {}) {
3729
- return factoryTimer(Object.assign(Object.assign({}, config), {
3720
+ return factoryTimer(Object.assign({}, config, {
3730
3721
  factory: util.incrementingNumberFactory(config)
3731
3722
  }));
3732
3723
  }
@@ -3927,7 +3918,7 @@ function errorOnEmissionsInPeriod(config) {
3927
3918
  errorMessage: inputErrorMessage,
3928
3919
  switchToObs
3929
3920
  } = config;
3930
- const errorMessage = inputErrorMessage !== null && inputErrorMessage !== void 0 ? inputErrorMessage : 'errorOnEmissionsInPeriod(): Too many emissions in time period.';
3921
+ const errorMessage = inputErrorMessage != null ? inputErrorMessage : 'errorOnEmissionsInPeriod(): Too many emissions in time period.';
3931
3922
  const errorFactory = inputErrorFactory ? inputErrorFactory : !switchToObs ? () => new Error(errorMessage) : undefined;
3932
3923
  return source => {
3933
3924
  const counter = util.timePeriodCounter(period);
@@ -3935,7 +3926,7 @@ function errorOnEmissionsInPeriod(config) {
3935
3926
  return source.pipe(rxjs.map(x => {
3936
3927
  if (counter() > maxEmissionsPerPeriod) {
3937
3928
  const error = errorFactory();
3938
- onError === null || onError === void 0 ? void 0 : onError(error);
3929
+ onError == null || onError(error);
3939
3930
  throw error;
3940
3931
  } else {
3941
3932
  return x;
@@ -3955,13 +3946,13 @@ function errorOnEmissionsInPeriod(config) {
3955
3946
  }
3956
3947
 
3957
3948
  function setContainsAllValuesFrom(valuesObs) {
3958
- return combineLatestMapFrom(valuesObs, (set, values) => util.setContainsAllValues(set, values !== null && values !== void 0 ? values : []));
3949
+ return combineLatestMapFrom(valuesObs, (set, values) => util.setContainsAllValues(set, values != null ? values : []));
3959
3950
  }
3960
3951
  function setContainsAnyValueFrom(valuesObs) {
3961
- return combineLatestMapFrom(valuesObs, (set, values) => util.setContainsAnyValue(set, values !== null && values !== void 0 ? values : []));
3952
+ return combineLatestMapFrom(valuesObs, (set, values) => util.setContainsAnyValue(set, values != null ? values : []));
3962
3953
  }
3963
3954
  function setContainsNoValueFrom(valuesObs) {
3964
- return combineLatestMapFrom(valuesObs, (set, values) => util.setContainsNoneOfValue(set, values !== null && values !== void 0 ? values : []));
3955
+ return combineLatestMapFrom(valuesObs, (set, values) => util.setContainsNoneOfValue(set, values != null ? values : []));
3965
3956
  }
3966
3957
  function distinctUntilHasDifferentValues() {
3967
3958
  return rxjs.distinctUntilChanged(util.hasSameValues);
@@ -4032,14 +4023,31 @@ exports.LoadingStateType = void 0;
4032
4023
  * @returns
4033
4024
  */
4034
4025
  function loadingStateType(loadingState) {
4035
- if (loadingState.loading) {
4036
- return exports.LoadingStateType.LOADING;
4037
- } else if (util.objectHasKey(loadingState, 'value')) {
4038
- return exports.LoadingStateType.SUCCESS;
4039
- } else if (util.objectHasKey(loadingState, 'error')) {
4040
- return exports.LoadingStateType.ERROR;
4026
+ const isLoading = !isLoadingStateFinishedLoading(loadingState);
4027
+ let type;
4028
+ if (isLoading) {
4029
+ type = exports.LoadingStateType.LOADING;
4041
4030
  } else {
4042
- return exports.LoadingStateType.IDLE;
4031
+ if (util.objectHasKey(loadingState, 'value')) {
4032
+ type = exports.LoadingStateType.SUCCESS;
4033
+ } else if (util.objectHasKey(loadingState, 'error')) {
4034
+ type = exports.LoadingStateType.ERROR;
4035
+ } else {
4036
+ type = exports.LoadingStateType.IDLE;
4037
+ }
4038
+ }
4039
+ return type;
4040
+ }
4041
+ function isLoadingStateFinishedLoading(state) {
4042
+ if (state) {
4043
+ const loading = state.loading;
4044
+ if (loading === true) {
4045
+ return false;
4046
+ } else {
4047
+ return loading === false || Boolean(state.value || state.error) || state.value === null;
4048
+ }
4049
+ } else {
4050
+ return false;
4043
4051
  }
4044
4052
  }
4045
4053
  /**
@@ -4051,16 +4059,16 @@ function idleLoadingState() {
4051
4059
  };
4052
4060
  }
4053
4061
  function beginLoading(state) {
4054
- return state ? Object.assign(Object.assign({}, state), {
4062
+ return state ? Object.assign({}, state, {
4055
4063
  loading: true
4056
4064
  }) : {
4057
4065
  loading: true
4058
4066
  };
4059
4067
  }
4060
4068
  function beginLoadingPage(page, state) {
4061
- return state ? Object.assign(Object.assign({
4069
+ return state ? Object.assign({
4062
4070
  page
4063
- }, state), {
4071
+ }, state, {
4064
4072
  loading: true
4065
4073
  }) : {
4066
4074
  page,
@@ -4074,7 +4082,7 @@ function successResult(value) {
4074
4082
  };
4075
4083
  }
4076
4084
  function successPageResult(page, value) {
4077
- return Object.assign(Object.assign({}, successResult(value)), {
4085
+ return Object.assign({}, successResult(value), {
4078
4086
  page
4079
4087
  });
4080
4088
  }
@@ -4085,59 +4093,77 @@ function errorResult(error) {
4085
4093
  };
4086
4094
  }
4087
4095
  function errorPageResult(page, error) {
4088
- return Object.assign(Object.assign({}, errorResult(error)), {
4096
+ return Object.assign({}, errorResult(error), {
4089
4097
  page
4090
4098
  });
4091
4099
  }
4092
- function unknownLoadingStatesIsLoading(states) {
4093
- return util.reduceBooleansWithOr(states.map(loadingStateIsLoading), false);
4094
- }
4095
- function allLoadingStatesHaveFinishedLoading(states) {
4096
- return util.reduceBooleansWithAnd(states.map(loadingStateHasFinishedLoading), true);
4097
- }
4098
- function loadingStateIsIdle(state) {
4099
- if (state) {
4100
- return loadingStateType(state) === exports.LoadingStateType.IDLE;
4101
- } else {
4102
- return true;
4103
- }
4104
- }
4105
- function loadingStateIsLoading(state) {
4106
- return !loadingStateHasFinishedLoading(state);
4107
- }
4108
- function isSuccessLoadingState(state) {
4109
- if (state) {
4110
- return loadingStateType(state) === exports.LoadingStateType.SUCCESS;
4111
- } else {
4112
- return false;
4113
- }
4100
+ /**
4101
+ * Returns true if any of the input LoadingStates return true for isLoadingStateLoading().
4102
+ *
4103
+ * @param states
4104
+ * @returns
4105
+ */
4106
+ function isAnyLoadingStateInLoadingState(states) {
4107
+ return util.reduceBooleansWithOr(states.map(isLoadingStateLoading), false);
4114
4108
  }
4115
- function isErrorLoadingState(state) {
4116
- if (state) {
4117
- return loadingStateType(state) === exports.LoadingStateType.ERROR;
4118
- } else {
4119
- return false;
4120
- }
4109
+ /**
4110
+ * Returns true if all input LoadingStates return true for isLoadingStateLoading().
4111
+ *
4112
+ * @param states
4113
+ * @returns
4114
+ */
4115
+ function areAllLoadingStatesFinishedLoading(states) {
4116
+ return util.reduceBooleansWithAnd(states.map(isLoadingStateFinishedLoading), true);
4121
4117
  }
4122
- function loadingStateHasFinishedLoading(state) {
4123
- if (state) {
4124
- const loading = state.loading;
4125
- if (loading === true) {
4126
- return false;
4118
+ function isLoadingStateWithStateType(type) {
4119
+ const defaultResult = type === exports.LoadingStateType.IDLE ? true : false;
4120
+ return state => {
4121
+ if (state) {
4122
+ return loadingStateType(state) === type;
4127
4123
  } else {
4128
- return loading === false || Boolean(state.value || state.error) || state.value === null;
4124
+ return defaultResult;
4129
4125
  }
4130
- } else {
4131
- return false;
4132
- }
4126
+ };
4133
4127
  }
4134
4128
  /**
4135
- * Whether or not the input loading state has a non-undefined value.
4129
+ * Returns true if the input LoadingState passed to loadingStateType() returns IDLE.
4136
4130
  *
4137
4131
  * @param state
4138
4132
  * @returns
4139
4133
  */
4140
- function loadingStateHasValue(state) {
4134
+ const isLoadingStateInIdleState = isLoadingStateWithStateType(exports.LoadingStateType.IDLE);
4135
+ /**
4136
+ * Returns true if the input LoadingState passed to loadingStateType() returns LOADING.
4137
+ *
4138
+ * @param state
4139
+ * @returns
4140
+ */
4141
+ const isLoadingStateLoading = isLoadingStateWithStateType(exports.LoadingStateType.LOADING);
4142
+ /**
4143
+ * Alias of isLoadingStateLoading.
4144
+ */
4145
+ const isLoadingStateInLoadingState = isLoadingStateLoading;
4146
+ /**
4147
+ * Returns true if the input LoadingState passed to loadingStateType() returns SUCCESS.
4148
+ *
4149
+ * @param state
4150
+ * @returns
4151
+ */
4152
+ const isLoadingStateInSuccessState = isLoadingStateWithStateType(exports.LoadingStateType.SUCCESS);
4153
+ /**
4154
+ * Returns true if the input LoadingState passed to loadingStateType() returns ERROR.
4155
+ *
4156
+ * @param state
4157
+ * @returns
4158
+ */
4159
+ const isLoadingStateInErrorState = isLoadingStateWithStateType(exports.LoadingStateType.ERROR);
4160
+ /**
4161
+ * Whether or not the input LoadingState has a non-undefined value.
4162
+ *
4163
+ * @param state
4164
+ * @returns
4165
+ */
4166
+ function isLoadingStateWithDefinedValue(state) {
4141
4167
  if (state) {
4142
4168
  return state.value !== undefined;
4143
4169
  } else {
@@ -4145,12 +4171,12 @@ function loadingStateHasValue(state) {
4145
4171
  }
4146
4172
  }
4147
4173
  /**
4148
- * Whether or not the input loading state has a non-null error.
4174
+ * Whether or not the input LoadingState has a non-null error defined. It may be loading.
4149
4175
  *
4150
4176
  * @param state
4151
4177
  * @returns
4152
4178
  */
4153
- function loadingStateHasError(state) {
4179
+ function isLoadingStateWithError(state) {
4154
4180
  if (state) {
4155
4181
  return state.error != null;
4156
4182
  } else {
@@ -4158,27 +4184,27 @@ function loadingStateHasError(state) {
4158
4184
  }
4159
4185
  }
4160
4186
  /**
4161
- * Whether or not the input loading state is not loading and has a non-null value.
4187
+ * Whether or not the input LoadingState is not loading and has a non-null value.
4162
4188
  *
4163
4189
  * @param state
4164
4190
  * @returns
4165
4191
  */
4166
- function loadingStateHasFinishedLoadingWithValue(state) {
4192
+ function isLoadingStateFinishedLoadingWithDefinedValue(state) {
4167
4193
  if (state) {
4168
- return loadingStateHasFinishedLoading(state) && state.value !== undefined;
4194
+ return isLoadingStateFinishedLoading(state) && state.value !== undefined;
4169
4195
  } else {
4170
4196
  return false;
4171
4197
  }
4172
4198
  }
4173
4199
  /**
4174
- * Whether or not the input loading state is not loading and has an error defined.
4200
+ * Whether or not the input LoadingState is not loading and has an error defined.
4175
4201
  *
4176
4202
  * @param state
4177
4203
  * @returns
4178
4204
  */
4179
- function loadingStateHasFinishedLoadingWithError(state) {
4205
+ function isLoadingStateFinishedLoadingWithError(state) {
4180
4206
  if (state) {
4181
- return loadingStateHasFinishedLoading(state) && state.error != null;
4207
+ return isLoadingStateFinishedLoading(state) && state.error != null;
4182
4208
  } else {
4183
4209
  return false;
4184
4210
  }
@@ -4191,20 +4217,20 @@ function loadingStateHasFinishedLoadingWithError(state) {
4191
4217
  * @param a
4192
4218
  * @param b
4193
4219
  */
4194
- function loadingStatesHaveEquivalentMetadata(a, b) {
4220
+ function isPageLoadingStateMetadataEqual(a, b) {
4195
4221
  return util.valuesAreBothNullishOrEquivalent(a.page, b.page) && a.loading == b.loading && util.valuesAreBothNullishOrEquivalent(a.error, b.error);
4196
4222
  }
4197
4223
  function mergeLoadingStates(...args) {
4198
- var _a;
4224
+ var _loadingStates$find;
4199
4225
  const validArgs = util.filterMaybeValues(args); // filter out any undefined values
4200
4226
  const lastValueIsMergeFn = typeof validArgs[validArgs.length - 1] === 'function';
4201
4227
  const loadingStates = lastValueIsMergeFn ? validArgs.slice(0, validArgs.length - 1) : validArgs;
4202
4228
  const mergeFn = lastValueIsMergeFn ? args[validArgs.length - 1] : (...inputArgs) => util.mergeObjects(inputArgs);
4203
- const error = (_a = loadingStates.find(x => x.error)) === null || _a === void 0 ? void 0 : _a.error; // find the first error
4229
+ const error = (_loadingStates$find = loadingStates.find(x => x.error)) == null ? void 0 : _loadingStates$find.error; // find the first error
4204
4230
  let result;
4205
4231
  if (error) {
4206
4232
  // ignore all loading states, except for any error-prone item that is still loading
4207
- const currentLoadings = loadingStates.map(x => (x === null || x === void 0 ? void 0 : x.error) ? x.loading : false);
4233
+ const currentLoadings = loadingStates.map(x => x != null && x.error ? x.loading : false);
4208
4234
  const nonMaybeLoadings = currentLoadings.filter(x => x != null);
4209
4235
  const loading = nonMaybeLoadings.length > 0 ? util.reduceBooleansWithOr(nonMaybeLoadings) : undefined;
4210
4236
  result = {
@@ -4213,7 +4239,7 @@ function mergeLoadingStates(...args) {
4213
4239
  error
4214
4240
  };
4215
4241
  } else {
4216
- const loading = util.reduceBooleansWithOr(loadingStates.map(loadingStateIsLoading));
4242
+ const loading = util.reduceBooleansWithOr(loadingStates.map(isLoadingStateLoading));
4217
4243
  if (loading) {
4218
4244
  result = {
4219
4245
  loading: true
@@ -4230,30 +4256,30 @@ function mergeLoadingStates(...args) {
4230
4256
  return result;
4231
4257
  }
4232
4258
  /**
4233
- * Updates the input state to start loading.
4259
+ * Returns a new merged state to be loading or idle, and clears the current/error value. It will have a LoadingStateType of LOADING if loading is true.
4234
4260
  */
4235
- function updatedStateForSetLoading(state, loading = true) {
4236
- return Object.assign(Object.assign({}, state), {
4261
+ function mergeLoadingStateWithLoading(state, loading = true) {
4262
+ return Object.assign({}, state, {
4237
4263
  value: undefined,
4238
4264
  loading,
4239
4265
  error: undefined
4240
4266
  });
4241
4267
  }
4242
4268
  /**
4243
- * Updates the input state with the input error.
4269
+ * Returns a new merged state with the input value. It will have a LoadingStateType of SUCCESS now.
4244
4270
  */
4245
- function updatedStateForSetValue(state, value) {
4246
- return Object.assign(Object.assign({}, state), {
4247
- value: value !== null && value !== void 0 ? value : undefined,
4271
+ function mergeLoadingStateWithValue(state, value) {
4272
+ return Object.assign({}, state, {
4273
+ value: value != null ? value : undefined,
4248
4274
  loading: false,
4249
4275
  error: undefined
4250
4276
  });
4251
4277
  }
4252
4278
  /**
4253
- * Updates the input state with the input error.
4279
+ * Returns a new merged state with the input error. It will have a LoadingStateType of ERROR now.
4254
4280
  */
4255
- function updatedStateForSetError(state, error) {
4256
- return Object.assign(Object.assign({}, state), {
4281
+ function mergeLoadingStateWithError(state, error) {
4282
+ return Object.assign({}, state, {
4257
4283
  loading: false,
4258
4284
  error
4259
4285
  });
@@ -4263,8 +4289,8 @@ function mapMultipleLoadingStateResults(input, config) {
4263
4289
  mapValues,
4264
4290
  mapState
4265
4291
  } = config;
4266
- const loading = unknownLoadingStatesIsLoading(input);
4267
- const error = input.map(x => x === null || x === void 0 ? void 0 : x.error).filter(x => Boolean(x))[0];
4292
+ const loading = isAnyLoadingStateInLoadingState(input);
4293
+ const error = input.map(x => x == null ? void 0 : x.error).filter(x => Boolean(x))[0];
4268
4294
  let result;
4269
4295
  if (!error && !loading) {
4270
4296
  if (mapValues) {
@@ -4288,7 +4314,7 @@ function mapLoadingStateResults(input, config) {
4288
4314
  mapState,
4289
4315
  alwaysMapValue = false
4290
4316
  } = config;
4291
- const inputValue = input === null || input === void 0 ? void 0 : input.value;
4317
+ const inputValue = input == null ? void 0 : input.value;
4292
4318
  let value;
4293
4319
  if ((inputValue != null || alwaysMapValue) && mapValue) {
4294
4320
  value = mapValue(inputValue, input);
@@ -4297,7 +4323,7 @@ function mapLoadingStateResults(input, config) {
4297
4323
  }
4298
4324
  let result;
4299
4325
  if (!mapState) {
4300
- result = Object.assign(Object.assign({}, input), {
4326
+ result = Object.assign({}, input, {
4301
4327
  value
4302
4328
  });
4303
4329
  } else {
@@ -4314,21 +4340,84 @@ function mapLoadingStateValueFunction(mapFn) {
4314
4340
  return result;
4315
4341
  };
4316
4342
  }
4343
+ // MARK: Compat
4344
+ /**
4345
+ * @deprecated use unknownLoadingStatesIsLoading instead.
4346
+ */
4347
+ const unknownLoadingStatesIsLoading = isAnyLoadingStateInLoadingState;
4348
+ /**
4349
+ * @deprecated use areAllLoadingStatesFinishedLoading instead.
4350
+ */
4351
+ const allLoadingStatesHaveFinishedLoading = areAllLoadingStatesFinishedLoading;
4352
+ /**
4353
+ * @deprecated use isLoadingStateInIdleState instead.
4354
+ */
4355
+ const loadingStateIsIdle = isLoadingStateInIdleState;
4356
+ /**
4357
+ * @deprecated use isLoadingStateInSuccessState instead.
4358
+ */
4359
+ const isSuccessLoadingState = isLoadingStateInSuccessState;
4360
+ /**
4361
+ * @deprecated use isLoadingStateInErrorState instead.
4362
+ */
4363
+ const isErrorLoadingState = isLoadingStateInErrorState;
4364
+ /**
4365
+ * @deprecated Use isLoadingStateLoading instead.
4366
+ */
4367
+ const loadingStateIsLoading = isLoadingStateLoading;
4368
+ /**
4369
+ * @deprecated use isLoadingStateFinishedLoading instead.
4370
+ */
4371
+ const loadingStateHasFinishedLoading = isLoadingStateFinishedLoading;
4372
+ /**
4373
+ * @deprecated use isLoadingStateWithError instead.
4374
+ */
4375
+ const loadingStateHasError = isLoadingStateWithError;
4376
+ /**
4377
+ * @deprecated use isLoadingStateWithDefinedValue instead.
4378
+ */
4379
+ const loadingStateHasValue = isLoadingStateWithDefinedValue;
4380
+ /**
4381
+ * @deprecated use isLoadingStateFinishedLoadingWithDefinedValue instead.
4382
+ */
4383
+ const loadingStateHasFinishedLoadingWithValue = isLoadingStateFinishedLoadingWithDefinedValue;
4384
+ /**
4385
+ * @deprecated use isLoadingStateFinishedLoadingWithError instead.
4386
+ */
4387
+ const loadingStateHasFinishedLoadingWithError = isLoadingStateFinishedLoadingWithError;
4388
+ /**
4389
+ * @deprecated use isPageLoadingStateMetadataEqual instead.
4390
+ */
4391
+ const loadingStatesHaveEquivalentMetadata = isPageLoadingStateMetadataEqual;
4392
+ /**
4393
+ * @deprecated use mergeLoadingStateWithLoading instead.
4394
+ */
4395
+ const updatedStateForSetLoading = mergeLoadingStateWithLoading;
4396
+ /**
4397
+ * @deprecated use updatedStateForSetValue instead.
4398
+ */
4399
+ const updatedStateForSetValue = mergeLoadingStateWithValue;
4400
+ /**
4401
+ * @deprecated use mergeLoadingStateWithError instead.
4402
+ */
4403
+ const updatedStateForSetError = mergeLoadingStateWithError;
4317
4404
 
4318
4405
  /**
4319
4406
  * Abstract LoadingContext implementation using LoadingState.
4320
4407
  */
4321
4408
  class AbstractLoadingStateContextInstance {
4322
- constructor(config) {
4323
- this._stateSubject$ = new rxjs.BehaviorSubject(undefined);
4324
- this.stateSubject$ = this._stateSubject$.pipe(filterMaybe(), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
4409
+ constructor(_config) {
4410
+ this._stateSubject = new rxjs.BehaviorSubject(undefined);
4411
+ this._config = new rxjs.BehaviorSubject(undefined);
4412
+ this.config$ = this._config.pipe(filterMaybe(), rxjs.shareReplay(1));
4413
+ this.stateSubject$ = this._stateSubject.pipe(filterMaybe(), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
4325
4414
  this.state$ = this.stateSubject$.pipe(rxjs.switchMap(x => x), rxjs.shareReplay(1));
4326
- this.stateObs$ = this._stateSubject$.asObservable();
4327
- this.stream$ = this._stateSubject$.pipe(rxjs.mergeMap(obs => {
4415
+ this.stateObs$ = this._stateSubject.asObservable();
4416
+ this.stream$ = this.stateObs$.pipe(rxjs.mergeMap(obs => {
4328
4417
  if (obs) {
4329
4418
  return obs.pipe(
4330
4419
  // If the observable did not pass a value immediately, we start with the start value.
4331
- timeoutStartWith(beginLoading()), rxjs.map(x => this.loadingEventForLoadingPair(x, this._config)));
4420
+ timeoutStartWith(beginLoading()), rxjs.combineLatestWith(this.config$), rxjs.map(([x, config]) => this.loadingEventForLoadingPair(x, config)));
4332
4421
  } else {
4333
4422
  return rxjs.of(beginLoading());
4334
4423
  }
@@ -4338,30 +4427,34 @@ class AbstractLoadingStateContextInstance {
4338
4427
  /**
4339
4428
  * Emits when the input state has changed.
4340
4429
  */
4341
- this.stateChange$ = this._stateSubject$.pipe(rxjs.map(() => undefined));
4430
+ this.stateChange$ = this._stateSubject.pipe(rxjs.map(() => undefined));
4342
4431
  this.loading$ = this.stream$.pipe(rxjs.map(x => x.loading), rxjs.shareReplay(1));
4343
- if (rxjs.isObservable(config)) {
4344
- this._config = {
4345
- obs: config
4432
+ let nextConfig;
4433
+ if (rxjs.isObservable(_config)) {
4434
+ nextConfig = {
4435
+ obs: _config
4346
4436
  };
4347
4437
  } else {
4348
- this._config = config !== null && config !== void 0 ? config : {
4438
+ nextConfig = _config != null ? _config : {
4349
4439
  showLoadingOnNoValue: false
4350
4440
  };
4351
4441
  }
4352
- if (this._config.obs) {
4353
- this.setStateObs(this._config.obs);
4442
+ this._config.next(nextConfig);
4443
+ // Only set once
4444
+ if (nextConfig.obs) {
4445
+ this.setStateObs(nextConfig.obs);
4354
4446
  }
4355
4447
  }
4356
4448
  setStateObs(state) {
4357
- this._stateSubject$.next(state);
4449
+ this._stateSubject.next(state);
4358
4450
  }
4359
4451
  destroy() {
4360
- this._stateSubject$.complete();
4452
+ this._stateSubject.complete();
4453
+ this._config.complete();
4361
4454
  }
4362
4455
  }
4363
4456
 
4364
- // TODO: Fix all LoadingState types to use the LoadingStateValue inference
4457
+ // TODO(BREAKING_CHANGE): Fix all LoadingState types to use the LoadingStateValue inference typings
4365
4458
  /**
4366
4459
  * Wraps an observable output and maps the value to a LoadingState.
4367
4460
  *
@@ -4371,16 +4464,7 @@ function loadingStateFromObs(obs, firstOnly) {
4371
4464
  if (firstOnly) {
4372
4465
  obs = obs.pipe(rxjs.first());
4373
4466
  }
4374
- return obs.pipe(rxjs.map(value => ({
4375
- loading: false,
4376
- value,
4377
- error: undefined
4378
- })), rxjs.catchError(error => rxjs.of({
4379
- loading: false,
4380
- error
4381
- })), timeoutStartWith({
4382
- loading: true
4383
- }, 50), rxjs.shareReplay(1));
4467
+ return obs.pipe(rxjs.map(value => successResult(value)), rxjs.catchError(error => rxjs.of(errorResult(error))), timeoutStartWith(beginLoading(), 50), rxjs.shareReplay(1));
4384
4468
  }
4385
4469
  function combineLoadingStates(...args) {
4386
4470
  const validArgs = util.filterMaybeValues(args); // filter out any undefined values
@@ -4415,7 +4499,7 @@ function combineLoadingStatesStatus(sources) {
4415
4499
  if (firstErrorState) {
4416
4500
  result = errorResult(firstErrorState.error);
4417
4501
  } else {
4418
- const oneOrMoreStatesAreCurrentlyLoading = allLoadingStates.findIndex(loadingStateIsLoading) !== -1;
4502
+ const oneOrMoreStatesAreCurrentlyLoading = allLoadingStates.findIndex(isLoadingStateLoading) !== -1;
4419
4503
  if (oneOrMoreStatesAreCurrentlyLoading) {
4420
4504
  result = beginLoading(); // still loading
4421
4505
  } else {
@@ -4433,7 +4517,7 @@ function startWithBeginLoading(state) {
4433
4517
  */
4434
4518
  function valueFromLoadingState() {
4435
4519
  return obs => {
4436
- return obs.pipe(rxjs.filter(loadingStateHasValue), rxjs.map(x => x.value));
4520
+ return obs.pipe(rxjs.filter(isLoadingStateWithDefinedValue), rxjs.map(x => x.value));
4437
4521
  };
4438
4522
  }
4439
4523
  /**
@@ -4441,7 +4525,7 @@ function valueFromLoadingState() {
4441
4525
  */
4442
4526
  function errorFromLoadingState() {
4443
4527
  return obs => {
4444
- return obs.pipe(rxjs.filter(loadingStateHasError), rxjs.map(x => x.error));
4528
+ return obs.pipe(rxjs.filter(isLoadingStateWithError), rxjs.map(x => x.error));
4445
4529
  };
4446
4530
  }
4447
4531
  /**
@@ -4449,13 +4533,13 @@ function errorFromLoadingState() {
4449
4533
  */
4450
4534
  function valueFromFinishedLoadingState() {
4451
4535
  return obs => {
4452
- return obs.pipe(rxjs.filter(loadingStateHasFinishedLoading), rxjs.map(x => x.value));
4536
+ return obs.pipe(rxjs.filter(isLoadingStateFinishedLoading), rxjs.map(x => x.value));
4453
4537
  };
4454
4538
  }
4455
4539
  function tapOnLoadingStateType(fn, type) {
4456
4540
  let decisionFunction;
4457
4541
  if (type === exports.LoadingStateType.LOADING) {
4458
- decisionFunction = loadingStateIsLoading;
4542
+ decisionFunction = isLoadingStateLoading;
4459
4543
  } else {
4460
4544
  decisionFunction = state => loadingStateType(state) === type;
4461
4545
  }
@@ -4475,25 +4559,25 @@ function mapLoadingStateValueWithOperator(operator, mapOnUndefined = false) {
4475
4559
  return obs => {
4476
4560
  return obs.pipe(rxjs.switchMap(state => {
4477
4561
  let mappedObs;
4478
- if (loadingStateHasValue(state) || mapOnUndefined && loadingStateHasFinishedLoading(state) && !loadingStateHasError(state)) {
4562
+ if (isLoadingStateWithDefinedValue(state) || mapOnUndefined && isLoadingStateFinishedLoading(state) && !isLoadingStateWithError(state)) {
4479
4563
  // map the value
4480
- mappedObs = rxjs.of(state.value).pipe(operator, rxjs.map(value => Object.assign(Object.assign({}, state), {
4564
+ mappedObs = rxjs.of(state.value).pipe(operator, rxjs.map(value => Object.assign({}, state, {
4481
4565
  value
4482
4566
  })),
4483
4567
  // if the operator does not return nearly instantly, then return the current state, minus a value
4484
- timeoutStartWith(Object.assign(Object.assign({}, state), {
4568
+ timeoutStartWith(Object.assign({}, state, {
4485
4569
  loading: true,
4486
4570
  value: undefined
4487
4571
  }), 0));
4488
4572
  } else {
4489
4573
  // only pass through if there is an error, otherwise show loading.
4490
- if (loadingStateHasError(state)) {
4491
- mappedObs = rxjs.of(Object.assign(Object.assign({}, state), {
4574
+ if (isLoadingStateWithError(state)) {
4575
+ mappedObs = rxjs.of(Object.assign({}, state, {
4492
4576
  value: undefined
4493
4577
  }));
4494
4578
  } else {
4495
4579
  // never pass through the non-mapped state's value as-is.
4496
- mappedObs = rxjs.of(Object.assign(Object.assign({}, state), {
4580
+ mappedObs = rxjs.of(Object.assign({}, state, {
4497
4581
  loading: true,
4498
4582
  value: undefined
4499
4583
  }));
@@ -4512,14 +4596,14 @@ function distinctLoadingState(inputConfig) {
4512
4596
  } = typeof inputConfig === 'function' ? {
4513
4597
  valueComparator: inputConfig
4514
4598
  } : inputConfig;
4515
- const passRetainedValue = inputPassRetainedValue !== null && inputPassRetainedValue !== void 0 ? inputPassRetainedValue : x => x !== null;
4516
- const metadataComparator = inputMetadataComparator !== null && inputMetadataComparator !== void 0 ? inputMetadataComparator : loadingStatesHaveEquivalentMetadata;
4599
+ const passRetainedValue = inputPassRetainedValue != null ? inputPassRetainedValue : x => x !== null;
4600
+ const metadataComparator = inputMetadataComparator != null ? inputMetadataComparator : isPageLoadingStateMetadataEqual;
4517
4601
  return obs => {
4518
4602
  return obs.pipe(rxjs.scan((acc, state) => {
4519
4603
  const nextValue = state.value;
4520
4604
  // determine the value change
4521
4605
  let isSameValue = false;
4522
- if (loadingStateHasValue(state) || compareOnUndefinedValue && loadingStateHasFinishedLoading(state) && !loadingStateHasError(state)) {
4606
+ if (isLoadingStateWithDefinedValue(state) || compareOnUndefinedValue && isLoadingStateFinishedLoading(state) && !isLoadingStateWithError(state)) {
4523
4607
  // if the value is the same, then
4524
4608
  isSameValue = valueComparator(nextValue, acc.value);
4525
4609
  } else if (passRetainedValue(nextValue, acc.value, state, acc.previous)) {
@@ -4529,12 +4613,11 @@ function distinctLoadingState(inputConfig) {
4529
4613
  const isSameLoadingStateMetadata = util.safeCompareEquality(state, acc.previous, metadataComparator);
4530
4614
  // pick the value
4531
4615
  const value = isSameValue ? acc.value : nextValue;
4532
- const current = Object.assign(Object.assign({}, state), {
4533
- // copy all metadata over
4616
+ const current = Object.assign({}, state, {
4534
4617
  value // set the new value
4535
4618
  });
4536
4619
 
4537
- return Object.assign(Object.assign({}, acc), {
4620
+ return Object.assign({}, acc, {
4538
4621
  value,
4539
4622
  isSameValue,
4540
4623
  isSameLoadingStateMetadata,
@@ -4560,7 +4643,7 @@ function distinctLoadingState(inputConfig) {
4560
4643
  * @returns
4561
4644
  */
4562
4645
  function promiseFromLoadingState(obs) {
4563
- return rxjs.firstValueFrom(obs.pipe(rxjs.filter(loadingStateHasFinishedLoading))).then(x => {
4646
+ return rxjs.firstValueFrom(obs.pipe(rxjs.filter(isLoadingStateFinishedLoading))).then(x => {
4564
4647
  let result;
4565
4648
  if (x.error) {
4566
4649
  throw x.error;
@@ -4571,18 +4654,22 @@ function promiseFromLoadingState(obs) {
4571
4654
  });
4572
4655
  }
4573
4656
 
4574
- // TODO: breaking change refactor: Switch the names of these functions below, so the isListLoadingStateEmpty is the non-operator function.
4575
4657
  /**
4576
4658
  * Returns true if the loading state is not loading and is empty.
4577
4659
  *
4578
4660
  * @param listLoadingState
4579
4661
  * @returns
4580
4662
  */
4581
- function listLoadingStateIsEmpty(listLoadingState) {
4663
+ function isListLoadingStateWithEmptyValue(listLoadingState) {
4582
4664
  return Boolean(!listLoadingState.value || !listLoadingState.value.length);
4583
4665
  }
4584
- function isListLoadingStateEmpty() {
4585
- return rxjs.map(listLoadingStateIsEmpty);
4666
+ /**
4667
+ * Convenience function that merges map() with isListLoadingStateWithEmptyValue()
4668
+ *
4669
+ * @returns
4670
+ */
4671
+ function mapIsListLoadingStateWithEmptyValue() {
4672
+ return rxjs.map(isListLoadingStateWithEmptyValue);
4586
4673
  }
4587
4674
  /**
4588
4675
  * Wraps an observable output and maps the value to a PageLoadingState.
@@ -4593,24 +4680,33 @@ function pageLoadingStateFromObs(obs, firstOnly, page = 0) {
4593
4680
  return x;
4594
4681
  }));
4595
4682
  }
4683
+ // MARK: Compat
4684
+ /**
4685
+ * @deprecated use isListLoadingStateWithEmptyValue instead.
4686
+ */
4687
+ const listLoadingStateIsEmpty = isListLoadingStateWithEmptyValue;
4688
+ /**
4689
+ * @deprecated use mapIsListLoadingStateWithEmptyValue instead.
4690
+ */
4691
+ const isListLoadingStateEmpty = mapIsListLoadingStateWithEmptyValue;
4596
4692
 
4597
4693
  /**
4598
4694
  * LoadingContext implementation that uses a ListLoadingState observable.
4599
4695
  */
4600
4696
  class ListLoadingStateContextInstance extends AbstractLoadingStateContextInstance {
4601
- constructor() {
4602
- super(...arguments);
4697
+ constructor(...args) {
4698
+ super(...args);
4603
4699
  /**
4604
4700
  * Returns the current values or an empty list.
4605
4701
  */
4606
4702
  this.list$ = this.stream$.pipe(rxjs.map(x => {
4607
- var _a;
4608
- return (_a = x.value) !== null && _a !== void 0 ? _a : [];
4703
+ var _x$value;
4704
+ return (_x$value = x.value) != null ? _x$value : [];
4609
4705
  }), rxjs.shareReplay(1));
4610
4706
  /**
4611
4707
  * Returns true while loading and the current value is considered empty.
4612
4708
  */
4613
- this.isEmptyLoading$ = this.stream$.pipe(rxjs.map(x => loadingStateIsLoading(x) && listLoadingStateIsEmpty(x)), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
4709
+ this.isEmptyLoading$ = this.stream$.pipe(rxjs.map(x => isLoadingStateLoading(x) && isListLoadingStateWithEmptyValue(x)), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
4614
4710
  /**
4615
4711
  * Whether or not the current value is empty.
4616
4712
  *
@@ -4618,9 +4714,9 @@ class ListLoadingStateContextInstance extends AbstractLoadingStateContextInstanc
4618
4714
  *
4619
4715
  * After that, will return true if the value is empty even if loading a new value.
4620
4716
  */
4621
- this.isEmpty$ = this.stream$.pipe(rxjs.skipWhile(x => loadingStateIsLoading(x)),
4717
+ this.isEmpty$ = this.stream$.pipe(rxjs.skipWhile(x => isLoadingStateLoading(x)),
4622
4718
  // skip until the first non-loading event has occured
4623
- isListLoadingStateEmpty(), rxjs.distinctUntilChanged());
4719
+ mapIsListLoadingStateWithEmptyValue(), rxjs.distinctUntilChanged());
4624
4720
  /**
4625
4721
  * Whether or not the current value is empty and not loading.
4626
4722
  *
@@ -4628,17 +4724,17 @@ class ListLoadingStateContextInstance extends AbstractLoadingStateContextInstanc
4628
4724
  *
4629
4725
  * After that, will return true if the value is empty even if loading a new value.
4630
4726
  */
4631
- this.isEmptyAndNotLoading$ = this.stream$.pipe(rxjs.skipWhile(x => loadingStateIsLoading(x)),
4727
+ this.isEmptyAndNotLoading$ = this.stream$.pipe(rxjs.skipWhile(x => isLoadingStateLoading(x)),
4632
4728
  // skip until the first non-loading event has occured
4633
- rxjs.map(x => !loadingStateIsLoading(x) && listLoadingStateIsEmpty(x)), rxjs.distinctUntilChanged());
4729
+ rxjs.map(x => !isLoadingStateLoading(x) && isListLoadingStateWithEmptyValue(x)), rxjs.distinctUntilChanged());
4634
4730
  }
4635
4731
  loadingEventForLoadingPair(state, config = {}) {
4636
4732
  const {
4637
4733
  showLoadingOnNoValue
4638
4734
  } = config;
4639
- let loading = state === null || state === void 0 ? void 0 : state.loading;
4640
- const error = state === null || state === void 0 ? void 0 : state.error;
4641
- let value = state === null || state === void 0 ? void 0 : state.value;
4735
+ let loading = state == null ? void 0 : state.loading;
4736
+ const error = state == null ? void 0 : state.error;
4737
+ let value = state == null ? void 0 : state.value;
4642
4738
  const hasValue = value != null;
4643
4739
  if (hasValue) {
4644
4740
  value = util.limitArray(value, config); // Always limit the value/results.
@@ -4648,7 +4744,7 @@ class ListLoadingStateContextInstance extends AbstractLoadingStateContextInstanc
4648
4744
  if (showLoadingOnNoValue) {
4649
4745
  loading = !hasValue;
4650
4746
  } else {
4651
- loading = loadingStateIsLoading(state);
4747
+ loading = isLoadingStateLoading(state);
4652
4748
  }
4653
4749
  }
4654
4750
  return {
@@ -4666,8 +4762,8 @@ function listLoadingStateContext(config) {
4666
4762
  * LoadingContext implementation for a LoadingState.
4667
4763
  */
4668
4764
  class LoadingStateContextInstance extends AbstractLoadingStateContextInstance {
4669
- constructor() {
4670
- super(...arguments);
4765
+ constructor(...args) {
4766
+ super(...args);
4671
4767
  this.value$ = this.stream$.pipe(rxjs.map(x => x.value), rxjs.shareReplay(1));
4672
4768
  this.valueAfterLoaded$ = this.stream$.pipe(rxjs.filter(x => !x.loading), rxjs.map(x => x.value), rxjs.shareReplay(1));
4673
4769
  }
@@ -4675,13 +4771,13 @@ class LoadingStateContextInstance extends AbstractLoadingStateContextInstance {
4675
4771
  showLoadingOnNoValue
4676
4772
  } = {}) {
4677
4773
  let loading = false;
4678
- const error = pair === null || pair === void 0 ? void 0 : pair.error;
4679
- const value = pair === null || pair === void 0 ? void 0 : pair.value;
4774
+ const error = pair == null ? void 0 : pair.error;
4775
+ const value = pair == null ? void 0 : pair.value;
4680
4776
  if (!util.hasNonNullValue(error)) {
4681
4777
  if (showLoadingOnNoValue) {
4682
4778
  loading = !util.hasNonNullValue(value);
4683
4779
  } else {
4684
- loading = loadingStateIsLoading(pair);
4780
+ loading = isLoadingStateLoading(pair);
4685
4781
  }
4686
4782
  }
4687
4783
  return {
@@ -4700,6 +4796,8 @@ function loadingStateContext(config) {
4700
4796
  */
4701
4797
  class SimpleLoadingContext {
4702
4798
  constructor(loading = true) {
4799
+ this._subject = void 0;
4800
+ this._error = void 0;
4703
4801
  this._subject = new rxjs.BehaviorSubject({
4704
4802
  loading
4705
4803
  });
@@ -4741,6 +4839,7 @@ class ValuesLoadingContext extends SimpleLoadingContext {
4741
4839
  loading = true
4742
4840
  } = {}) {
4743
4841
  super(loading);
4842
+ this._checkDone = void 0;
4744
4843
  this._checkDone = checkDone;
4745
4844
  }
4746
4845
  /**
@@ -4765,70 +4864,113 @@ class ValuesLoadingContext extends SimpleLoadingContext {
4765
4864
  }
4766
4865
  }
4767
4866
 
4768
- /**
4769
- * ItemAccumulator implementation.
4770
- */
4771
- class ItemAccumulatorInstance {
4772
- constructor(itemIteration, mapItemFunction) {
4773
- this.itemIteration = itemIteration;
4774
- this.mapItemFunction = mapItemFunction;
4775
- this.hasCompletedInitialLoad$ = this.itemIteration.firstState$.pipe(rxjs.map(() => true), rxjs.startWith(false), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
4776
- this.latestSuccessfulState$ = this.itemIteration.latestState$.pipe(rxjs.filter(x => !loadingStateHasError(x)), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
4777
- /**
4778
- * All successful page results in a single array.
4779
- */
4780
- this.allSuccessfulStates$ = this.latestSuccessfulState$.pipe(scanIntoArray({
4781
- immutable: false
4782
- }),
4783
- /**
4784
- * Don't wait for the first successful state in order to avoid never returning a value on immediate failures.
4785
- */
4786
- rxjs.startWith([]), distinctUntilArrayLengthChanges(), rxjs.shareReplay(1));
4787
- this.successfulLoadCount$ = this.allSuccessfulStates$.pipe(rxjs.map(x => x.length), rxjs.shareReplay(1));
4788
- // MARK: ItemAccumulator
4789
- this.currentAllItemPairs$ = this.allSuccessfulStates$.pipe(scanBuildArray(allSuccessfulStates => {
4790
- const mapStateToItem = util.mapFunctionOutputPair(mapLoadingStateValueFunction(this.mapItemFunction));
4791
- /*
4792
- Start with allSuccessfulPageResults$ since it contains all page results since the start of the iterator,
4793
- and subscription to allItems may not have started at the same time.
4794
- We use scan to add in all models coming in afterwards by pushing them into the accumulator.
4795
- This is to prevent performance issues with very large iteration sets, since we can
4796
- append onto the array, rather than concat/copy the array each time.
4797
- */
4798
- const allPageResultsUpToFirstSubscription = allSuccessfulStates;
4799
- const firstLatestState = util.lastValue(allPageResultsUpToFirstSubscription);
4800
- const seed = allPageResultsUpToFirstSubscription.map(mapStateToItem).filter(x => util.isMaybeSo(x.output));
4801
- const accumulatorObs = this.latestSuccessfulState$.pipe(rxjs.skipWhile(x => x === firstLatestState), rxjs.map(mapStateToItem), rxjs.filter(x => util.isMaybeSo(x.output)));
4802
- return {
4803
- seed,
4804
- accumulatorObs
4805
- };
4806
- }), rxjs.shareReplay(1));
4807
- this.currentAllItems$ = this.currentAllItemPairs$.pipe(rxjs.map(x => x.map(y => y.output)), rxjs.shareReplay(1));
4808
- this.allItemPairs$ = this.hasCompletedInitialLoad$.pipe(switchMapWhileTrue(this.currentAllItemPairs$), rxjs.shareReplay(1));
4809
- this.allItems$ = this.hasCompletedInitialLoad$.pipe(switchMapWhileTrue(this.currentAllItems$), rxjs.shareReplay(1));
4810
- this._sub = new SubscriptionObject(this.allSuccessfulStates$.subscribe());
4867
+ function _await$1(value, then, direct) {
4868
+ if (direct) {
4869
+ return then ? then(value) : value;
4811
4870
  }
4812
- destroy() {
4813
- this._sub.destroy();
4871
+ if (!value || !value.then) {
4872
+ value = Promise.resolve(value);
4814
4873
  }
4874
+ return then ? value.then(then) : value;
4875
+ } /**
4876
+ * Automatically calls next on the accumulator's page item iteration up to the target number of results. Returns the total number of items loaded.
4877
+ *
4878
+ * The promise will reject with an error if an error is encountered.
4879
+ *
4880
+ * @param iteration
4881
+ * @param maxResultsLimit
4882
+ * @returns
4883
+ */
4884
+
4885
+ function _async$1(f) {
4886
+ return function () {
4887
+ for (var args = [], i = 0; i < arguments.length; i++) {
4888
+ args[i] = arguments[i];
4889
+ }
4890
+ try {
4891
+ return Promise.resolve(f.apply(this, args));
4892
+ } catch (e) {
4893
+ return Promise.reject(e);
4894
+ }
4895
+ };
4815
4896
  }
4816
- function itemAccumulator(itemIteration, mapItem) {
4817
- if (!mapItem) {
4818
- mapItem = a => a;
4897
+ function _call(body, then, direct) {
4898
+ if (direct) {
4899
+ return then ? then(body()) : body();
4819
4900
  }
4820
- return new ItemAccumulatorInstance(itemIteration, mapItem);
4901
+ try {
4902
+ var result = Promise.resolve(body());
4903
+ return then ? result.then(then) : result;
4904
+ } catch (e) {
4905
+ return Promise.reject(e);
4906
+ }
4907
+ }
4908
+ function itemAccumulator(itemIteration, inputMapItem) {
4909
+ const mapItemFunction = inputMapItem != null ? inputMapItem : a => a;
4910
+ const hasCompletedInitialLoad$ = itemIteration.firstState$.pipe(rxjs.map(() => true), rxjs.startWith(false), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
4911
+ const latestSuccessfulState$ = itemIteration.latestState$.pipe(rxjs.filter(x => !isLoadingStateWithError(x)), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
4912
+ const allSuccessfulStates$ = latestSuccessfulState$.pipe(scanIntoArray({
4913
+ immutable: false
4914
+ }),
4915
+ /**
4916
+ * Don't wait for the first successful state in order to avoid never returning a value on immediate failures.
4917
+ */
4918
+ rxjs.startWith([]), distinctUntilArrayLengthChanges(), rxjs.shareReplay(1));
4919
+ const successfulLoadCount$ = allSuccessfulStates$.pipe(rxjs.map(x => x.length), rxjs.shareReplay(1));
4920
+ // MARK: ItemAccumulator
4921
+ const currentAllItemPairs$ = allSuccessfulStates$.pipe(scanBuildArray(allSuccessfulStates => {
4922
+ const mapStateToItem = util.mapFunctionOutputPair(mapLoadingStateValueFunction(mapItemFunction));
4923
+ /*
4924
+ Start with allSuccessfulPageResults$ since it contains all page results since the start of the iterator,
4925
+ and subscription to allItems may not have started at the same time.
4926
+ We use scan to add in all models coming in afterwards by pushing them into the accumulator.
4927
+ This is to prevent performance issues with very large iteration sets, since we can
4928
+ append onto the array, rather than concat/copy the array each time.
4929
+ */
4930
+ const allPageResultsUpToFirstSubscription = allSuccessfulStates;
4931
+ const firstLatestState = util.lastValue(allPageResultsUpToFirstSubscription);
4932
+ const seed = allPageResultsUpToFirstSubscription.map(mapStateToItem).filter(x => util.isMaybeSo(x.output));
4933
+ const accumulatorObs = latestSuccessfulState$.pipe(rxjs.skipWhile(x => x === firstLatestState), rxjs.map(mapStateToItem), rxjs.filter(x => util.isMaybeSo(x.output)));
4934
+ return {
4935
+ seed,
4936
+ accumulatorObs
4937
+ };
4938
+ }), rxjs.shareReplay(1));
4939
+ const currentAllItems$ = currentAllItemPairs$.pipe(rxjs.map(x => x.map(y => y.output)), rxjs.shareReplay(1));
4940
+ const allItemPairs$ = hasCompletedInitialLoad$.pipe(switchMapWhileTrue(currentAllItemPairs$), rxjs.shareReplay(1));
4941
+ const allItems$ = hasCompletedInitialLoad$.pipe(switchMapWhileTrue(currentAllItems$), rxjs.shareReplay(1));
4942
+ const sub = new SubscriptionObject(allSuccessfulStates$.subscribe());
4943
+ const destroy = () => sub.destroy();
4944
+ const result = {
4945
+ itemIteration,
4946
+ mapItemFunction,
4947
+ hasCompletedInitialLoad$,
4948
+ latestSuccessfulState$,
4949
+ allSuccessfulStates$,
4950
+ successfulLoadCount$,
4951
+ currentAllItemPairs$,
4952
+ currentAllItems$,
4953
+ allItemPairs$,
4954
+ allItems$,
4955
+ destroy
4956
+ };
4957
+ return result;
4821
4958
  }
4822
- /**
4823
- * Automatically calls next on the accumulator's page item iteration up to the target number of results. Returns the total number of items loaded.
4824
- *
4825
- * The promise will reject with an error if an error is encountered.
4826
- *
4827
- * @param iteration
4828
- * @param maxResultsLimit
4829
- * @returns
4830
- */
4831
4959
  function itemAccumulatorNextPageUntilResultsCount(config) {
4960
+ const checkResultsLimit = _async$1(function () {
4961
+ return _await$1(rxjs.firstValueFrom(accumulator.currentAllItems$), function (allItems) {
4962
+ return _await$1(rxjs.firstValueFrom(canLoadMoreObs), function (canLoadMore) {
4963
+ return _await$1(countResults(allItems), function (currentCount) {
4964
+ const maxResultsLimit = getMaxResultsLimit();
4965
+ const shouldContinue = canLoadMore && currentCount < maxResultsLimit;
4966
+ return {
4967
+ shouldContinue,
4968
+ currentCount
4969
+ };
4970
+ });
4971
+ });
4972
+ });
4973
+ });
4832
4974
  const {
4833
4975
  accumulator,
4834
4976
  maxResultsLimit,
@@ -4838,30 +4980,18 @@ function itemAccumulatorNextPageUntilResultsCount(config) {
4838
4980
  const canLoadMoreObs = iterationHasNextAndCanLoadMore(accumulator.itemIteration).pipe(timeoutStartWith(false, 100),
4839
4981
  // TODO: This can fail to emit anything if the iterator has been destroyed
4840
4982
  rxjs.shareReplay(1));
4841
- function checkResultsLimit() {
4842
- return __awaiter(this, void 0, void 0, function* () {
4843
- const allItems = yield rxjs.firstValueFrom(accumulator.currentAllItems$);
4844
- const canLoadMore = yield rxjs.firstValueFrom(canLoadMoreObs);
4845
- const currentCount = yield countResults(allItems);
4846
- const maxResultsLimit = getMaxResultsLimit();
4847
- const shouldContinue = canLoadMore && currentCount < maxResultsLimit;
4848
- return {
4849
- shouldContinue,
4850
- currentCount
4851
- };
4852
- });
4853
- }
4854
4983
  return new Promise((resolve, reject) => {
4855
4984
  accumulator.currentAllItems$.pipe(rxjs.first(), rxjs.switchMap(allItems => rxjs.from(util.asPromise(countResults(allItems))))).subscribe({
4856
- next: currentResultsCount => __awaiter(this, void 0, void 0, function* () {
4985
+ next: _async$1(function (currentResultsCount) {
4857
4986
  util.performTaskLoop({
4858
4987
  initValue: currentResultsCount,
4859
- checkContinue: (x, i) => __awaiter(this, void 0, void 0, function* () {
4860
- const result = yield checkResultsLimit();
4861
- currentResultsCount = result.currentCount;
4862
- return result.shouldContinue;
4863
- }),
4864
- next: () => __awaiter(this, void 0, void 0, function* () {
4988
+ checkContinue: function (x, i) {
4989
+ return _call(checkResultsLimit, function (result) {
4990
+ currentResultsCount = result.currentCount;
4991
+ return result.shouldContinue;
4992
+ });
4993
+ },
4994
+ next: _async$1(function () {
4865
4995
  return accumulator.itemIteration.nextPage();
4866
4996
  })
4867
4997
  }).then(page => {
@@ -4873,6 +5003,7 @@ function itemAccumulatorNextPageUntilResultsCount(config) {
4873
5003
  reject(error);
4874
5004
  throw error;
4875
5005
  });
5006
+ return _await$1();
4876
5007
  }),
4877
5008
  error: error => {
4878
5009
  reject(error);
@@ -4891,7 +5022,7 @@ function flattenAccumulatorResultItemArray(accumulator) {
4891
5022
  return accumulator.currentAllItemPairs$.pipe(scanBuildArray(allItems => {
4892
5023
  const pairs = allItems;
4893
5024
  const firstLatestItemPair = util.lastValue(allItems);
4894
- const skipValue = firstLatestItemPair === null || firstLatestItemPair === void 0 ? void 0 : firstLatestItemPair.input;
5025
+ const skipValue = firstLatestItemPair == null ? void 0 : firstLatestItemPair.input;
4895
5026
  const seed = util.flattenArray(pairs.map(x => x.output));
4896
5027
  const mapStateToItem = mapLoadingStateValueFunction(accumulator.mapItemFunction);
4897
5028
  const accumulatorObs = accumulator.itemIteration.latestState$.pipe(rxjs.skipWhile(x => x.value === skipValue), rxjs.map(mapStateToItem), filterMaybe());
@@ -4932,6 +5063,13 @@ function pageItemAccumulatorCurrentPage(pageItemAccumulator) {
4932
5063
 
4933
5064
  class MappedItemIterationInstance {
4934
5065
  constructor(itemIterator, config) {
5066
+ this.itemIterator = void 0;
5067
+ this.config = void 0;
5068
+ this.hasNext$ = void 0;
5069
+ this.canLoadMore$ = void 0;
5070
+ this.firstState$ = void 0;
5071
+ this.latestState$ = void 0;
5072
+ this.currentState$ = void 0;
4935
5073
  this.itemIterator = itemIterator;
4936
5074
  this.config = config;
4937
5075
  this.hasNext$ = this.itemIterator.hasNext$;
@@ -4964,8 +5102,8 @@ function mapItemIteration(itemIteration, config) {
4964
5102
  * MappedItemIterationInstance extension that implements PageItemIteration.
4965
5103
  */
4966
5104
  class MappedPageItemIterationInstance extends MappedItemIterationInstance {
4967
- constructor() {
4968
- super(...arguments);
5105
+ constructor(...args) {
5106
+ super(...args);
4969
5107
  this.latestLoadedPage$ = this.itemIterator.latestLoadedPage$;
4970
5108
  }
4971
5109
  // MARK: PageItemIteration
@@ -4994,10 +5132,32 @@ function mapPageItemIteration(itemIteration, config) {
4994
5132
  /**
4995
5133
  * Default number of pages that can be loaded.
4996
5134
  */
5135
+
5136
+ function _await(value, then, direct) {
5137
+ if (direct) {
5138
+ return then ? then(value) : value;
5139
+ }
5140
+ if (!value || !value.then) {
5141
+ value = Promise.resolve(value);
5142
+ }
5143
+ return then ? value.then(then) : value;
5144
+ } /**
5145
+ * Used for generating new iterations.
5146
+ */
5147
+
5148
+ function _async(f) {
5149
+ return function () {
5150
+ for (var args = [], i = 0; i < arguments.length; i++) {
5151
+ args[i] = arguments[i];
5152
+ }
5153
+ try {
5154
+ return Promise.resolve(f.apply(this, args));
5155
+ } catch (e) {
5156
+ return Promise.reject(e);
5157
+ }
5158
+ };
5159
+ }
4997
5160
  const DEFAULT_ITEM_PAGE_ITERATOR_MAX = 100;
4998
- /**
4999
- * Used for generating new iterations.
5000
- */
5001
5161
  class ItemPageIterator {
5002
5162
  get maxPageLoadLimit() {
5003
5163
  return this._maxPageLoadLimit;
@@ -5006,6 +5166,8 @@ class ItemPageIterator {
5006
5166
  this._maxPageLoadLimit = maxPageLoadLimit;
5007
5167
  }
5008
5168
  constructor(delegate) {
5169
+ this.delegate = void 0;
5170
+ this._maxPageLoadLimit = void 0;
5009
5171
  this.delegate = delegate;
5010
5172
  }
5011
5173
  /**
@@ -5023,16 +5185,16 @@ class ItemPageIterator {
5023
5185
  */
5024
5186
  class ItemPageIterationInstance {
5025
5187
  constructor(iterator, config) {
5026
- var _a;
5027
- this.iterator = iterator;
5028
- this.config = config;
5188
+ var _this$config$maxPageL;
5189
+ this.iterator = void 0;
5190
+ this.config = void 0;
5029
5191
  /**
5030
5192
  * Used for triggering loading of more content.
5031
5193
  */
5032
5194
  this._next = new rxjs.BehaviorSubject({
5033
5195
  n: 0
5034
5196
  });
5035
- this._maxPageLoadLimit = new rxjs.BehaviorSubject((_a = this.config.maxPageLoadLimit) !== null && _a !== void 0 ? _a : this.iterator.maxPageLoadLimit);
5197
+ this._maxPageLoadLimit = new rxjs.BehaviorSubject(undefined);
5036
5198
  // MARK: State
5037
5199
  this.state$ = this._next.pipe(rxjs.delay(0), rxjs.exhaustMap(request => rxjs.combineLatest([this.hasNextAndCanLoadMore$, this._lastFinishedPageResultState$]).pipe(rxjs.first(), rxjs.map(([hasNextAndCanLoadMore, prevResult]) => [itemPageIteratorShouldLoadNextPage(request, hasNextAndCanLoadMore, prevResult), prevResult]), rxjs.mergeMap(([shouldLoadNextPage, prevResult]) => {
5038
5200
  if (shouldLoadNextPage) {
@@ -5081,13 +5243,13 @@ class ItemPageIterationInstance {
5081
5243
  };
5082
5244
  // If it was a replay of the previous result, change nothing.
5083
5245
  if (acc.current !== curr) {
5084
- if (loadingStateHasFinishedLoading(curr)) {
5246
+ if (isLoadingStateFinishedLoading(curr)) {
5085
5247
  // only set first finished once
5086
5248
  if (!next.firstFinished) {
5087
5249
  next.firstFinished = curr;
5088
5250
  }
5089
5251
  next.latestFinished = curr;
5090
- if (!loadingStateHasError(curr)) {
5252
+ if (!isLoadingStateWithError(curr)) {
5091
5253
  next.lastSuccessful = curr;
5092
5254
  if (!next.firstSuccessful) {
5093
5255
  next.firstSuccessful = curr;
@@ -5116,7 +5278,7 @@ class ItemPageIterationInstance {
5116
5278
  /**
5117
5279
  * Same as _nextTrigger$, but catches finished loading events.
5118
5280
  */
5119
- this._nextFinished$ = this._nextTrigger$.pipe(rxjs.filter(x => loadingStateHasFinishedLoading(x.current)));
5281
+ this._nextFinished$ = this._nextTrigger$.pipe(rxjs.filter(x => isLoadingStateFinishedLoading(x.current)));
5120
5282
  /**
5121
5283
  * The first page results that finished loading.
5122
5284
  */
@@ -5143,10 +5305,10 @@ class ItemPageIterationInstance {
5143
5305
  /**
5144
5306
  * Whether or not items are currently being loaded.
5145
5307
  */
5146
- this.isLoading$ = this._currentPageResultState$.pipe(rxjs.map(x => loadingStateIsLoading(x)), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
5308
+ this.isLoading$ = this._currentPageResultState$.pipe(rxjs.map(x => isLoadingStateLoading(x)), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
5147
5309
  this._lastFinishedPageResultState$ = this.latestPageResultState$.pipe(rxjs.startWith(undefined), rxjs.shareReplay(1));
5148
- this._lastFinishedPageResult$ = this._lastFinishedPageResultState$.pipe(rxjs.map(x => x === null || x === void 0 ? void 0 : x.value));
5149
- this._lastFinishedPageResultItem$ = this._lastFinishedPageResult$.pipe(rxjs.map(x => x === null || x === void 0 ? void 0 : x.value));
5310
+ this._lastFinishedPageResult$ = this._lastFinishedPageResultState$.pipe(rxjs.map(x => x == null ? void 0 : x.value));
5311
+ this._lastFinishedPageResultItem$ = this._lastFinishedPageResult$.pipe(rxjs.map(x => x == null ? void 0 : x.value));
5150
5312
  /**
5151
5313
  * The first page results that has finished loading without an error.
5152
5314
  */
@@ -5174,6 +5336,9 @@ class ItemPageIterationInstance {
5174
5336
  this.firstState$ = this.firstPageResultState$.pipe(mapItemPageLoadingStateFromResultPageLoadingState(), rxjs.shareReplay(1));
5175
5337
  this.latestState$ = this.latestPageResultState$.pipe(mapItemPageLoadingStateFromResultPageLoadingState(), rxjs.shareReplay(1));
5176
5338
  this.latestItems$ = this.latestState$.pipe(rxjs.distinctUntilChanged(), rxjs.map(x => x.value), rxjs.shareReplay(1));
5339
+ this.iterator = iterator;
5340
+ this.config = config;
5341
+ this._maxPageLoadLimit.next((_this$config$maxPageL = this.config.maxPageLoadLimit) != null ? _this$config$maxPageL : this.iterator.maxPageLoadLimit);
5177
5342
  }
5178
5343
  // MARK: PageItemIteration
5179
5344
  get maxPageLoadLimit() {
@@ -5184,8 +5349,9 @@ class ItemPageIterationInstance {
5184
5349
  this._maxPageLoadLimit.next(limit);
5185
5350
  }
5186
5351
  nextPage(request = {}) {
5187
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
5188
- this._nextFinished$.pipe(rxjs.exhaustMap(() => this.latestPageResultState$), rxjs.defaultIfEmpty({
5352
+ const _this = this;
5353
+ return new Promise(_async(function (resolve, reject) {
5354
+ _this._nextFinished$.pipe(rxjs.exhaustMap(() => _this.latestPageResultState$), rxjs.defaultIfEmpty({
5189
5355
  error: undefined,
5190
5356
  page: -1
5191
5357
  }), rxjs.first()).subscribe({
@@ -5200,7 +5366,8 @@ class ItemPageIterationInstance {
5200
5366
  reject(error);
5201
5367
  }
5202
5368
  });
5203
- this.next(request);
5369
+ _this.next(request);
5370
+ return _await();
5204
5371
  }));
5205
5372
  }
5206
5373
  next(request = {}) {
@@ -5241,13 +5408,13 @@ function isItemPageIteratorResultEndResult(result) {
5241
5408
  function itemPageIteratorShouldLoadNextPage(request, hasNextAndCanLoadMore, prevResult) {
5242
5409
  return hasNextAndCanLoadMore &&
5243
5410
  // Must be able to load more
5244
- Boolean(!loadingStateHasError(prevResult) || request.retry) &&
5411
+ Boolean(!isLoadingStateWithError(prevResult) || request.retry) &&
5245
5412
  // Must not have any errors
5246
5413
  Boolean(request.page == null || nextIteratorPageNumber(prevResult) === request.page); // Must match the page, if provided
5247
5414
  }
5248
5415
 
5249
5416
  function nextIteratorPageNumber(prevResult) {
5250
- return loadingStateHasError(prevResult) ? prevResult.page : util.getNextPageNumber(prevResult);
5417
+ return isLoadingStateWithError(prevResult) ? prevResult.page : util.getNextPageNumber(prevResult);
5251
5418
  }
5252
5419
  function mapItemPageLoadingStateFromResultPageLoadingState() {
5253
5420
  return rxjs.map(itemPageLoadingStateFromResultPageLoadingState);
@@ -5268,8 +5435,8 @@ function onLockSetNextUnlock({
5268
5435
  timeout: inputTimeout,
5269
5436
  delayTime
5270
5437
  }) {
5271
- const timeoutTime = inputTimeout !== null && inputTimeout !== void 0 ? inputTimeout : util.MS_IN_SECOND * 50;
5272
- return lockSet.isUnlocked$.pipe(rxjs.filter(x => x), rxjs.delay(delayTime !== null && delayTime !== void 0 ? delayTime : 0), rxjs.timeout({
5438
+ const timeoutTime = inputTimeout != null ? inputTimeout : util.MS_IN_SECOND * 50;
5439
+ return lockSet.isUnlocked$.pipe(rxjs.filter(x => x), rxjs.delay(delayTime != null ? delayTime : 0), rxjs.timeout({
5273
5440
  first: timeoutTime,
5274
5441
  with: () => rxjs.of(false).pipe(rxjs.tap(() => console.warn('LockSet time out. Potential issue detected.')))
5275
5442
  }), rxjs.first()).subscribe(fn);
@@ -5296,13 +5463,12 @@ class LockSet {
5296
5463
  return this._locks.value;
5297
5464
  }
5298
5465
  setLocked(key, config, duration) {
5299
- var _a;
5300
5466
  let lockedConfig;
5301
5467
  if (typeof config === 'object') {
5302
5468
  lockedConfig = config;
5303
5469
  } else {
5304
5470
  lockedConfig = {
5305
- locked: (_a = config) !== null && _a !== void 0 ? _a : true,
5471
+ locked: config != null ? config : true,
5306
5472
  duration
5307
5473
  };
5308
5474
  }
@@ -5323,7 +5489,7 @@ class LockSet {
5323
5489
  this.lockForTime(seconds * 1000);
5324
5490
  }
5325
5491
  lockForTime(milliseconds, key) {
5326
- this.addLock(key !== null && key !== void 0 ? key : DEFAULT_LOCK_SET_TIME_LOCK_KEY, rxjs.of(false).pipe(rxjs.delay(milliseconds), rxjs.startWith(true)));
5492
+ this.addLock(key != null ? key : DEFAULT_LOCK_SET_TIME_LOCK_KEY, rxjs.of(false).pipe(rxjs.delay(milliseconds), rxjs.startWith(true)));
5327
5493
  }
5328
5494
  addLock(key, obs) {
5329
5495
  obs = obs.pipe(rxjs.defaultIfEmpty(false) // empty observables count as unlocked.
@@ -5361,7 +5527,7 @@ class LockSet {
5361
5527
  }
5362
5528
  return removeFn;
5363
5529
  }), cleanup(removeLockSet => {
5364
- removeLockSet === null || removeLockSet === void 0 ? void 0 : removeLockSet();
5530
+ removeLockSet == null || removeLockSet();
5365
5531
  })).subscribe();
5366
5532
  }
5367
5533
  /**
@@ -5382,9 +5548,9 @@ class LockSet {
5382
5548
  mergeConfig = config;
5383
5549
  }
5384
5550
  }
5385
- this.onNextUnlock(Object.assign(Object.assign({}, mergeConfig), {
5551
+ this.onNextUnlock(Object.assign({}, mergeConfig, {
5386
5552
  fn: unlocked => {
5387
- fn === null || fn === void 0 ? void 0 : fn(unlocked);
5553
+ fn == null || fn(unlocked);
5388
5554
  setTimeout(() => this.destroy(), 100);
5389
5555
  },
5390
5556
  delayTime
@@ -5402,15 +5568,18 @@ LockSet.LOCK_SET_CHILD_INDEX_STEPPER = 0;
5402
5568
  */
5403
5569
  class WorkInstance {
5404
5570
  constructor(value, delegate) {
5405
- this.value = value;
5406
- this.delegate = delegate;
5571
+ this.value = void 0;
5572
+ this.delegate = void 0;
5407
5573
  this._done = false;
5408
5574
  this._doneActionBegan = false;
5575
+ this._result = void 0;
5409
5576
  this._loadingState = new rxjs.BehaviorSubject(undefined);
5410
5577
  this._sub = new SubscriptionObject();
5411
5578
  this.loadingState$ = this._loadingState.pipe(filterMaybe());
5412
5579
  this._hasStarted$ = this._loadingState.pipe(rxjs.map(x => Boolean(x)), rxjs.shareReplay(1));
5413
- this._isComplete$ = this.loadingState$.pipe(rxjs.map(x => loadingStateHasFinishedLoading(x)), rxjs.shareReplay(1));
5580
+ this._isComplete$ = this.loadingState$.pipe(rxjs.map(x => isLoadingStateFinishedLoading(x)), rxjs.shareReplay(1));
5581
+ this.value = value;
5582
+ this.delegate = delegate;
5414
5583
  // Schedule to cleanup self once isComplete is true.
5415
5584
  this.result$.subscribe(loadingState => {
5416
5585
  this._result = loadingState;
@@ -5424,7 +5593,7 @@ class WorkInstance {
5424
5593
  return this._done ? rxjs.of(this._doneActionBegan) : this._hasStarted$;
5425
5594
  }
5426
5595
  get isComplete() {
5427
- return this._done || loadingStateHasFinishedLoading(this._loadingState.value);
5596
+ return this._done || isLoadingStateFinishedLoading(this._loadingState.value);
5428
5597
  }
5429
5598
  get isComplete$() {
5430
5599
  return this._done ? rxjs.of(true) : this._isComplete$;
@@ -5447,7 +5616,7 @@ class WorkInstance {
5447
5616
  this._sub.subscription = obs.pipe(rxjs.delay(0),
5448
5617
  // delay to prevent an immediate start working, which can override the _sub.subscription value
5449
5618
  rxjs.first()).subscribe(() => {
5450
- this.startWorkingWithObservable(obs.pipe(rxjs.filter(x => x && !loadingStateIsLoading(x)),
5619
+ this.startWorkingWithObservable(obs.pipe(rxjs.filter(x => x && !isLoadingStateLoading(x)),
5451
5620
  // don't return until it has finished loading.
5452
5621
  rxjs.map(x => {
5453
5622
  if (x.error) {
@@ -5605,7 +5774,6 @@ exports.FilterMapKeyInstance = FilterMapKeyInstance;
5605
5774
  exports.FilterSource = FilterSource;
5606
5775
  exports.FilterSourceConnector = FilterSourceConnector;
5607
5776
  exports.FilterSourceInstance = FilterSourceInstance;
5608
- exports.ItemAccumulatorInstance = ItemAccumulatorInstance;
5609
5777
  exports.ItemPageIterationInstance = ItemPageIterationInstance;
5610
5778
  exports.ItemPageIterator = ItemPageIterator;
5611
5779
  exports.ListLoadingStateContextInstance = ListLoadingStateContextInstance;
@@ -5622,6 +5790,7 @@ exports.WorkInstance = WorkInstance;
5622
5790
  exports.accumulatorCurrentPageListLoadingState = accumulatorCurrentPageListLoadingState;
5623
5791
  exports.accumulatorFlattenPageListLoadingState = accumulatorFlattenPageListLoadingState;
5624
5792
  exports.allLoadingStatesHaveFinishedLoading = allLoadingStatesHaveFinishedLoading;
5793
+ exports.areAllLoadingStatesFinishedLoading = areAllLoadingStatesFinishedLoading;
5625
5794
  exports.asObservable = asObservable;
5626
5795
  exports.asObservableFromGetter = asObservableFromGetter;
5627
5796
  exports.asyncPusher = asyncPusher;
@@ -5665,11 +5834,25 @@ exports.idleLoadingState = idleLoadingState;
5665
5834
  exports.incrementingNumberTimer = incrementingNumberTimer;
5666
5835
  exports.initialize = initialize;
5667
5836
  exports.invertObservableDecision = invertObservableDecision;
5837
+ exports.isAnyLoadingStateInLoadingState = isAnyLoadingStateInLoadingState;
5668
5838
  exports.isErrorLoadingState = isErrorLoadingState;
5669
5839
  exports.isItemPageIteratorResultEndResult = isItemPageIteratorResultEndResult;
5670
5840
  exports.isListLoadingStateEmpty = isListLoadingStateEmpty;
5841
+ exports.isListLoadingStateWithEmptyValue = isListLoadingStateWithEmptyValue;
5671
5842
  exports.isLoading = isLoading;
5843
+ exports.isLoadingStateFinishedLoading = isLoadingStateFinishedLoading;
5844
+ exports.isLoadingStateFinishedLoadingWithDefinedValue = isLoadingStateFinishedLoadingWithDefinedValue;
5845
+ exports.isLoadingStateFinishedLoadingWithError = isLoadingStateFinishedLoadingWithError;
5846
+ exports.isLoadingStateInErrorState = isLoadingStateInErrorState;
5847
+ exports.isLoadingStateInIdleState = isLoadingStateInIdleState;
5848
+ exports.isLoadingStateInLoadingState = isLoadingStateInLoadingState;
5849
+ exports.isLoadingStateInSuccessState = isLoadingStateInSuccessState;
5850
+ exports.isLoadingStateLoading = isLoadingStateLoading;
5851
+ exports.isLoadingStateWithDefinedValue = isLoadingStateWithDefinedValue;
5852
+ exports.isLoadingStateWithError = isLoadingStateWithError;
5853
+ exports.isLoadingStateWithStateType = isLoadingStateWithStateType;
5672
5854
  exports.isNot = isNot;
5855
+ exports.isPageLoadingStateMetadataEqual = isPageLoadingStateMetadataEqual;
5673
5856
  exports.isSuccessLoadingState = isSuccessLoadingState;
5674
5857
  exports.itemAccumulator = itemAccumulator;
5675
5858
  exports.itemAccumulatorNextPageUntilResultsCount = itemAccumulatorNextPageUntilResultsCount;
@@ -5698,6 +5881,7 @@ exports.mapEachAsync = mapEachAsync;
5698
5881
  exports.mapFilterWithPreset = mapFilterWithPreset;
5699
5882
  exports.mapForEach = mapForEach;
5700
5883
  exports.mapIf = mapIf;
5884
+ exports.mapIsListLoadingStateWithEmptyValue = mapIsListLoadingStateWithEmptyValue;
5701
5885
  exports.mapItemIteration = mapItemIteration;
5702
5886
  exports.mapKeysIntersectionToArray = mapKeysIntersectionToArray;
5703
5887
  exports.mapLoadingState = mapLoadingState;
@@ -5708,6 +5892,9 @@ exports.mapMaybe = mapMaybe;
5708
5892
  exports.mapMultipleLoadingStateResults = mapMultipleLoadingStateResults;
5709
5893
  exports.mapPageItemIteration = mapPageItemIteration;
5710
5894
  exports.maybeValueFromObservableOrValueGetter = maybeValueFromObservableOrValueGetter;
5895
+ exports.mergeLoadingStateWithError = mergeLoadingStateWithError;
5896
+ exports.mergeLoadingStateWithLoading = mergeLoadingStateWithLoading;
5897
+ exports.mergeLoadingStateWithValue = mergeLoadingStateWithValue;
5711
5898
  exports.mergeLoadingStates = mergeLoadingStates;
5712
5899
  exports.multiKeyValueMap = multiKeyValueMap;
5713
5900
  exports.onFalseToTrue = onFalseToTrue;