Skip to content

Commit

Permalink
refactor: remove payload property from all actions and move corresp…
Browse files Browse the repository at this point in the history
…onding properties into action itself
  • Loading branch information
MrWolfZ committed Apr 17, 2018
1 parent ad7f92d commit 6f955e9
Show file tree
Hide file tree
Showing 27 changed files with 157 additions and 260 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This release requires TypeScript >=2.8.0 for the conditional type support.
* `setValue`: move `state` parameter to first position for uncurried overload ([1a69795](https://github.com/MrWolfZ/ngrx-forms/commit/1a69795))
* `validate`: move `state` parameter to first position for uncurried overload and add rest param overloads
* due to rework of `updateArray`, `updateGroup`, and `updateRecursive` update functions it is now invalid to call any of these functions without parameters (which made no sense anyway) but it is still possible to call the functions with an empty array as parameter (which is useful in dynamic situations)
* remove `payload` property from all actions and move corresponding properties into action itself

#### Features

Expand Down
238 changes: 67 additions & 171 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,308 +5,204 @@ import { KeyValue, NgrxFormControlId } from './state';
export class SetValueAction<TValue> implements Action {
static readonly TYPE = 'ngrx/forms/SET_VALUE';
readonly type = SetValueAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly value: TValue;
};

constructor(
controlId: string,
value: TValue,
) {
this.controlId = controlId;
this.payload = { value };
}
public readonly controlId: NgrxFormControlId,
public readonly value: TValue,
) { }
}

export class SetErrorsAction implements Action {
static readonly TYPE = 'ngrx/forms/SET_ERRORS';
readonly type = SetErrorsAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly errors: ValidationErrors;
};

constructor(
controlId: string,
errors: ValidationErrors,
) {
this.controlId = controlId;
this.payload = {
errors,
};
}
public readonly controlId: NgrxFormControlId,
public readonly errors: ValidationErrors,
) { }
}

export class SetAsyncErrorAction implements Action {
static readonly TYPE = 'ngrx/forms/SET_ASYNC_ERROR';
readonly type = SetAsyncErrorAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly name: string;
readonly value: any;
};

constructor(
controlId: string,
name: string,
value: any,
) {
this.controlId = controlId;
this.payload = {
name,
value,
};
}
public readonly controlId: NgrxFormControlId,
public readonly name: string,
public readonly value: any,
) { }
}

export class ClearAsyncErrorAction implements Action {
static readonly TYPE = 'ngrx/forms/CLEAR_ASYNC_ERROR';
readonly type = ClearAsyncErrorAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly name: string;
};

constructor(
controlId: string,
name: string,
) {
this.controlId = controlId;
this.payload = {
name,
};
}
public readonly controlId: NgrxFormControlId,
public readonly name: string,
) { }
}

export class StartAsyncValidationAction implements Action {
static readonly TYPE = 'ngrx/forms/START_ASYNC_VALIDATION';
readonly type = StartAsyncValidationAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly name: string;
};

constructor(
controlId: string,
name: string,
) {
this.controlId = controlId;
this.payload = {
name,
};
}
public readonly controlId: NgrxFormControlId,
public readonly name: string,
) { }
}

export class MarkAsDirtyAction implements Action {
static readonly TYPE = 'ngrx/forms/MARK_AS_DIRTY';
readonly type = MarkAsDirtyAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class MarkAsPristineAction implements Action {
static readonly TYPE = 'ngrx/forms/MARK_AS_PRISTINE';
readonly type = MarkAsPristineAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class EnableAction implements Action {
static readonly TYPE = 'ngrx/forms/ENABLE';
readonly type = EnableAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class DisableAction implements Action {
static readonly TYPE = 'ngrx/forms/DISABLE';
readonly type = DisableAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class MarkAsTouchedAction implements Action {
static readonly TYPE = 'ngrx/forms/MARK_AS_TOUCHED';
readonly type = MarkAsTouchedAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class MarkAsUntouchedAction implements Action {
static readonly TYPE = 'ngrx/forms/MARK_AS_UNTOUCHED';
readonly type = MarkAsUntouchedAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class FocusAction implements Action {
static readonly TYPE = 'ngrx/forms/FOCUS';
readonly type = FocusAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class UnfocusAction implements Action {
static readonly TYPE = 'ngrx/forms/UNFOCUS';
readonly type = UnfocusAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class MarkAsSubmittedAction implements Action {
static readonly TYPE = 'ngrx/forms/MARK_AS_SUBMITTED';
readonly type = MarkAsSubmittedAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class MarkAsUnsubmittedAction implements Action {
static readonly TYPE = 'ngrx/forms/MARK_AS_UNSUBMITTED';
readonly type = MarkAsUnsubmittedAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export class AddArrayControlAction<TValue> implements Action {
static readonly TYPE = 'ngrx/forms/ADD_ARRAY_CONTROL';
readonly type = AddArrayControlAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly value: TValue;
readonly index: number | undefined;
};

constructor(
controlId: string,
value: TValue,
index?: number,
) {
this.controlId = controlId;
this.payload = { index, value };
}
public readonly controlId: NgrxFormControlId,
public readonly value: TValue,
public readonly index?: number,
) { }
}

export class AddGroupControlAction<TValue extends KeyValue, TControlKey extends keyof TValue = keyof TValue> implements Action {
static readonly TYPE = 'ngrx/forms/ADD_GROUP_CONTROL';
readonly type = AddGroupControlAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly name: keyof TValue;
readonly value: TValue[TControlKey];
};

constructor(
controlId: string,
name: keyof TValue,
value: TValue[TControlKey],
) {
this.controlId = controlId;
this.payload = { name, value };
}
public readonly controlId: NgrxFormControlId,
public readonly name: keyof TValue,
public readonly value: TValue[TControlKey],
) { }
}

export class RemoveArrayControlAction implements Action {
static readonly TYPE = 'ngrx/forms/REMOVE_ARRAY_CONTROL';
readonly type = RemoveArrayControlAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly index: number;
};

constructor(
controlId: string,
index: number,
) {
this.controlId = controlId;
this.payload = { index };
}
public readonly controlId: NgrxFormControlId,
public readonly index: number,
) { }
}

export class RemoveGroupControlAction<TValue> implements Action {
static readonly TYPE = 'ngrx/forms/REMOVE_CONTROL';
readonly type = RemoveGroupControlAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly name: keyof TValue;
};

constructor(
controlId: string,
name: keyof TValue,
) {
this.controlId = controlId;
this.payload = { name };
}
public readonly controlId: NgrxFormControlId,
public readonly name: keyof TValue,
) { }
}

export class SetUserDefinedPropertyAction implements Action {
static readonly TYPE = 'ngrx/forms/SET_USER_DEFINED_PROPERTY';
readonly type = SetUserDefinedPropertyAction.TYPE;
readonly controlId: NgrxFormControlId;

readonly payload: {
readonly name: string;
readonly value: any;
};

constructor(
controlId: string,
name: string,
value: any,
) {
this.controlId = controlId;
this.payload = { name, value };
}
public readonly controlId: NgrxFormControlId,
public readonly name: string,
public readonly value: any,
) { }
}

export class ResetAction implements Action {
static readonly TYPE = 'ngrx/forms/RESET';
readonly type = ResetAction.TYPE;
readonly controlId: NgrxFormControlId;

constructor(controlId: string) {
this.controlId = controlId;
}
constructor(
public readonly controlId: NgrxFormControlId,
) { }
}

export type Actions<TValue> =
Expand Down
Loading

0 comments on commit 6f955e9

Please sign in to comment.