Skip to content

Commit

Permalink
feat: removeArrayControl: move state parameter to first position …
Browse files Browse the repository at this point in the history
…for uncurried overload
  • Loading branch information
MrWolfZ committed Apr 15, 2018
1 parent 2ab675a commit 5a5aa17
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This release requires TypeScript >=2.8.0 for the conditional type support.
* remove `cast` utility function since it is obsolete due to proper control type inference
* change order of parameters for many update functions to more be consistent
* `addArrayControl`: move `state` parameter to first position for uncurried overload ([ab094b8](https://github.com/MrWolfZ/ngrx-forms/commit/ab094b8))
* `removeArrayControl`: move `state` parameter to first position for uncurried overload
* `addGroupControl`: move `state` parameter to first position for uncurried overload ([b6da5ee](https://github.com/MrWolfZ/ngrx-forms/commit/b6da5ee))

#### Features
Expand Down
2 changes: 1 addition & 1 deletion src/update-function/remove-array-control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe(removeArrayControl.name, () => {
});

it('should call reducer for arrays uncurried', () => {
const resultState = removeArrayControl<string>(0, INITIAL_ARRAY_STATE);
const resultState = removeArrayControl<string>(INITIAL_ARRAY_STATE, 0);
expect(resultState).not.toBe(INITIAL_ARRAY_STATE);
});

Expand Down
14 changes: 7 additions & 7 deletions src/update-function/remove-array-control.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RemoveArrayControlAction } from '../actions';
import { formArrayReducer } from '../array/reducer';
import { FormArrayState } from '../state';
import { FormArrayState, isArrayState } from '../state';
import { ensureState } from './util';

/**
Expand All @@ -10,15 +10,15 @@ import { ensureState } from './util';
export function removeArrayControl<TValue>(index: number): (state: FormArrayState<TValue>) => FormArrayState<TValue>;

/**
* This update function takes an index and an array form state and removes the
* This update function takes an array form state and an index and removes the
* child control at the given index from the state.
*/
export function removeArrayControl<TValue>(index: number, state: FormArrayState<TValue>): FormArrayState<TValue>;
export function removeArrayControl<TValue>(state: FormArrayState<TValue>, index: number): FormArrayState<TValue>;

export function removeArrayControl<TValue>(index: number, state?: FormArrayState<TValue>) {
if (!!state) {
return formArrayReducer(state, new RemoveArrayControlAction(state.id, index));
export function removeArrayControl<TValue>(indexOrState: number | FormArrayState<TValue>, index?: number) {
if (isArrayState(indexOrState)) {
return formArrayReducer(indexOrState, new RemoveArrayControlAction(indexOrState.id, index!));
}

return (s: FormArrayState<TValue>) => removeArrayControl(index, ensureState(s));
return (s: FormArrayState<TValue>) => removeArrayControl(ensureState(s), indexOrState as number);
}

0 comments on commit 5a5aa17

Please sign in to comment.