Comments (3)
@JeanDenisVIDOT thanks for reaching out. You can add global logic and also any injected helpers (to use inside any logic) where we create the original logicMiddleware.
https://github.com/jeffbski/react-boilerplate-logic/blob/master/app/store.js#L15
Original code is:
const injectedHelpers = { requestUtil };
const logicMiddleware = createLogicMiddleware([], injectedHelpers);
So you can change it so that you can add in any helpers you want available in all logic and if you want any logic to always be loaded then you can add that here too.
import foo from './foo'; // another helper I want to use in my logic
import globalLogic from './global-logic'; // array of logic to add always
const injectedHelpers = { requestUtil, foo }; // adding foo as another injected helper available to all logic
const logicMiddleware = createLogicMiddleware(globalLogic, injectedHelpers);
So by adding additional injected helpers you can use them in your logic like
const abcLogic = createLogic({
type: CAT,
transform({ getState, action, requestUtil, foo }, next) {
// your code
},
process({ getState, action, requestUtil, foo }, dispatch, done) {
// your code
}
});
Then of course create a file globalLogic.js which exports the logic array as the default.
import { createLogic } from 'redux-logic';
const logic1 = createLogic({...});
const logic2 = createLogic({...});
export default [
logic1,
logic2
];
from react-boilerplate-logic.
@jeffbski thanks for your answer.
So, for instance :
If I dispatch an action when store has been initialized ( like store.dispatch({ type: 'foo' }) ) I'll be able to execute my logic ?
Is it possible for a logic to listen more than one action for type property ?
Is it possible for a logic to listen more than one action for cancelType property ?
Sorry for my beginner questions but I'm trying to understand.
from react-boilerplate-logic.
Yes, whenever you dispatch after the logic has been loaded then it will be listening and will respond calling your logic functions.
Yes, you can listen to more than one type per logic. The type can be a string, a regex, or an array of strings and regex so you can easily match many types of actions in one logic.
type: [FOO, BAR, /cat.*/]
Yes, same thing for cancelType.
No worries on the questions. I am happy to help as I can.
from react-boilerplate-logic.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-boilerplate-logic.