Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(state): add void transform to actions #1596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions libs/state/actions/src/lib/transforms.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @description
* This transform is a side effecting operation applying `preventDefault` to a passed Event
* @param e
*/
export function preventDefault(e: Event): Event {
e.preventDefault();
Expand All @@ -11,7 +10,6 @@ export function preventDefault(e: Event): Event {
/**
* @description
* This transform is a side effecting operation applying `stopPropagation` to a passed Event
* @param e
*/
export function stopPropagation(e: Event): Event {
e.stopPropagation();
Expand All @@ -21,24 +19,30 @@ export function stopPropagation(e: Event): Event {
/**
* @description
* This transform is a side effecting operation applying `preventDefault` and `stopPropagation` to a passed Event
* @param e
*/
export function preventDefaultStopPropagation(e: Event): Event {
e.stopPropagation();
e.preventDefault();
return e;
}


/**
* @description
* This transform is helps to pluck values from DOM `Event` or forward the value directly.
* @param e
* This transform helps to pluck values from DOM `Event` or forward the value directly.
*/
export function eventValue<T = string>(e: Event | T): T {
// Consider https://stackoverflow.com/questions/1458894/how-to-determine-if-javascript-object-is-an-event
if((e as unknown as {target: {value: T}})?.target) {
return (e as unknown as {target: {value: T}})?.target?.value;
if ((e as unknown as { target: { value: T } })?.target) {
return (e as unknown as { target: { value: T } })?.target?.value;
}
return e as T;
}

/**
* @description
* This transform helps to void all arguments.
*/
export function toVoid(_?: unknown): void {
_;
return void 0;
}