Skip to content

@opencraft/providence


Interface: ListController\<T>

Defined in: lists/types/ListController.ts:9

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.

Extends

Type Parameters

T

T

Properties

attr

attr: \<Key>(attrName) => ListState\<T>[Key]

Defined in: types/BaseController.ts:40

Retrieves a particular attribute from the state for this module.

Type Parameters

Key

Key extends "errors" | "name" | "reverse" | "endpoint" | "persistent" | "fetching" | "ready" | "failed" | "params" | "keyProp" | "pageInfo" | "grow" | "paginated" | "refs"

Parameters

attrName

Key

Returns

ListState\<T>[Key]

Inherited from

BaseController.attr


commit

commit: \<OutsideModuleDefinition, Key>(funcName, ...payload) => void

Defined in: types/BaseController.ts:44

Commits a mutation for this module.

Type Parameters

OutsideModuleDefinition

OutsideModuleDefinition extends BaseModule\<any, any, any> = BaseListModule\<T>

Key

Key extends string = string & keyof OutsideModuleDefinition["mutations"]

Parameters

funcName

Key | `${string}/${Key}`

payload

...ParametersExceptFirst\<OutsideModuleDefinition["mutations"][Key]>

Returns

void

Inherited from

BaseController.commit


count

count: number | null

Defined in: lists/types/ListController.ts:120

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.


currentPage

currentPage: number

Defined in: lists/types/ListController.ts:130

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.


dispatch

dispatch: (\<Key>(funcName, ...payload) => ReturnType\<ListTasks\<T, BaseListModule\<T>>[Key]>) | (\<Key>(funcName, ...payload) => ReturnType\<ListTasks\<T, BaseListModule\<T>>[Key]>)

Defined in: types/BaseController.ts:48

Dispatches a task for this module.

Inherited from

BaseController.dispatch


empty

empty: boolean

Defined in: lists/types/ListController.ts:135

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.


endpoint

endpoint: string

Defined in: lists/types/ListController.ts:27

The endpoint property on the list module. This is a getter/setter, so you can update the endpoint.


errors

errors: default

Defined in: lists/types/ListController.ts:55

Retrieves the stored error information from our last attempt at getting the remote list.


extend

extend: (val) => void

Defined in: lists/types/ListController.ts:76

Extend the list with more single modules, keeping the existing ones in place.

Parameters

val

T[]

Returns

void


failed

failed: boolean

Defined in: lists/types/ListController.ts:91

Getter/setter to indicate that the attempt to fetch the list failed. Can be set manually if needed for testing.


fetching

fetching: boolean

Defined in: lists/types/ListController.ts:86

Getter/setter to indicate that the list is being fetched via get request. Can be set manually if needed for testing.


get

get: () => Promise\<T[]>

Defined in: lists/types/ListController.ts:40

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[]>


getOnce

getOnce: () => void

Defined in: lists/types/ListController.ts:32

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


grow

grow: boolean

Defined in: lists/types/ListController.ts:114

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.


keyProp

keyProp: keyof T

Defined in: lists/types/ListController.ts:104

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.


list

list: SingleController\<T>[]

Defined in: lists/types/ListController.ts:18

An array of SingleControllers based on the contents of the list.


makeReady

makeReady: (val) => T[]

Defined in: lists/types/ListController.ts:68

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

val

T[]

Returns

T[]


managedNames

managedNames: string[]

Defined in: types/BaseController.ts:36

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

BaseController.managedNames


moduleType

moduleType: "list"

Defined in: lists/types/ListController.ts:13

Returns 'list', the type of module this controller handles.


name

name: string

Defined in: types/BaseController.ts:21

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

BaseController.name


namespace

namespace: string[]

Defined in: types/BaseController.ts:31

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

BaseController.namespace


pageInfo

pageInfo: PageInfo | null

Defined in: lists/types/ListController.ts:109

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.


paginated

paginated: boolean

Defined in: lists/types/ListController.ts:124

Getter that tells you if this is marked as a paginated list.


params

params: QueryParams | null

Defined in: lists/types/ListController.ts:99

Getter/setter for query parameters used when interacting with the endpoint.


post

post: \<I, O>(val) => Promise\<AxiosResponse\<O, any, { }, any>>

Defined in: lists/types/ListController.ts:45

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

I

I

O

O = I

Parameters

val

I

Returns

Promise\<AxiosResponse\<O, any, { }, any>>


preDestroy

preDestroy: () => void

Defined in: types/BaseController.ts:53

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

BaseController.preDestroy


prefix

prefix: (val) => void

Defined in: lists/types/ListController.ts:72

Prefix the list with more single modules, keeping the existing ones in place.

Parameters

val

T[]

Returns

void


rawList

rawList: T[]

Defined in: lists/types/ListController.ts:23

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.


rawState

rawState: ListState\<T>

Defined in: types/BaseController.ts:26

The raw state of the dynamically created module. This should be a copy so mutating the output doesn't affect the state.

Inherited from

BaseController.rawState


ready

ready: boolean

Defined in: lists/types/ListController.ts:81

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.


resetErrors

resetErrors: () => void

Defined in: lists/types/ListController.ts:59

Empties out the values in errors.

Returns

void


setPage

setPage: (val) => void

Defined in: lists/types/ListController.ts:50

Sets the page number. Does not perform a fetch request. Use .get() after setting this value to get the new page.

Parameters

val

number

Returns

void


totalPages

totalPages: number | null

Defined in: lists/types/ListController.ts:95

Returns the total number of pages at the endpoint, or null if this is not known/applicable.