@reactables/forms 1.3.0-alpha.2 → 1.3.0-beta.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.
@@ -28,7 +28,7 @@ export interface FormReducers {
28
28
  markControlAsUntouched: <T>(state: BaseFormState<T>, payload: ControlRef) => BaseFormState<T>;
29
29
  resetControl: <T>(state: BaseFormState<T>, payload: ControlRef) => BaseFormState<T>;
30
30
  }
31
- export type CustomReducerFunc = (reducers: FormReducers, state: BaseFormState<unknown>, action: Action<unknown>) => BaseFormState<unknown>;
31
+ export type CustomReducerFunc<T = unknown> = (reducers: FormReducers, state: BaseFormState<unknown>, action: Action<T>) => BaseFormState<unknown>;
32
32
  export type CustomReducer = CustomReducerFunc | {
33
33
  reducer: CustomReducerFunc;
34
34
  effects?: Effect<unknown, unknown>[] | ((payload?: unknown) => ScopedEffects<unknown>);
@@ -38,8 +38,13 @@ export type CustomReducers<T> = {
38
38
  [key: string]: CustomReducer;
39
39
  })]: CustomReducer;
40
40
  };
41
- export interface RxFormOptions extends EffectsAndSources {
42
- reducers?: CustomReducers<unknown>;
41
+ export type ActionCreatorTypeFromCustomReducer<T> = T extends (reducers: FormReducers, state: BaseFormState<unknown>) => BaseFormState<unknown> ? () => void : T extends CustomReducerFunc<infer P> ? (payload: P) => void : T extends {
42
+ reducer: (reducers: FormReducers, state: BaseFormState<unknown>) => BaseFormState<unknown>;
43
+ } ? () => void : T extends {
44
+ reducer: CustomReducerFunc<infer P>;
45
+ } ? (payload: P) => void : never;
46
+ export interface RxFormOptions<T extends CustomReducers<unknown>> extends EffectsAndSources {
47
+ reducers?: T;
43
48
  providers?: RxFormProviders;
44
49
  name?: string;
45
50
  debug?: boolean;
@@ -57,6 +62,38 @@ export interface RxFormProviders {
57
62
  [key: string]: ValidatorAsyncFn;
58
63
  };
59
64
  }
60
- export declare const build: <Value, Actions = RxFormActions>(config: AbstractControlConfig, options?: RxFormOptions) => Reactable<Form<Value>, Actions>;
61
- export declare const load: <Value, Actions = RxFormActions>(state: Form<Value>, options?: RxFormOptions) => Reactable<Form<Value>, Actions>;
65
+ export declare const build: <T extends CustomReducers<unknown>>(config: AbstractControlConfig, options?: RxFormOptions<T>) => Reactable<Form<unknown>, { [K in keyof T]: ActionCreatorTypeFromCustomReducer<T[K]>; } & {
66
+ updateValues: <T_1>(payload: UpdateValuesPayload<T_1>) => void;
67
+ addControl: (payload: AddControlPayload) => void;
68
+ pushControl: (payload: PushControlPayload) => void;
69
+ removeControl: (payload: ControlRef) => void;
70
+ markControlAsPristine: (payload: ControlRef) => void;
71
+ markControlAsTouched: (payload: MarkTouchedPayload) => void;
72
+ markControlAsUntouched: (payload: ControlRef) => void;
73
+ resetControl: (payload: ControlRef) => void;
74
+ } & ActionMap, ActionTypes<T>>;
75
+ export declare const load: <Value, T extends CustomReducers<unknown>>(state: Form<Value>, options?: RxFormOptions<T>) => Reactable<Form<unknown>, { [K in keyof T]: ActionCreatorTypeFromCustomReducer<T[K]>; } & {
76
+ updateValues: <T_1>(payload: UpdateValuesPayload<T_1>) => void;
77
+ addControl: (payload: AddControlPayload) => void;
78
+ pushControl: (payload: PushControlPayload) => void;
79
+ removeControl: (payload: ControlRef) => void;
80
+ markControlAsPristine: (payload: ControlRef) => void;
81
+ markControlAsTouched: (payload: MarkTouchedPayload) => void;
82
+ markControlAsUntouched: (payload: ControlRef) => void;
83
+ resetControl: (payload: ControlRef) => void;
84
+ } & ActionMap, ActionTypes<T>>;
85
+ type CustomReducerActionTypes<T extends CustomReducers<unknown>> = {
86
+ [K in keyof T as `${K & string}`]: `${K & string}`;
87
+ };
88
+ type FormActionTypes = {
89
+ updateValues: 'updateValues';
90
+ addControl: 'addControl';
91
+ pushControl: 'pushControl';
92
+ removeControl: 'removeControl';
93
+ markControlAsPristine: 'markControlAsPristine';
94
+ markControlAsTouched: 'markControlAsTouched';
95
+ markControlAsUntouched: 'markControlAsUntouched';
96
+ resetControl: 'resetControl';
97
+ };
98
+ type ActionTypes<T extends CustomReducers<unknown>> = CustomReducerActionTypes<T> & FormActionTypes;
62
99
  export {};
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js CHANGED
@@ -1152,17 +1152,19 @@ var createReactable = function (initialBaseState, options, initialFormState) {
1152
1152
  effects: effects
1153
1153
  }, _b));
1154
1154
  }, {});
1155
- var _d = core.RxBuilder(__assign({ initialState: initialBaseState, name: "Stage 1 ".concat(name ? name : 'rxForm'), debug: debug, reducers: __assign({ updateValues: function (state, action, mergeChanges) {
1156
- return updateValues(state, action, providers, mergeChanges);
1157
- }, removeControl: function (state, action, mergeChanges) {
1158
- return removeControl(state, action, providers, mergeChanges);
1159
- }, addControl: function (state, action, mergeChanges) {
1160
- return addControl(state, action, providers, mergeChanges);
1161
- }, pushControl: function (state, action, mergeChanges) {
1162
- return pushControl(state, action, providers, mergeChanges);
1163
- }, resetControl: function (state, action, mergeChanges) {
1164
- return resetControl(state, action, providers, mergeChanges);
1165
- }, markControlAsPristine: markControlAsPristine, markControlAsTouched: markControlAsTouched, markControlAsUntouched: markControlAsUntouched }, customReducers) }, otherOptions)), hub1State$ = _d[0], hub1Actions = _d[1], hub1Actions$ = _d[2];
1155
+ var _d = core.RxBuilder(__assign({ initialState: initialBaseState, name: "Stage 1 ".concat(name ? name : 'rxForm'), debug: debug, reducers: __assign({ updateValues: function (state, action) {
1156
+ return updateValues(state, action, providers);
1157
+ }, removeControl: function (state, action) { return removeControl(state, action, providers); }, addControl: function (state, action) {
1158
+ return addControl(state, action, providers);
1159
+ }, pushControl: function (state, action) {
1160
+ return pushControl(state, action, providers);
1161
+ }, resetControl: function (state, action) { return resetControl(state, action, providers); }, markControlAsPristine: function (state, action) {
1162
+ return markControlAsPristine(state, action);
1163
+ }, markControlAsTouched: function (state, action) {
1164
+ return markControlAsTouched(state, action);
1165
+ }, markControlAsUntouched: function (state, action) {
1166
+ return markControlAsUntouched(state, action);
1167
+ } }, customReducers) }, otherOptions)), hub1State$ = _d[0], hub1Actions = _d[1], hub1Actions$ = _d[2];
1166
1168
  var state$ = core.RxBuilder({
1167
1169
  sources: [buildHub2Source(hub1State$, initialBaseState).pipe(operators.skip(initialFormState ? 1 : 0))],
1168
1170
  initialState: initialFormState || null,
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "author": "David Lai",
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
- "@reactables/core": "^1.3.0-alpha.2",
17
+ "@reactables/core": "^1.3.0-beta.0",
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": "1.3.0-alpha.2"
26
+ "version": "1.3.0-beta.0"
27
27
  }