@reactables/forms 0.5.1-alpha.0 → 0.5.3-alpha.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/README.md CHANGED
@@ -2,14 +2,119 @@
2
2
 
3
3
  ## Description
4
4
 
5
- State management for building a comprehensive form library using [Reactables Core](https://github.com/reactables/reactables/tree/main/packages/core).
5
+ State Management of reactive forms with [Reactables](https://github.com/reactables/reactables/tree/main/packages/core).
6
6
 
7
- ## Architecture (WIP see https://github.com/reactables/reactables/issues/8)
7
+ ## Table of Contents
8
8
 
9
- The following diagram visualizes the architecture of [Reactables Forms](https://github.com/reactables/reactables/tree/main/packages/forms) - a state management model for building reactive forms.
9
+ 1. [Installation](#installation)
10
+ 1. [Examples](#examples)
11
+ 1. [Form Control](#form-control)
12
+ 1. [Form Array](#form-array)
13
+ 1. [Form Group](#form-group)
10
14
 
11
- There are two sets of hub and stores. The first set is responsible for handling user input and updating the form.
15
+ 1. [API](#api)
16
+ 1. [RxActions](#api-actions)
17
+ 1. [build](#api-build)
18
+ 1. [control](#api-control)
19
+ 1. [group](#api-group)
20
+ 1. [array](#api-array)
21
+ 1. [Other Interfaces](#interfaces)
22
+ 1. [EffectsAndSources](#effects-sources)
12
23
 
13
- The second set is responsible for reacting to the form change in the first store and asynchronous validation.
14
24
 
15
- ![Reactables architecture](https://raw.githubusercontent.com/reactables/reactables/main/documentation/Slide10ReactablesForms.jpg)
25
+ ## Installation <a name="installation"></a>
26
+
27
+ Installation will require [RxJS](https://rxjs.dev/) if not already installed.
28
+
29
+ `npm i rxjs @reactables/forms`
30
+
31
+ ## Examples <a name="examples"></a>
32
+
33
+ WIP
34
+
35
+ ## API <a name="api"></a>
36
+
37
+ The API for building Reactable Forms is very similar to [Angular FormBuilder](https://angular.io/api/forms/FormBuilder). It has been adapted to support Reactable features.
38
+
39
+ ### `RxActions` <a name="api-actions"></a>
40
+
41
+ Actions available to trigger state changes on Reactable.
42
+
43
+ ```typescript
44
+ type RxFormActions = {
45
+ updateValues: <T>(payload: ControlChange<T>) => void;
46
+ addControl: (payload: AddControl) => void;
47
+ pushControl: (payload: PushControl) => void;
48
+ removeControl: (payload: ControlRef) => void;
49
+ markControlAsPristine: (payload: ControlRef) => void;
50
+ markControlAsTouched: (payload: MarkTouched) => void;
51
+ markControlAsUntouched: (payload: ControlRef) => void;
52
+ resetControl: (payload: ControlRef) => void;
53
+ };
54
+ ```
55
+
56
+ ### `build` <a name="api-build"></a>
57
+
58
+ ```typescript
59
+ type build = (config: AbstractControlConfig, options?: EffectsAndSources) => Reactable<Form<unknown>, RxFormActions>
60
+ ```
61
+
62
+ Factory method for creating a form Reactable. Accepts a configuration object generated by one or more helper methods - [`control`](#api-control), [`group`](#api-group), [`array`](#api-array).
63
+
64
+ Options can also be provided to declare [Effects and Sources](#effects-sources) for the form Reactable.
65
+
66
+ ### `control` <a name="api-control"></a>
67
+
68
+ Function to create a `FormControlConfig` configuration object. Accepts a configuration object or a tuple.
69
+ ```typescript
70
+ type control = <T>(config: FormControlConfig<T> | FbControl<T>) => FormControlConfig<T>
71
+
72
+ interface FormControlConfig<T> {
73
+ initialValue: T;
74
+ validators?: ValidatorFn[];
75
+ asyncValidators?: ValidatorAsyncFn[];
76
+ }
77
+
78
+ type FbControl<T> = [T, (ValidatorFn | ValidatorFn[])?, (ValidatorAsyncFn | ValidatorAsyncFn[])?];
79
+ ```
80
+
81
+ ### `group` <a name="api-group"></a>
82
+
83
+ Function to create a `FormGroupConfig` configuration object. Accepts a configuration object containing a `controls` dictionary of additional configuration objects generated by [`control`](#api-control), [`group`](#api-group), or [`array`](#api-array).
84
+
85
+ ```typescript
86
+ type group = (config: FormGroupConfig) => FormGroupConfig
87
+
88
+ interface FormGroupConfig{
89
+ validators?: ValidatorFn[];
90
+ asyncValidators?: ValidatorAsyncFn[];
91
+ controls: { [key: string]: AbstractControlConfig };
92
+ }
93
+ ```
94
+ ### `array` <a name="api-array"></a>
95
+
96
+ Function to create a `FormArrayConfig` configuration object. Accepts a configuration object containing a `controls` array of additional configuration objects generated by [`control`](#api-control), [`group`](#api-group), or [`array`](#api-array).
97
+
98
+ ```typescript
99
+ type array = (config: FormArrayConfig) => FormArrayConfig
100
+
101
+ interface FormArrayConfig {
102
+ validators?: ValidatorFn[];
103
+ asyncValidators?: ValidatorAsyncFn[];
104
+ controls: AbstractControlConfig[];
105
+ }
106
+ ```
107
+
108
+ ### Other Interfaces <a name="interfaces"></a>
109
+
110
+ #### EffectsAndSources <a name="effects-sources"></a>
111
+ ```typescript
112
+ interface EffectsAndSources {
113
+ effects?: Effect<unknown, unknown>[];
114
+ sources?: Observable<Action<unknown>>[] | { [key: string]: Observable<unknown> };
115
+ }
116
+ ```
117
+ | Property | Description |
118
+ | -------- | ----------- |
119
+ | effects (optional) | Array of [Effects](https://github.com/reactables/reactables/tree/main/packages/core#api-effect) to be registered to the Reactable |
120
+ | sources (optional) | Additional [Action](https://github.com/reactables/reactables/tree/main/packages/core#action-) Observables the Reactable is listening to. Can be an array or a dictionary where key is the action type and value is the Observable emitting the payload |
@@ -5,6 +5,9 @@ import { FormControlConfig, FormArrayConfig, FormGroupConfig, AbstractControlCon
5
5
  import { ValidatorFn, ValidatorAsyncFn } from '../Models/Validators';
6
6
  import { Form } from '../Models/Controls';
7
7
  type FbControl<T> = [T, (ValidatorFn | ValidatorFn[])?, (ValidatorAsyncFn | ValidatorAsyncFn[])?];
8
+ export declare const control: <T>(config: FormControlConfig<T> | FbControl<T>) => FormControlConfig<T>;
9
+ export declare const array: (config: FormArrayConfig) => FormArrayConfig;
10
+ export declare const group: (config: FormGroupConfig) => FormGroupConfig;
8
11
  export type RxFormActions = {
9
12
  updateValues: <T>(payload: ControlChange<T>) => void;
10
13
  addControl: (payload: AddControl) => void;
@@ -15,10 +18,5 @@ export type RxFormActions = {
15
18
  markControlAsUntouched: (payload: ControlRef) => void;
16
19
  resetControl: (payload: ControlRef) => void;
17
20
  };
18
- export declare const RxForm: {
19
- group: (config: FormGroupConfig) => FormGroupConfig;
20
- array: (config: FormArrayConfig) => FormArrayConfig;
21
- control: <T>(config: FormControlConfig<T> | FbControl<T>) => FormControlConfig<T>;
22
- build: (config: AbstractControlConfig, options?: EffectsAndSources) => Reactable<Form<unknown>, RxFormActions>;
23
- };
21
+ export declare const build: (config: AbstractControlConfig, options?: EffectsAndSources) => Reactable<Form<unknown>, RxFormActions>;
24
22
  export {};
@@ -1 +1 @@
1
- export { RxForm, RxFormActions } from './RxForm';
1
+ export { build, group, array, control, RxFormActions } from './RxForm';
package/dist/index.js CHANGED
@@ -839,7 +839,7 @@ var mergeRemoveControl = function (state, form, controlRef) {
839
839
  }
840
840
  return __assign(__assign({}, acc), (_a = {}, _a[key] = __assign(__assign(__assign({}, existingControl), baseControl), { errors: errors, valid: selfValid && childrenValid, childrenValid: childrenValid }), _a));
841
841
  }, {});
842
- var descendants = existingBranch.filter(function (control) { return control.controlRef.length < parentRef.length; });
842
+ var descendants = existingBranch.filter(function (control) { return control.controlRef.length > parentRef.length; });
843
843
  var removedControls = __assign({}, state);
844
844
  descendants.forEach(function (control) {
845
845
  delete removedControls[getFormKey(control.controlRef)];
@@ -980,12 +980,6 @@ var build = function (config, options) {
980
980
  state$: rxHub2.state$.pipe(operators.filter(function (form) { return form !== null; })),
981
981
  actions: rxHub1.actions
982
982
  };
983
- };
984
- var RxForm = {
985
- group: group,
986
- array: array,
987
- control: control,
988
- build: build
989
983
  };
990
984
 
991
985
  var getArrayItems = function (controlRef, form) {
@@ -998,6 +992,9 @@ var getArrayItems = function (controlRef, form) {
998
992
  };
999
993
 
1000
994
  exports.ControlModels = Controls;
1001
- exports.RxForm = RxForm;
1002
995
  exports.Validators = index;
996
+ exports.array = array;
997
+ exports.build = build;
998
+ exports.control = control;
1003
999
  exports.getArrayItems = getArrayItems;
1000
+ exports.group = group;
package/package.json CHANGED
@@ -14,12 +14,14 @@
14
14
  "author": "David Lai",
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
- "@reactables/core": "^0.5.1-alpha.0",
18
- "lodash.clonedeep": "^4.5.0",
17
+ "@reactables/core": "^0.5.3-alpha.0",
19
18
  "lodash.isequal": "^4.5.0"
20
19
  },
21
20
  "peerDependencies": {
22
21
  "rxjs": "^6.0.0 || ^7.0.0"
23
22
  },
24
- "version": "0.5.1-alpha.0"
23
+ "devDependencies": {
24
+ "lodash.clonedeep": "^4.5.0"
25
+ },
26
+ "version": "0.5.3-alpha.0"
25
27
  }