Interface: ListController<T>
lists/types/ListController.ListController
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
↳ ListController
Properties
attr
• attr: attrName
: Key
) => ListState
<T
>[Key
]
Type declaration
▸ <Key
>(attrName
): ListState
<T
>[Key
]
Retrieves a particular attribute from the state for this module.
Type parameters
Name | Type |
---|---|
Key |
extends "errors" | "name" | "reverse" | "endpoint" | "persistent" | "fetching" | "ready" | "failed" | "params" | "keyProp" | "pageInfo" | "grow" | "paginated" | "refs" |
Parameters
Name | Type |
---|---|
attrName |
Key |
Returns
ListState
<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 > = BaseListModule <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
count
• count: null
| number
Getter that tells you how many total items are in the list at the endpoint. This may not be something every API supports. It will be null if the information is unknown, such as before the list is fetched or if the client function for list handling doesn't include this information.
Defined in
src/base/lists/types/ListController.ts:120
currentPage
• currentPage: number
The current page number. Stays at 1 if the list is unpaginated. If set, the state will be updated to the target page number, and a fetch will be started for the target page. This is useful for components that increment/set target page values as part of pagination.
Defined in
src/base/lists/types/ListController.ts:130
dispatch
• dispatch: <Key>(funcName
: Key
, ...payload
: ParametersExceptFirst
<ListTasks
<T
, BaseListModule
<T
>>[Key
]>) => ReturnType
<ListTasks
<T
, BaseListModule
<T
>>[Key
]> | <Key>(funcName
: Key
, ...payload
: ParametersExceptFirst
<ListTasks
<T
, BaseListModule
<T
>>[Key
]>) => ReturnType
<ListTasks
<T
, BaseListModule
<T
>>[Key
]>
Dispatches a task for this module.
Inherited from
Defined in
src/base/types/BaseController.ts:48
empty
• empty: boolean
Returns true if the page is definitively empty. That means the list has been fetched, no items have been returned, and the current page is 1.
Defined in
src/base/lists/types/ListController.ts:135
endpoint
• endpoint: string
The endpoint property on the list module. This is a getter/setter, so you can update the endpoint.
Defined in
src/base/lists/types/ListController.ts:27
errors
• errors: default
Retrieves the stored error information from our last attempt at getting the remote list.
Defined in
src/base/lists/types/ListController.ts:55
extend
• extend: (val
: T
[]) => void
Type declaration
▸ (val
): void
Extend the list with more single modules, keeping the existing ones in place.
Parameters
Name | Type |
---|---|
val |
T [] |
Returns
void
Defined in
src/base/lists/types/ListController.ts:76
failed
• failed: boolean
Getter/setter to indicate that the attempt to fetch the list failed. Can be set manually if needed for testing.
Defined in
src/base/lists/types/ListController.ts:91
fetching
• fetching: boolean
Getter/setter to indicate that the list is being fetched via get
request. Can be set
manually if needed for testing.
Defined in
src/base/lists/types/ListController.ts:86
get
• get: () => Promise
<T
[]>
Type declaration
▸ (): Promise
<T
[]>
Performs a get request. Will create/replace the tracked Single modules based on what it retrieves, and return a promise containing the raw values.
Returns
Promise
<T
[]>
Defined in
src/base/lists/types/ListController.ts:40
getOnce
• getOnce: () => void
Type declaration
▸ (): void
Fetch the list 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/lists/types/ListController.ts:32
grow
• grow: boolean
Getter/setter to indicate whether the list is in 'grow' mode, whereas the pages are fetched, the contents are added to the list rather than replacing it.
Defined in
src/base/lists/types/ListController.ts:114
keyProp
• keyProp: keyof T
Returns the keyProp of the list-- that is, the unique ID property on each single used to tell them apart. This is usually something like 'id', which is the default.
Defined in
src/base/lists/types/ListController.ts:104
list
• list: SingleController
<T
>[]
An array of SingleControllers based on the contents of the list.
Defined in
src/base/lists/types/ListController.ts:18
makeReady
• makeReady: (val
: T
[]) => T
[]
Type declaration
▸ (val
): T
[]
Set up the single modules and mark ready as true
. Mostly useful for testing.
Unlike with the single controller version of this function, this version returns a promise, since it has to create new modules separate from the list's own internal state and so must create several internal transactions rather than a single commit.
Parameters
Name | Type |
---|---|
val |
T [] |
Returns
T
[]
Defined in
src/base/lists/types/ListController.ts:68
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: "list"
Returns 'list
', the type of module this controller handles.
Defined in
src/base/lists/types/ListController.ts:13
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
pageInfo
• pageInfo: null
| PageInfo
An object that contains some mate information about pagination, such as the total count of items the endpoint tracks, and the size of the most recently returned array from the server.
Defined in
src/base/lists/types/ListController.ts:109
paginated
• paginated: boolean
Getter that tells you if this is marked as a paginated list.
Defined in
src/base/lists/types/ListController.ts:124
params
• params: null
| QueryParams
Getter/setter for query parameters used when interacting with the endpoint.
Defined in
src/base/lists/types/ListController.ts:99
post
• post: (val
: I
) => Promise
<AxiosResponse
<O
, any
>>
Type declaration
▸ <I
, O
>(val
): Promise
<AxiosResponse
<O
, any
>>
Sends a post request. DOES NOT update the single modules 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/lists/types/ListController.ts:45
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
prefix
• prefix: (val
: T
[]) => void
Type declaration
▸ (val
): void
Prefix the list with more single modules, keeping the existing ones in place.
Parameters
Name | Type |
---|---|
val |
T [] |
Returns
void
Defined in
src/base/lists/types/ListController.ts:72
rawList
• rawList: T
[]
Property which returns all the x values of all SingleControllers as a single array. Setting this value to a new array replaces all the SingleModules within it.
Defined in
src/base/lists/types/ListController.ts:23
rawState
• rawState: ListState
<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 the list is initialized and ready to be interacted with. Mostly set internally, but can be explicitly set during testing.
Defined in
src/base/lists/types/ListController.ts:81
resetErrors
• resetErrors: () => void
Type declaration
▸ (): void
Empties out the values in errors.
Returns
void
Defined in
src/base/lists/types/ListController.ts:59
setPage
• setPage: (val
: number
) => void
Type declaration
▸ (val
): void
Sets the page number. Does not perform a fetch request. Use .get() after setting this value to get the new page.
Parameters
Name | Type |
---|---|
val |
number |
Returns
void
Defined in
src/base/lists/types/ListController.ts:50
toJSON
• Private
toJSON: () => { controller
: string
; list
: T
[] ; moduleType
: "list"
}
Type declaration
▸ (): Object
Custom JSON serializer to prevent infinite recursion.
Returns
Object
Name | Type |
---|---|
controller |
string |
list |
T [] |
moduleType |
"list" |
Defined in
src/base/lists/types/ListController.ts:141
totalPages
• totalPages: null
| number
Returns the total number of pages at the endpoint, or null if this is not known/applicable.
Defined in
src/base/lists/types/ListController.ts:95
uid
• Private
uid: string
An internal ID used to track this controller as a listener of single modules.