realue
- ErrorMutator
- ErrorReport
- ErrorReportArray
- ErrorReportChildren
- ErrorReportObject
- ErrorReportValue
- ErrorTransformer
- Fetch
- ItemId
- ItemProps
- Name
- NameItem
- NameProperty
- NeverNevoProps
- NevoName
- NevoProps
- NevoPropsAdapted
- OptionPropsAdapted
- PromiseState
- Property
- UseTransformOptions
- ValueMutator
- ValueRemover
- ValueTransformer
- ValueValidator
- adapt
- capitalize
- changeError
- childrenError
- disable
- globalError
- isArray
- isEqualError
- itemIdDefault
- normalize
- normalizeError
- useAbortController
- useArray
- useChange
- useDebounce
- useFetch
- useInput
- useLog
- useObject
- useOption
- usePrevious
- usePreviousArgument
- usePreviousArgumentList
- usePromise
- useRemove
- useResilient
- useSyncedProps
- useSyncedSignal
- useSyncedState
- useTransform
- useValidator
- withoutNevoProps
Ƭ ErrorMutator<E
>: (error
: E
| undefined
, name
: Name
) => void
Function that mutates an error
. Used as the signature for the onChangeError
callback of the NEVO pattern.
Name | Type |
---|---|
E |
extends ErrorReport <any > |
▸ (error
, name
): void
Name | Type |
---|---|
error |
E | undefined |
name |
Name |
void
Ƭ ErrorReport<T
, U
>: [U
] extends [unknown
[]] ? ErrorReportArray
<U
> : [U
] extends [object
] ? ErrorReportObject
<U
> : ErrorReportValue
Name | Type |
---|---|
T |
T |
U |
NonNullable <T > |
Ƭ ErrorReportArray<T
>: Partial
<{ [K in keyof T as number]: ErrorReport<T[K]> }> & { ?
: ErrorReportValue
} | ErrorReportValue
Name | Type |
---|---|
T |
extends unknown [] |
lib/types/ErrorReportArray.ts:4
Ƭ ErrorReportChildren<T
>: Partial
<{ [K in keyof T]: ErrorReport<T[K]> }>
Name | Type |
---|---|
T |
extends unknown [] | object |
lib/types/ErrorReportChildren.ts:3
Ƭ ErrorReportObject<T
>: Partial
<{ [K in keyof T]: ErrorReport<T[K]> }> & { ?
: ErrorReportValue
} | ErrorReportValue
Name | Type |
---|---|
T |
extends object |
lib/types/ErrorReportObject.ts:4
Ƭ ErrorReportValue: string
[]
lib/types/ErrorReportValue.ts:1
Ƭ ErrorTransformer<T
, U
>: (error
: ErrorReport
<T
> | undefined
) => ErrorReport
<U
> | undefined
Name |
---|
T |
U |
▸ (error
): ErrorReport
<U
> | undefined
Name | Type |
---|---|
error |
ErrorReport <T > | undefined |
ErrorReport
<U
> | undefined
lib/types/ErrorTransformer.ts:3
Ƭ Fetch<T
, R
>: (request
: R
, abortController?
: AbortController
) => Promise
<T
>
Name |
---|
T |
R |
▸ (request
, abortController?
): Promise
<T
>
Name | Type |
---|---|
request |
R |
abortController? |
AbortController |
Promise
<T
>
Ƭ ItemId<T
>: (index
: number
, item
: T
) => string
Name |
---|
T |
▸ (index
, item
): string
Name | Type |
---|---|
index |
number |
item |
T |
string
Ƭ ItemProps<T
, E
>: NevoProps
<T
, E
> & { id
: string
; key
: string
}
Name | Type |
---|---|
T |
T |
E |
extends ErrorReport <any > = ErrorReport <T > |
Ƭ Name: NameProperty
| NameItem
Ƭ NameItem: `${number}`
Ƭ NameProperty: string
Ƭ NeverNevoProps: Object
Excludes the props following the NEVO pattern. Useful for creating discriminated union types that enable component uses that do not necessitate the NEVO pattern.
Name | Type |
---|---|
error? |
never |
name? |
never |
onChange? |
never |
onChangeError? |
never |
value? |
never |
Ƭ NevoName: keyof NevoProps
<any
>
Ƭ NevoProps<T
, E
>: Object
Set of properties that define the NEVO pattern:
name
: The name used to identify the entity represented by thevalue
.error
: An error object describing issues to be shown.value
: The value to be handled by a component.onChange
: The callback the component uses to notify the parent component about changes of thevalue
.onChangeError
: The callback the component uses to notify the parent component about changes of theerror
.
Name | Type |
---|---|
T |
T |
E |
extends ErrorReport <any > = ErrorReport <T > |
Name | Type | Description |
---|---|---|
error? |
E |
An error object describing issues to be shown. |
name |
Name |
The name used to identify the entity represented by the value . |
onChange? |
ValueMutator <NoInfer <T >> |
The callback the component uses to notify the parent component about changes of the value . |
onChangeError? |
ErrorMutator <NoInfer <E >> |
The callback the component uses to notify the parent component about changes of the error . |
value |
T |
The value to be handled by a component. |
Ƭ NevoPropsAdapted<T
, K
, E
>: Property
<`${K}Name`, Name
> & Property
<`${K}Error`, E
> & Property
<K
, T
> & Property
<`onChange${Capitalize<K>}`, ValueMutator
<T
>> & Property
<`onChange${Capitalize<K>}Error`, ErrorMutator
<E
>>
Name | Type |
---|---|
T |
T |
K |
extends string |
E |
extends ErrorReport <any > = ErrorReport <T > |
lib/types/NevoPropsAdapted.ts:7
Ƭ OptionPropsAdapted<T
, K
>: Property
<K
, T
> & Property
<`onChange${Capitalize<K>}`, ValueMutator
<T
>>
Name | Type |
---|---|
T |
T |
K |
extends string |
lib/types/OptionPropsAdapted.ts:4
Ƭ PromiseState<T
>: Object
Name |
---|
T |
Name | Type |
---|---|
promise? |
Promise <T | undefined > |
reason? |
unknown |
status |
PromiseStatus |
value? |
T |
Ƭ Property<K
, V
>: { [P in K]: { [Q in P]: V } }[K
]
Returns an object type with a single property.
Name | Type |
---|---|
K |
extends PropertyKey |
V |
V |
Ƭ UseTransformOptions<T
, U
>: { onChange
: ValueTransformer
<U
, T
> ; value
: ValueTransformer
<T
, U
> } & { error
: ErrorTransformer
<T
, U
> ; onChangeError
: ErrorTransformer
<U
, T
> } | { error?
: never
; onChangeError?
: never
}
Options for useTransform
.
Name |
---|
T |
U |
lib/types/UseTransformOptions.ts:7
Ƭ ValueMutator<T
>: (value
: T
, name
: Name
) => void
Function that changes a value
. Used as the signature for the onChange
callback of the NEVO pattern.
Name |
---|
T |
▸ (value
, name
): void
Name | Type |
---|---|
value |
T |
name |
Name |
void
Ƭ ValueRemover: (name
: NameItem
) => void
Function that removes an array item at index name
.
▸ (name
): void
Name | Type |
---|---|
name |
NameItem |
void
Ƭ ValueTransformer<T
, U
>: (value
: T
) => U
Name |
---|
T |
U |
▸ (value
): U
Name | Type |
---|---|
value |
T |
U
lib/types/ValueTransformer.ts:1
Ƭ ValueValidator<T
, E
>: (value
: T
, name
: Name
, error
: E
| undefined
) => Promise
<E
| undefined
> | E
| undefined
Function that valides a value
with a given name
and returns a promise that resolves to an error, if any.
Name | Type |
---|---|
T |
T |
E |
extends ErrorReport <any > = ErrorReport <T > |
▸ (value
, name
, error
): Promise
<E
| undefined
> | E
| undefined
Name | Type |
---|---|
value |
T |
name |
Name |
error |
E | undefined |
Promise
<E
| undefined
> | E
| undefined
▸ adapt<T
, K
>(props
, propertyName
): NevoPropsAdapted
<T
, K
>
Adapts the provided props
to the specified propertyName
.
Name | Type |
---|---|
T |
T |
K |
extends string |
Name | Type | Description |
---|---|---|
props |
NevoProps <T > |
Properties according to the Nevo pattern. |
propertyName |
K |
Name of the value property. |
NevoPropsAdapted
<T
, K
>
Example
<SomeComponent {...property("value")} {...adapt(property("option"), "option")} />
▸ capitalize<T
>(value
): Capitalize
<T
>
Name | Type |
---|---|
T |
extends string |
Name | Type |
---|---|
value |
T |
Capitalize
<T
>
▸ changeError<T
, E
>(error
, itemName
, itemError
): E
| undefined
Name | Type |
---|---|
T |
extends undefined | object |
E |
extends ErrorReportObject <NonNullable <T >> |
Name | Type |
---|---|
error |
undefined | E |
itemName |
"" | keyof E |
itemError |
undefined | ErrorReportValue | E [keyof E ] |
E
| undefined
▸ changeError<T
, E
>(error
, itemName
, itemError
): E
| undefined
Name | Type |
---|---|
T |
extends undefined | any [] |
E |
extends ErrorReportArray <NonNullable <T >> |
Name | Type |
---|---|
error |
undefined | E |
itemName |
number | "" |
itemError |
undefined | ErrorReportValue | E [number ] |
E
| undefined
▸ childrenError<T
>(error?
): Partial
<{ [K in keyof T as number]: ErrorReport<T[K]> }> | undefined
Name | Type |
---|---|
T |
extends unknown [] |
Name | Type |
---|---|
error? |
ErrorReportArray <T > |
Partial
<{ [K in keyof T as number]: ErrorReport<T[K]> }> | undefined
▸ childrenError<T
>(error?
): Partial
<{ [K in keyof T]: ErrorReport<T[K]> }> | undefined
Name | Type |
---|---|
T |
extends object |
Name | Type |
---|---|
error? |
ErrorReportObject <T > |
Partial
<{ [K in keyof T]: ErrorReport<T[K]> }> | undefined
▸ disable(condition?
): null
| { onChange
: undefined
= undefined; onChangeError
: undefined
= undefined }
Returns the props with onChange
and onChangeError
the condition
is truthy. Useful for disabling edits in some cases.
Name | Type | Description |
---|---|---|
condition? |
boolean | PromiseState <unknown > |
Boolean that disables changes if true, or PromiseState |
null
| { onChange
: undefined
= undefined; onChangeError
: undefined
= undefined }
The props necessary to disable changes or not.
Example
<>
<Component {...props} {...disable(promiseState.status === "pending")} />
<Component {...props} {...disable(promiseState)} />
</>
▸ globalError<T
>(error?
): ErrorReportValue
| undefined
Name |
---|
T |
Name | Type |
---|---|
error? |
ErrorReport <T > |
ErrorReportValue
| undefined
▸ isArray(arg
): arg is any[]
Name | Type |
---|---|
arg |
any |
arg is any[]
▸ isEqualError<T
>(a?
, b?
): boolean
Returns true
if the two provided error values have the same errors messages.
Name |
---|
T |
Name | Type | Description |
---|---|---|
a? |
ErrorReport <T > |
Error value |
b? |
ErrorReport <T > |
Error value |
boolean
true
if the two provided error values are equal.
▸ itemIdDefault<T
>(index
, item
): string
Default function used by useArray
for defining the unique identifier of an item.
Name |
---|
T |
Name | Type | Description |
---|---|---|
index |
number |
Array index of the item. |
item |
T |
Value of the item. |
string
A unique identifier string for this item.
▸ normalize<T
, K
>(props
, propertyName
): NevoProps
<T
>
Normalizes the provided props
from the provided propertyName
.
Name | Type |
---|---|
T |
T |
K |
extends string |
Name | Type | Description |
---|---|---|
props |
NevoPropsAdapted <T , K > |
Propertyes according to the Nevo pattern. |
propertyName |
K |
Name of the value property. |
NevoProps
<T
>
Example
<SomeComponent {...normalize("option", props)} />
▸ normalizeError<T
>(error
): undefined
| ErrorReport
<T
>
Name |
---|
T |
Name | Type |
---|---|
error |
undefined | ErrorReport <T > |
undefined
| ErrorReport
<T
>
▸ useAbortController(): () => AbortController
Creates an on-demand AbortController
that triggers when the provided inputs
change (at least when the element unmounts).
fn
Callback that returns a new AbortController
.
▸ (): AbortController
AbortController
lib/hooks/useAbortController.ts:13
▸ useArray<A
, G
, T
, E
>(props
, itemId?
): ItemCallable
<T
, E
>
Takes an array and returns a function that generates the required props for handling an array item value.
That function also contains three callables: loop
, add
, and remove
.
Name | Type |
---|---|
A |
extends undefined | any [] |
G |
extends ErrorReportArray <NonNullable <A >> |
T |
A extends H [] ? H : never |
E |
extends ErrorReportArray <any > = ErrorReport <T > |
Name | Type | Default value | Description |
---|---|---|---|
props |
NevoProps <A , G > |
undefined |
The props holding the array value . |
itemId |
ItemId <T > |
itemIdDefault |
An optional function that returns a unique identifier for a given array item . |
ItemCallable
<T
, E
>
The item
function that returns the props for a specific item index
.
▸ useChange<T
>(props
, transformValue?
): undefined
| () => void
Name |
---|
T |
Name | Type | Default value |
---|---|---|
props |
Pick <NevoProps <T >, "name" | "value" | "onChange" > |
undefined |
transformValue |
(value : T ) => T |
identity |
undefined
| () => void
▸ useDebounce<T
>(props
, delay?
): Object
Name |
---|
T |
Name | Type |
---|---|
props |
Pick <NevoProps <T >, "name" | "value" | "onChange" > |
delay? |
number |
Object
Name | Type | Description |
---|---|---|
name |
string |
The name used to identify the entity represented by the value . |
onChange |
undefined | ValueMutator <T > |
- |
value |
T |
- |
▸ useFetch<T
, Q
>(fetch?
, props?
): [PromiseState
<T
>, (request?
: Q
) => void
]
Handles a single concurrent request and updates the value
or error
through the provided onChange
and onChangeError
callbacks. The callback in the returned tuple enables issuing new request. If the callback is called with no argument, it resets the request back to the idle
state, aborting the prior request if it was not fulfilled.
Name | Type |
---|---|
T |
extends object |
Q |
extends unknown |
Name | Type | Description |
---|---|---|
fetch |
Fetch <T , Q > |
An optional request fetcher that defaults to using the standard fetch method. |
props? |
NevoProps <T > |
The optional onChange and onChangeError callbacks to notify about the resulting value or error , and the name . |
[PromiseState
<T
>, (request?
: Q
) => void
]
A tuple consisting of the current request state and a callback to issue a new request.
▸ useInput<T
, E
>(props
, extractValue
): undefined
| (event
: TargetedEvent
<HTMLInputElement
, Event
>) => void
Name | Type |
---|---|
T |
T |
E |
extends ErrorReportArray <any > |
Name | Type |
---|---|
props |
NevoProps <T , E > |
extractValue |
(element : HTMLInputElement ) => T |
undefined
| (event
: TargetedEvent
<HTMLInputElement
, Event
>) => void
▸ useLog(title
, props
): void
Name | Type |
---|---|
title |
string |
props |
Props |
void
▸ useObject<T
, E
>(props
): PropertyCallable
<NonNullable
<T
>>
Takes an object and returns a function that generates the required props for handling an object property value.
Name | Type |
---|---|
T |
extends undefined | object |
E |
extends ErrorReportObject <NonNullable <T >> = ErrorReportObject <NonNullable <T >> |
Name | Type | Description |
---|---|---|
props |
NevoProps <T , E > |
The props holding the object value . |
PropertyCallable
<NonNullable
<T
>>
The property
function that returns the props for a specific property name
.
▸ useOption<T
, K
>(props
, propertyName
): OptionPropsAdapted
<T
, K
>
Name | Type |
---|---|
T |
T |
K |
extends string |
Name | Type | Description |
---|---|---|
props |
NevoProps <T > |
Properties according to the Nevo pattern. |
propertyName |
K |
OptionPropsAdapted
<T
, K
>
▸ usePrevious<T
>(value
): undefined
| T
Returns the previous value.
Name |
---|
T |
Name | Type | Description |
---|---|---|
value |
T |
Value from which to get the previous value from. |
undefined
| T
The previous value.
▸ usePreviousArgument<T
, U
>(callback
): (value
: T
) => U
Returns a unary callback that calls the provided callback
with both the current and previous value of the argument. Can be used for computations that require working with the previous value.
Name |
---|
T |
U |
Name | Type | Description |
---|---|---|
callback |
(value : T , previousValue : undefined | T ) => U |
The callback that receives both the current and previous value of the argument. |
fn
A callback that receives the argument value and returns the result of the provided callback
.
▸ (value
): U
Name | Type |
---|---|
value |
T |
U
lib/hooks/usePreviousArgument.ts:9
▸ usePreviousArgumentList<T
, U
>(callback
): (...current
: T
) => U
Returns a callback that calls the provided callback
with both the current and previous value of the argument list.
Name | Type |
---|---|
T |
extends any [] |
U |
U |
Name | Type | Description |
---|---|---|
callback |
(current : T , previous : undefined | T ) => U |
The callback that receives both the current and previous value of the argument list. |
fn
A callback that receives the argument value list and returns the result of the provided callback
.
▸ (...current
): U
Name | Type |
---|---|
...current |
T |
U
lib/hooks/usePreviousArgumentList.ts:9
▸ usePromise<T
>(promise?
): PromiseState
<T
>
Returns a promise state object to track the provided promise
.
Ignores outdated promises or ones that resolve when the component got unmounted.
Name |
---|
T |
Name | Type | Description |
---|---|---|
promise? |
T | Promise <T > |
The promise to track. |
PromiseState
<T
>
A promise state object
▸ useRemove(props
): undefined
| () => void
Name | Type |
---|---|
props |
Object |
props.name |
string |
props.onRemove? |
ValueRemover |
undefined
| () => void
▸ useResilient<T
>(value
, trigger?
): T
Returns the provided value
when trigger
was truthy.
By default, trigger
is true
when value
is not undefined
.
Name |
---|
T |
Name | Type | Description |
---|---|---|
value |
T |
The value to keep a non-undefined value of. |
trigger |
boolean |
The trigger that sets the last value if it is truthy . |
T
The last non-undefined version of the provided value
, or undefined
.
▸ useSyncedProps<T
>(props?
): Pick
<NevoProps
<T
>, "name"
| "error"
| "value"
> & Required
<Pick
<NevoProps
<T
>, "onChange"
| "onChangeError"
>>
Creates a local state of value
and error
values and syncs them with the parent props
, if provided.
Usefull if you need to handle a local state while ensuring that new values provided from the parent component are taken into consideration, or to let the parent know about value
and error
changes.
Name |
---|
T |
Name | Type | Description |
---|---|---|
props? |
NevoProps <T > |
Optional properties according to the Nevo pattern. |
Pick
<NevoProps
<T
>, "name"
| "error"
| "value"
> & Required
<Pick
<NevoProps
<T
>, "onChange"
| "onChangeError"
>>
Properties according to the Nevo pattern.
lib/hooks/useSyncedProps.ts:11
▸ useSyncedSignal<T
>(value
): [T
, (value
: T
) => void
]
Name |
---|
T |
Name | Type |
---|---|
value |
T |
[T
, (value
: T
) => void
]
lib/hooks/useSyncedSignal.ts:3
▸ useSyncedState<T
>(props
): [T
, (value
: T
) => void
]
Creates a state that is synced with its parent.
If props.value
changes, the internal state
is also updated.
Calls to onChangeState(value)
trigger a call of props.onChange(state, props.name)
.
Name |
---|
T |
Name | Type | Description |
---|---|---|
props |
NevoProps <T > |
The NEVO props. |
[T
, (value
: T
) => void
]
The [state, onChangeState]
tuple.
lib/hooks/useSyncedState.ts:12
▸ useTransform<T
, U
>(props
, options
): NevoProps
<U
>
Transforms the incoming value
and the outgoing value
passed to the onChange
callback, and optionally the incoming error
and the outgoing error
passed to the onChangeError
callback. If the incoming and outgoing error
transforms are not provided, returned props will not contain error
nor onChangeError
.
Name |
---|
T |
U |
Name | Type | Description |
---|---|---|
props |
NevoProps <T > |
The props holding the value and onChange callbacks. |
options |
UseTransformOptions <T , U > |
Options for useTransform . |
NevoProps
<U
>
Updated props.
▸ useValidator<T
, N
, E
>(props
, onValidate?
): PromiseState
<E
| undefined
>
Name | Type |
---|---|
T |
T |
N |
extends string |
E |
extends ErrorReportValue |
Name | Type |
---|---|
props |
NevoProps <T , E > |
onValidate? |
ValueValidator <T , E > |
PromiseState
<E
| undefined
>
▸ useValidator<T
, N
, E
>(props
, onValidate?
): PromiseState
<E
| undefined
>
Name | Type |
---|---|
T |
extends object |
N |
extends string |
E |
extends ErrorReportObject <T > |
Name | Type |
---|---|
props |
NevoProps <T , E > |
onValidate? |
ValueValidator <T , E > |
PromiseState
<E
| undefined
>
▸ useValidator<T
, N
, E
>(props
, onValidate?
): PromiseState
<E
| undefined
>
Name | Type |
---|---|
T |
extends unknown [] |
N |
extends string |
E |
extends ErrorReportArray <T > |
Name | Type |
---|---|
props |
NevoProps <T , E > |
onValidate? |
ValueValidator <T , E > |
PromiseState
<E
| undefined
>
▸ withoutNevoProps<P
>(props
): Omit
<P
, NevoName
>
Returns the properties without the ones according to the Nevo pattern.
Name | Type |
---|---|
P |
extends object |
Name | Type | Description |
---|---|---|
props |
P |
Properties according to the Nevo pattern with extra properties. |
Omit
<P
, NevoName
>
The propterties without the ones according to the Nevo pattern.