Selectors
The Selectors package is a kernel that exposes an API using the selectorsHelper to manage Redux's selectors.
Selectors helper
The selectorsHelper exposes an API to manage the Selectors, which allows you to add new selectors, retrieve added selectors, and use added selectors.
What is a selector? You can find useful information about selectors in the following Redux documentation.
make
Retrieves a selector by its name. Factories registered are instantiated for every make executed.
Usage
make(selectorName: String): Function
-
selectorName String
The name of the selector to be retrieved.
Returns
-
Function
The desired selector, returns undefined in case it doesn't exist.
Example
const state = storeHelper.getState();
const getCurrentTerminalIdFactory = () => (state) => state.terminals.current.currentTerminalId;
selectorsHelper.registerFactory('getCurrentTerminalId', getCurrentTerminalIdFactory);
const getCurrentTerminalId = selectorsHelper.make('getCurrentTerminalId');
const currentTerminalId = getCurrentTerminalId(state);
registerFactory
Registers a factory which creates a selector to allow its use among all the plugins. Factories can access to the plugin dio.
registerFactory can not override a defined selector
Usage
registerFactory(selectorName: String, selectorFactory: Function): Boolean
Example
const getCurrentTerminalIdFactory = () => (state) => state.terminals.current.currentTerminalId;
selectorsHelper.registerFactory('getCurrentTerminalId', getCurrentTerminalIdFactory);
Factories can access to the plugin dio.
selectorsHelper.registerFactory(
'getFive',
({ FIVE }) =>
() =>
FIVE,
);
diHelper.useValue('FIVE', 5);
const getFive = selectorsHelper.make('getFive');
console.log(getFive()); // 5