Output controller values
Name | Type | Description | Default value |
---|---|---|---|
id | string | The id value will be equal to the prefix. Readonly. | 'c-state' |
actions | object | Return the object with default action creators and your action creators. | - |
select | function | Method to get state of a particular controller. | - |
How select works
- TypeScript
- JavaScript
controller.select(state: ReduxState): Partial<ReduxState>
controller.select(store.getState())
Action types
- TypeScript
- JavaScript
ts
import { Controller, create } from 'redux-saga-controller';
interface IInitial {
initialized: boolean;
disabled: boolean;
data: UserData | null
}
export const controller:Controller<IInitial> = create({
prefix: 'testController',
actions: ['initialize', 'getSelf'], // TYPE: "@testController-state/initialize" TYPE: "@testController-state/getSelf"
initial: {
initialized: false,
disabled: true,
data: {
name: 'John',
age: 30,
}
},
subscriber: function * () {
// ...
},
});
ts
import { Controller, create } from 'redux-saga-controller';
interface IInitial {
initialized: boolean;
disabled: boolean;
data: UserData | null
}
export const controller:Controller<IInitial> = create({
prefix: 'defaultPrefix',
actions: {
initialize: 'INITIALIZE', // TYPE: "@defaultPrefix-state/INITIALIZE"
getSelf: 'GET_SELF', // TYPE: "@defaultPrefix-state/GET_SELF"
},
initial: {
initialized: false,
disabled: true,
data: {
name: 'John',
age: 30,
}
},
subscriber: function * () {
// ...
},
});
js
import { create } from 'redux-saga-controller';
export const controller = create(
{
// initial state controller
initial: {
initialized: false,
disabled: true,
data: {
name: 'John',
age: 30,
}
},
prefix: 'defaultPrefix',
actions: {
data: 'DATA', // TYPE: "@defaultPrefix-state/DATA"
initialize: 'INITIALIZE', // TYPE: "@defaultPrefix-state/INITIALIZE"
updateData: 'UPDATE_DATA', // TYPE: "@defaultPrefix-state/UPDATE_DATA"
},
subscriber: function * () {
// ...
}
},
);
js
import { create } from 'redux-saga-controller';
export const controller = create(
{
// initial state controller
initial: {
initialized: false,
disabled: true,
data: {
name: 'John',
age: 30,
}
},
prefix: 'defaultPrefix',
actions: ['initialize', 'updateData'], // TYPE: "@defaultPrefix-state/initialize", TYPE: "@defaultPrefix-state/updateData"
subscriber: function * () {
// ...
}
},
);