Actions
Actions are minimal descriptions of store updates.
They are dispatched by Controller methods -> read and consumed by Manager middleware -> processed by reducers registered with DataProvider to update the store's state.
Many actions use the same meta information:
interface ActionMeta {
readonly fetchedAt: number;
readonly date: number;
readonly expiresAt: number;
}
FETCH
interface FetchMeta {
fetchedAt: number;
resolve: (value?: any | PromiseLike<any>) => void;
reject: (reason?: any) => void;
promise: PromiseLike<any>;
}
interface FetchAction {
type: typeof actionTypes.FETCH;
endpoint: Endpoint;
args: readonly [...Parameters<Endpoint>];
key: string;
meta: FetchMeta;
}
{
type: 'rdc/fetch',
key: 'GET https://jsonplaceholder.typicode.com/todos?userId=1',
args: [
{
userId: 1
}
],
endpoint: Endpoint('User.getList'),
meta: {
fetchedAt: '5:09:41.975 PM',
resolve: function (){},
reject: function (){},
promise: {}
}
}
Sent by Controller.fetch(), Controller.fetchIfStale(), useSuspense(), useDLE(), useLive(), useFetch()
Read by NetworkManager
SET
interface SetAction {
type: typeof actionTypes.SET;
schema: Queryable;
args: readonly any[];
meta: ActionMeta;
value: {} | ((previousValue: Denormalize<Queryable>) => {});
}
{
type: 'rdc/set',
value: {
userId: 1,
id: 1,
title: 'delectus aut autem',
completed: true
},
args: [
{
id: 1
}
],
schema: Todo,
meta: {
fetchedAt: '5:18:26.394 PM',
date: '5:18:26.636 PM',
expiresAt: '6:18:26.636 PM'
}
}
Sent by Controller.set()
SET_RESPONSE
interface SetResponseAction {
type: typeof actionTypes.SET_RESPONSE;
endpoint: Endpoint;
args: readonly any[];
key: string;
meta: ActionMeta;
response: ResolveType<Endpoint> | Error;
error: boolean;
}
{
type: 'rdc/setresponse',
key: 'PATCH https://jsonplaceholder.typicode.com/todos/1',
response: {
userId: 1,
id: 1,
title: 'delectus aut autem',
completed: true
},
args: [
{
id: 1
},
{
completed: true
}
],
endpoint: Endpont('Todo.partialUpdate'),
meta: {
fetchedAt: '5:18:26.394 PM',
date: '5:18:26.636 PM',
expiresAt: '6:18:26.636 PM'
},
error: false
}
Sent by Controller.setResponse(), NetworkManager
Read by NetworkManager, LogoutManager
RESET
interface ResetAction {
type: typeof actionTypes.RESET;
date: number;
}
{
type: 'rdc/reset',
date: '5:09:41.975 PM',
}
Sent by Controller.resetEntireStore()
Read by NetworkManager
SUBSCRIBE
interface SubscribeAction {
type: typeof actionTypes.SUBSCRIBE;
endpoint: Endpoint;
args: readonly any[];
key: string;
}
{
type: 'rdc/subscribe',
key: 'GET https://api.exchange.coinbase.com/products/BTC-USD/ticker',
args: [
{
product_id: 'BTC-USD'
}
],
endpoint: Endpoint('https://api.exchange.coinbase.com/products/:product_id/ticker'),
}
Sent by Controller.subscribe(), useSubscription(), useLive()
Read by SubscriptionManager
UNSUBSCRIBE
interface UnsubscribeAction {
type: typeof actionTypes.UNSUBSCRIBE;
endpoint: Endpoint;
args: readonly any[];
key: string;
}
{
type: 'rdc/unsubscribe',
key: 'GET https://api.exchange.coinbase.com/products/BTC-USD/ticker',
args: [
{
product_id: 'BTC-USD'
}
],
endpoint: Endpoint('https://api.exchange.coinbase.com/products/:product_id/ticker'),
}
Sent by Controller.unsubscribe(), useSubscription(), useLive()
Read by SubscriptionManager
INVALIDATE
interface InvalidateAction {
type: typeof actionTypes.INVALIDATE;
key: string;
}
{
type: 'rdc/invalidate',
key: 'GET https://jsonplaceholder.typicode.com/todos?userId=1',
}
Sent by Controller.invalidate()
INVALIDATEALL
interface InvalidateAllAction {
type: typeof actionTypes.INVALIDATEALL;
testKey: (key: string) => boolean;
}
{
type: 'rdc/invalidateall',
testKey: Endpoint('User.getList'),
}
Sent by Controller.invalidateAll()
EXPIREALL
interface ExpireAllAction {
type: typeof actionTypes.EXPIREALL;
testKey: (key: string) => boolean;
}
{
type: 'rdc/expireall',
testKey: Endpoint('User.getList'),
}
Sent by Controller.expireAll()