Interface: SingleController<T>
singles/types/SingleController.SingleController
Controllers are the public interface for interacting with providence modules in your store of choice. There will only ever be one controller per registered module, thanks to the registry. The controller should not hold information that can't be reconstructed upon hot reload. It should merely be an interface for manipulating the registered module.
Type parameters
Name |
---|
T |
Hierarchy
↳ SingleController
Properties
attr
• attr: attrName
: Key
) => SingleState
<T
>[Key
]
Type declaration
▸ <Key
>(attrName
): SingleState
<T
>[Key
]
Retrieves a particular attribute from the state for this module.
Type parameters
Name | Type |
---|---|
Key |
extends "errors" | "name" | "endpoint" | "persistent" | "fetching" | "ready" | "failed" | "params" | "x" | "deleted" | "patchers" |
Parameters
Name | Type |
---|---|
attrName |
Key |
Returns
SingleState
<T
>[Key
]
Inherited from
Defined in
src/base/types/BaseController.ts:40
commit
• commit: <OutsideModuleDefinition, Key>(funcName
: Key
| `${string}/${Key}`, ...payload
: ParametersExceptFirst
<OutsideModuleDefinition
["mutations"
][Key
]>) => void
Type declaration
▸ <OutsideModuleDefinition
, Key
>(funcName
, ...payload
): void
Commits a mutation for this module.
Type parameters
Name | Type |
---|---|
OutsideModuleDefinition |
extends BaseModule <any , any , any > = BaseSingleModule <T > |
Key |
extends string = string & keyof OutsideModuleDefinition ["mutations" ] |
Parameters
Name | Type |
---|---|
funcName |
Key | `${string}/${Key}` |
...payload |
ParametersExceptFirst <OutsideModuleDefinition ["mutations" ][Key ]> |
Returns
void
Inherited from
Defined in
src/base/types/BaseController.ts:44
delete
• delete: () => Promise
<void
>
Type declaration
▸ (): Promise
<void
>
Sends a deletion request to the server. If successful, marks x as null and sets
the deleted flag to true
and sets the
deleted flag to true
.
Returns
Promise
<void
>
Defined in
src/base/singles/types/SingleController.ts:84
deleted
• deleted: boolean
getter/setter to indicate whether the remote value we're tracking has been deleted.
Defined in
src/base/singles/types/SingleController.ts:143
dispatch
• dispatch: <Key>(funcName
: Key
, ...payload
: ParametersExceptFirst
<SingleTasks
<T
, BaseSingleModule
<T
>>[Key
]>) => ReturnType
<SingleTasks
<T
, BaseSingleModule
<T
>>[Key
]> | <Key>(funcName
: Key
, ...payload
: ParametersExceptFirst
<SingleTasks
<T
, BaseSingleModule
<T
>>[Key
]>) => ReturnType
<SingleTasks
<T
, BaseSingleModule
<T
>>[Key
]>
Dispatches a task for this module.
Inherited from
Defined in
src/base/types/BaseController.ts:48
endpoint
• endpoint: string
The endpoint property on the single module. This is a getter/setter, so you can update the endpoint.
Defined in
src/base/singles/types/SingleController.ts:19
errors
• errors: default
Retrieves the stored error information from our last attempt at getting the remote object.
Defined in
src/base/singles/types/SingleController.ts:89
failed
• failed: boolean
getter/setter to indicate that the attempt to fetch x failed. Can be set manually if needed for testing.
Defined in
src/base/singles/types/SingleController.ts:139
fetching
• fetching: boolean
getter/setter to indicate that x is being fetched via get
request. Can be set
manually if needed for testing.
Defined in
src/base/singles/types/SingleController.ts:134
get
• get: () => Promise
<T
>
Type declaration
▸ (): Promise
<T
>
Performs a get request. Will update the value of x based on what it retrieves, and return a promise containing the new value.
Returns
Promise
<T
>
Defined in
src/base/singles/types/SingleController.ts:63
getOnce
• getOnce: () => void
Type declaration
▸ (): void
Fetch this object from its endpoint. No matter how many times this function is called, it only runs once, allowing you to call it in any component that may need the function and not worry about several requests being sent.
Returns
void
Defined in
src/base/singles/types/SingleController.ts:58
getPatcherSetting
• Private
getPatcherSetting: attrName
: AttrName
, setting
: Setting
) => PatcherState
<T
, AttrName
>[Setting
]
Type declaration
▸ <AttrName
, Setting
>(attrName
, setting
): PatcherState
<T
, AttrName
>[Setting
]
Get one of the patcher's settings. The single module keeps all the data for its patchers, rather than creating a new module for each patcher.
Type parameters
Name | Type |
---|---|
AttrName |
extends string | number | symbol |
Setting |
extends keyof PatcherState <T , AttrName > |
Parameters
Name | Type |
---|---|
attrName |
AttrName |
setting |
Setting |
Returns
PatcherState
<T
, AttrName
>[Setting
]
Defined in
src/base/singles/types/SingleController.ts:121
initializePatcherSettings
• initializePatcherSettings: attrName
: AttrName
) => void
Type declaration
▸ <AttrName
>(attrName
): void
Initialize a patcher's settings. You might need this if the object returned from your initial fetching is incomplete and does not have the field you want to add a patcher for, or if you need to initialize a patcher without fetching the remote resource for some reason.
Type parameters
Name | Type |
---|---|
AttrName |
extends string | number | symbol |
Parameters
Name | Type |
---|---|
attrName |
AttrName |
Returns
void
Defined in
src/base/singles/types/SingleController.ts:103
makeReady
• makeReady: (val
: T
) => void
Type declaration
▸ (val
): void
Set x and mark ready as true
. Mostly useful for testing.
Parameters
Name | Type |
---|---|
val |
T |
Returns
void
Defined in
src/base/singles/types/SingleController.ts:97
managedNames
• managedNames: string
[]
Returns the names of all modules this module manages. For singles, that will only be the current module name. For lists, it will be the current module name and all the names of the singles it manages.
Inherited from
Defined in
src/base/types/BaseController.ts:36
moduleType
• moduleType: "single"
Returns 'single
', the type of module this controller handles.
Defined in
src/base/singles/types/SingleController.ts:15
name
• name: string
The name of the dynamically created module. This is a dot separated name. You can construct an escaped, valid name with use of the flattenNamespace function.
Inherited from
Defined in
src/base/types/BaseController.ts:21
namespace
• namespace: string
[]
Useful for when needing to walk through modules for an operation, namespace returns an array of strings representing this module's location in the hierarchy.
Inherited from
Defined in
src/base/types/BaseController.ts:31
p
• p: BoundPatchers
<T
>
A proxy object that creates patchers for any property on the object. So, for instance, if you have a type:
.. code-block:: typescript
declare interface MyType {
id: number,
name: string,
fun: boolean,
}
Then this object will contain the keys id
, name
, and fun
. Each of these attributes will be a
Patcher bound to its specific field.
Defined in
src/base/singles/types/SingleController.ts:45
params
• params: null
| QueryParams
getter/setter for query parameters used when interacting with the endpoint.
Defined in
src/base/singles/types/SingleController.ts:147
patch
• patch: (val
: Partial
<T
>) => Promise
<T
>
Type declaration
▸ (val
): Promise
<T
>
Sends a patch request. Updates x with the value returned from the server, and returns a promise containing the new value.
Parameters
Name | Type |
---|---|
val |
Partial <T > |
Returns
Promise
<T
>
Defined in
src/base/singles/types/SingleController.ts:68
post
• post: (val
: I
) => Promise
<AxiosResponse
<O
, any
>>
Type declaration
▸ <I
, O
>(val
): Promise
<AxiosResponse
<O
, any
>>
Sends a post request. DOES NOT update x with the value returned from the server. Returns a promise containing the value the server sent back.
Type parameters
Name | Type |
---|---|
I |
I |
O |
I |
Parameters
Name | Type |
---|---|
val |
I |
Returns
Promise
<AxiosResponse
<O
, any
>>
Defined in
src/base/singles/types/SingleController.ts:78
preDestroy
• preDestroy: () => void
Type declaration
▸ (): void
A function which is run after the controller is no longer needed (because all listeners have disconnected), before it is removed from the store.
Returns
void
Inherited from
Defined in
src/base/types/BaseController.ts:53
put
• put: (val
: Partial
<T
>) => Promise
<T
>
Type declaration
▸ (val
): Promise
<T
>
Sends a put request. Updates x with the value returned from the server, and returns a promise containing the new value.
Parameters
Name | Type |
---|---|
val |
Partial <T > |
Returns
Promise
<T
>
Defined in
src/base/singles/types/SingleController.ts:73
rawState
• rawState: SingleState
<T
>
The raw state of the dynamically created module. This should be a copy so mutating the output doesn't affect the state.
Inherited from
Defined in
src/base/types/BaseController.ts:26
ready
• ready: boolean
getter/setter to indicate that x is initialized and ready to be interacted with. Mostly set internally, but can be explicitly set during testing.
Defined in
src/base/singles/types/SingleController.ts:129
resetErrors
• resetErrors: () => void
Type declaration
▸ (): void
Empties out the values in errors.
Returns
void
Defined in
src/base/singles/types/SingleController.ts:93
setPatcherSetting
• Private
setPatcherSetting: <AttrName, Setting>(fieldUpdate
: FieldUpdate
<T
, AttrName
, Setting
>) => void
Type declaration
▸ <AttrName
, Setting
>(fieldUpdate
): void
Set one of the patcher's settings. The single module keeps all the data for its patchers, rather than creating a new module for each patcher.
Type parameters
Name | Type |
---|---|
AttrName |
extends string | number | symbol |
Setting |
extends keyof PatcherState <T , AttrName > |
Parameters
Name | Type |
---|---|
fieldUpdate |
FieldUpdate <T , AttrName , Setting > |
Returns
void
Defined in
src/base/singles/types/SingleController.ts:112
setX
• setX: (val
: null
| T
) => void
Type declaration
▸ (val
): void
Completely replace x.
Parameters
Name | Type |
---|---|
val |
null | T |
Returns
void
Defined in
src/base/singles/types/SingleController.ts:49
toJSON
• Private
toJSON: () => { controller
: string
; moduleType
: "single"
; x
: null
| T
}
Type declaration
▸ (): Object
Custom JSON serializer to prevent infinite recursion.
Returns
Object
Name | Type |
---|---|
controller |
string |
moduleType |
"single" |
x |
null | T |
Defined in
src/base/singles/types/SingleController.ts:153
uid
• Private
uid: string
An internal ID used to track this controller as a listener of single modules.
Inherited from
Defined in
src/base/types/BaseController.ts:16
updateX
• updateX: (val
: Partial
<T
>) => void
Type declaration
▸ (val
): void
Update the value of x in place by setting a subset of its values.
Parameters
Name | Type |
---|---|
val |
Partial <T > |
Returns
void
Defined in
src/base/singles/types/SingleController.ts:53
x
• x: null
| T
The data structure you're tracking in the single module. It can also be null if you've neither fetched nor preset its value. This is a getter and setter, so you can entirely replace x if you like.
Note that you should not mutate the attributes of x directly. Instead, if you need to change x, use updateX, setX, set the x setter directly, or use the Patchers`.