-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extend and use InputBag for State, QueryParams, PathParams
- Loading branch information
1 parent
8a4687f
commit 95a0e5d
Showing
17 changed files
with
313 additions
and
427 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,32 +1,62 @@ | ||
|
||
import { Dict } from '../index.js' | ||
export interface InputBag<Properties = Record<string, any>> { | ||
/** | ||
* Returns the properties object of this input bag. | ||
*/ | ||
toJSON (): Properties | ||
|
||
export interface InputBag<T> { | ||
/** | ||
* Returns an object with all `keys` existing in the input bag. | ||
*/ | ||
all(...keys: Array<keyof Dict<T>> | Array<Array<keyof Dict<T>>>): Dict<T> | ||
all (): Properties | ||
all <R extends Record<string, any>>(): R | ||
all<Key extends keyof Properties> (...keys: Key[] | Key[][]): Partial<Record<keyof Properties, Properties[keyof Properties]>> | ||
|
||
/** | ||
* Returns the input value for the given `name`. This method returns | ||
* `undefined` if the input bag doesn’t contain the given `name`. | ||
*/ | ||
get<Value = any, Key extends keyof Dict<T> = string> (name: Key): Value | Dict<T>[Key] | undefined | ||
get<Value = any, Key extends keyof Dict<T> = string> (name: Key, defaultValue: Value): Value | Dict<T>[Key] | ||
get<Key extends keyof Properties> (name: Key): Properties[Key] | ||
get<Value = any, Key extends keyof Properties = any> (name: Key, defaultValue: Value): Properties[Key] | Value | ||
|
||
/** | ||
* Set an input for the given `name` and assign the `value`. This | ||
* overrides a possibly existing input with the same `name`. | ||
*/ | ||
set (name: string, value: any): this | ||
set<Key extends keyof Properties> (name: Key, value: Properties[Key]): this | ||
set (values: Partial<Properties>): this | ||
|
||
/** | ||
* Merge the given `data` object with the existing input bag. | ||
*/ | ||
merge (data: Partial<Properties>): this | ||
|
||
/** | ||
* Determine whether the input bag contains an item for the given `key`, | ||
* independently from the key’s assigned value. If you need to ensure | ||
* that a value is not `undefined`, use the related `has` method. | ||
*/ | ||
exists<Key extends keyof Properties> (key: Key): boolean | ||
|
||
/** | ||
* Determine whether an item with the given `key` exists in the input bag | ||
* and the assigned value is not `undefined`. The assigned value could | ||
* also be `null`. Empty states should explcitely use `undefinied`. | ||
*/ | ||
has<Key extends keyof Properties> (key: Key): boolean | ||
|
||
/** | ||
* Determine whether the input bag is missing a value for the given `key`. | ||
*/ | ||
isMissing<Key extends keyof Properties> (key: Key): boolean | ||
|
||
/** | ||
* Removes the input with the given `name`. | ||
* Remove the input bag item for the given `key`. | ||
*/ | ||
remove(name: keyof Dict<T>): this | ||
remove<Key extends keyof Properties> (key: Key): this | ||
|
||
/** | ||
* Determine whether the input for the given `name` exists. | ||
* Removes all data from the input bag. | ||
*/ | ||
has(name: keyof Dict<T>): boolean | ||
clear(): this | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.