-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
css fixes and the disabled submit button inherits the default enable …
…style
- Loading branch information
1 parent
81ae34e
commit 042483a
Showing
6 changed files
with
59 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
export class ObjectUtils { | ||
public static setPropertyValueIfDoesNotExist<T>(object: T, keys: string[], value: unknown) { | ||
const propertyKey = keys[0] as keyof T; | ||
if (keys.length === 1) { | ||
public static setPropertyValueIfDoesNotExist<T>(object: T, nestedKeys: string[], value: unknown) { | ||
const propertyKey = nestedKeys[0] as keyof T; | ||
if (nestedKeys.length === 1) { | ||
object[propertyKey] ??= value as T[keyof T]; | ||
} else { | ||
object[propertyKey] ??= {} as T[keyof T]; | ||
keys.shift(); | ||
ObjectUtils.setPropertyValueIfDoesNotExist(object[propertyKey], keys, value); | ||
nestedKeys.shift(); | ||
ObjectUtils.setPropertyValueIfDoesNotExist(object[propertyKey], nestedKeys, value); | ||
} | ||
} | ||
|
||
public static setPropertyValue<T>(object: T, nestedKeys: string[], value: unknown) { | ||
const propertyKey = nestedKeys[0] as keyof T; | ||
if (nestedKeys.length === 1) { | ||
object[propertyKey] = value as T[keyof T]; | ||
} else { | ||
object[propertyKey] ??= {} as T[keyof T]; | ||
nestedKeys.shift(); | ||
ObjectUtils.setPropertyValue(object[propertyKey], nestedKeys, value); | ||
} | ||
} | ||
|
||
public static getObjectValue<T>(object: T, nestedKeys: string[]): object | undefined { | ||
const propertyKey = nestedKeys[0] as keyof T; | ||
const currentValue = object[propertyKey]; | ||
if (currentValue === undefined || nestedKeys.length === 1) { | ||
return currentValue as object | undefined; | ||
} | ||
return ObjectUtils.getObjectValue(currentValue, nestedKeys.slice(1)); | ||
} | ||
|
||
public static overwritePropertyObjectFromAnother<T>(target: T, source: T, nestedKeys: string[]) { | ||
const sourceObject = ObjectUtils.getObjectValue(source, nestedKeys); | ||
if (sourceObject) { | ||
const newObject = {...sourceObject, ...(ObjectUtils.getObjectValue(target, nestedKeys) || {})}; | ||
ObjectUtils.setPropertyValue(target, nestedKeys, newObject); | ||
} | ||
} | ||
} |
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