-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
addGroupControl
: move state
parameter to first position for…
… uncurried overload
- Loading branch information
Showing
5 changed files
with
17 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import { AddGroupControlAction } from '../actions'; | ||
import { formGroupReducer } from '../group/reducer'; | ||
import { FormGroupState, KeyValue } from '../state'; | ||
import { FormGroupState, isGroupState, KeyValue } from '../state'; | ||
import { ensureState } from './util'; | ||
|
||
/** | ||
* This update function takes a name and a value and returns a projection function | ||
* that adds a child control with the given name and value to a form group state. | ||
*/ | ||
export function addGroupControl<TValue extends KeyValue, TControlKey extends keyof TValue = string>( | ||
name: keyof TValue, | ||
export function addGroupControl<TValue extends KeyValue, TControlKey extends keyof TValue = keyof TValue>( | ||
name: TControlKey, | ||
value: TValue[TControlKey], | ||
): (state: FormGroupState<TValue>) => FormGroupState<TValue>; | ||
|
||
/** | ||
* This update function takes a name, a value, and a form group state and adds a child | ||
* control with the given name and value to the form group state. | ||
*/ | ||
export function addGroupControl<TValue extends KeyValue, TControlKey extends keyof TValue = string>( | ||
name: keyof TValue, | ||
value: TValue[TControlKey], | ||
export function addGroupControl<TValue extends KeyValue, TControlKey extends keyof TValue = keyof TValue>( | ||
state: FormGroupState<TValue>, | ||
name: TControlKey, | ||
value: TValue[TControlKey], | ||
): FormGroupState<TValue>; | ||
|
||
export function addGroupControl<TValue extends KeyValue, TControlKey extends keyof TValue = string>( | ||
name: keyof TValue, | ||
value: TValue[TControlKey], | ||
state?: FormGroupState<TValue>, | ||
export function addGroupControl<TValue extends KeyValue, TControlKey extends keyof TValue = keyof TValue>( | ||
nameOrState: TControlKey | FormGroupState<TValue>, | ||
valueOrName: TValue[TControlKey] | TControlKey, | ||
value?: TValue[TControlKey], | ||
) { | ||
if (!!state) { | ||
return formGroupReducer(state, new AddGroupControlAction<TValue, TControlKey>(state.id, name, value)); | ||
if (isGroupState(nameOrState)) { | ||
return formGroupReducer(nameOrState, new AddGroupControlAction<TValue, TControlKey>(nameOrState.id, valueOrName as TControlKey, value!)); | ||
} | ||
|
||
return (s: FormGroupState<TValue>) => addGroupControl(name, value, ensureState(s)); | ||
return (s: FormGroupState<TValue>) => addGroupControl(ensureState(s), nameOrState as TControlKey, valueOrName as TValue[TControlKey]); | ||
} |