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]
Retrieves a particular attribute from the state for this module.
Type declaration
▸ \<Key>(attrName): SingleState\<T>[Key]
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
Commits a mutation for this module.
Type declaration
▸ \<OutsideModuleDefinition, Key>(funcName, ...payload): void
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>
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.
Type declaration
▸ (): Promise\<void>
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>
Performs a get request. Will update the value of x based on what it retrieves, and return a promise containing the new value.
Type declaration
▸ (): Promise\<T>
Returns
Promise\<T>
Defined in
src/base/singles/types/SingleController.ts:63
getOnce
• getOnce: () => 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.
Type declaration
▸ (): void
Returns
void
Defined in
src/base/singles/types/SingleController.ts:58
getPatcherSetting
• Private getPatcherSetting: \attrName: AttrName, setting: 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 declaration
▸ \<AttrName, Setting>(attrName, setting): PatcherState\<T, AttrName>[Setting]
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
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 declaration
▸ \<AttrName>(attrName): void
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
Set x and mark ready as true. Mostly useful for testing.
Type declaration
▸ (val): void
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>
Sends a patch request. Updates x with the value returned from the server, and returns a promise containing the new value.
Type declaration
▸ (val): Promise\<T>
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, {}>>
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 declaration
▸ \<I, O>(val): Promise\<AxiosResponse\<O, any, {}>>
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
A function which is run after the controller is no longer needed (because all listeners have disconnected), before it is removed from the store.
Type declaration
▸ (): void
Returns
void
Inherited from
Defined in
src/base/types/BaseController.ts:53
put
• put: (val: Partial\<T>) => Promise\<T>
Sends a put request. Updates x with the value returned from the server, and returns a promise containing the new value.
Type declaration
▸ (val): Promise\<T>
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
Empties out the values in errors.
Type declaration
▸ (): void
Returns
void
Defined in
src/base/singles/types/SingleController.ts:93
setPatcherSetting
• Private setPatcherSetting: \<AttrName, Setting>(fieldUpdate: FieldUpdate\<T, AttrName, Setting>) => 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 declaration
▸ \<AttrName, Setting>(fieldUpdate): void
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
Completely replace x.
Type declaration
▸ (val): void
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 }
Custom JSON serializer to prevent infinite recursion.
Type declaration
▸ (): Object
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
Update the value of x in place by setting a subset of its values.
Type declaration
▸ (val): void
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`.