@reactables/forms 0.7.0-alpha.14 → 0.7.0-alpha.16

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.
@@ -1,4 +1,4 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { Action } from '@reactables/core';
3
3
  import { BaseFormState } from '../Models/Controls';
4
- export declare const buildHub2Source: <T, S>(hub1State$: Observable<BaseFormState<T>>) => Observable<Action<T>>;
4
+ export declare const buildHub2Source: <T>(hub1State$: Observable<BaseFormState<T>>) => Observable<Action<T>>;
@@ -33,11 +33,13 @@ export type CustomReducer = CustomReducerFunc | {
33
33
  reducer: CustomReducerFunc;
34
34
  effects?: ((payload?: unknown) => ScopedEffects<unknown>) | Effect<unknown, unknown>[];
35
35
  };
36
- export interface CustomReducers {
37
- [key: string]: CustomReducer;
38
- }
39
- export interface RxFormOptions<T extends CustomReducers> extends EffectsAndSources {
40
- reducers?: T;
36
+ export type CustomReducers<T> = {
37
+ [key in keyof (T & {
38
+ [key: string]: CustomReducer;
39
+ })]: CustomReducer;
40
+ };
41
+ export interface RxFormOptions extends EffectsAndSources {
42
+ reducers?: CustomReducers<unknown>;
41
43
  providers?: RxFormProviders;
42
44
  name?: string;
43
45
  }
@@ -53,6 +55,8 @@ export interface RxFormProviders {
53
55
  [key: string]: ValidatorAsyncFn;
54
56
  };
55
57
  }
56
- export declare const build: <T extends CustomReducers>(config: AbstractControlConfig, options?: RxFormOptions<T>) => Reactable<Form<unknown>, { [K in keyof T]: (payload?: any) => void; } & RxFormActions>;
57
- export declare const load: <T extends CustomReducers>(state: Form<unknown>, options?: RxFormOptions<T>) => Reactable<Form<unknown>, { [K in keyof T]: (payload?: any) => void; } & RxFormActions>;
58
+ export declare const build: <T extends CustomReducers<S>, S>(config: AbstractControlConfig, options?: RxFormOptions) => Reactable<Form<unknown>, { [K in keyof T]: (payload?: any) => void; } & RxFormActions>;
59
+ export declare const load: (state: Form<unknown>, options?: RxFormOptions) => Reactable<Form<unknown>, {
60
+ [x: string]: (payload?: any) => void;
61
+ } & RxFormActions>;
58
62
  export {};
package/dist/index.js CHANGED
@@ -337,34 +337,28 @@ var getAncestorControls = function (controlRef, form, excludeSelf) {
337
337
  };
338
338
 
339
339
  var UPDATE_DESCENDANT_VALUES = 'UPDATE_DESCENDANT_VALUES';
340
- var updateDescendants = function (state, _a, providers) {
340
+ var updateDescendantValues = function (form, _a, providers) {
341
341
  var _b = _a.payload, controlRef = _b.controlRef, value = _b.value;
342
- var descendants = getDescendantControls(controlRef, state.form, true).map(function (control) { return [getFormKey(control.controlRef), control]; });
342
+ var descendants = getDescendantControls(controlRef, form, true).map(function (control) { return [getFormKey(control.controlRef), control]; });
343
343
  var result = descendants.reduce(function (acc, _a) {
344
- var _b, _c;
344
+ var _b;
345
345
  var key = _a[0], control = _a[1];
346
346
  if (isChildRef(control.controlRef, controlRef)) {
347
347
  var childValue = value[control.controlRef.at(-1)];
348
348
  var validatorErrors = getErrors(control, childValue, providers);
349
349
  var newControl = __assign(__assign({}, control), { value: childValue, validatorErrors: validatorErrors, dirty: !isEqual__default["default"](childValue, control.pristineValue) });
350
- acc = {
351
- form: __assign(__assign({}, acc.form), (_b = {}, _b[key] = newControl, _b)),
352
- changedControls: __assign(__assign({}, acc.changedControls), (_c = {}, _c[newControl.key] = newControl, _c))
353
- };
350
+ acc = __assign(__assign({}, acc), (_b = {}, _b[key] = newControl, _b));
354
351
  var configControls = control.config.controls;
355
352
  if (configControls) {
356
- acc = updateDescendants(acc, {
353
+ acc = updateDescendantValues(acc, {
357
354
  type: UPDATE_DESCENDANT_VALUES,
358
355
  payload: { controlRef: control.controlRef, value: childValue }
359
356
  }, providers);
360
357
  }
361
358
  }
362
359
  return acc;
363
- }, { form: {}, changedControls: {} });
364
- return {
365
- form: __assign(__assign({}, state.form), result.form),
366
- changedControls: __assign({}, result.changedControls)
367
- };
360
+ }, form);
361
+ return result;
368
362
  };
369
363
  // Will only update child controls that are present.
370
364
  // Use AddControlPayload/RemoveControl action reducers to add/remove control
@@ -393,15 +387,20 @@ var updateValues = function (_a, action, providers, mergeChanges) {
393
387
  changedControls: (_c = {}, _c[newControl.key] = newControl, _c)
394
388
  };
395
389
  var configControls = config.controls;
396
- // Update its children
390
+ // Update its descendants
397
391
  if (configControls) {
398
- result = updateDescendants(result, {
392
+ var updatedDescendants = updateDescendantValues(result.form, {
399
393
  type: UPDATE_DESCENDANT_VALUES,
400
394
  payload: {
401
395
  controlRef: controlRef,
402
396
  value: newValue
403
397
  }
404
398
  }, providers);
399
+ var changedDescendantControls = getDescendantControls(controlRef, updatedDescendants).reduce(function (acc, control) {
400
+ var _a;
401
+ return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
402
+ }, {});
403
+ result = __assign(__assign({}, result), { form: updatedDescendants, changedControls: __assign(__assign({}, result.changedControls), changedDescendantControls) });
405
404
  }
406
405
  // Update its Ancestors
407
406
  if (controlRef.length) {
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "author": "David Lai",
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
- "@reactables/core": "^0.7.0-alpha.14",
17
+ "@reactables/core": "^0.7.0-alpha.16",
18
18
  "lodash.isequal": "^4.5.0"
19
19
  },
20
20
  "peerDependencies": {
@@ -23,5 +23,5 @@
23
23
  "devDependencies": {
24
24
  "lodash.clonedeep": "^4.5.0"
25
25
  },
26
- "version": "0.7.0-alpha.14"
26
+ "version": "0.7.0-alpha.16"
27
27
  }