-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing the event map in runtime #276
Comments
huh, interesting. Are you doing something like:
|
No. We need to modify the |
The only solution I see now is to fetch the configuration from the server as JSON (instead of using your powerful EventDefinitionsMap) via XHR. And create my own meta reducer to apply static definitions declared in that JSON. |
Sorry for the late reply on this. Had a busy week work-wise last week, and am in the middle of a move so my evenings/weekends are a bit more busy than usual. I'm not sold on adding support for this sort of behaviour to the main redux-beacon package. Mostly because it seems like a fairly unique use-case. Is that fair? But...we should be able to design something pretty easily based on the existing Maybe something like: const getEvents = (eventsMap: EventsMap | EventsMapper) =>
typeof eventsMap === 'function'
? action => flatten<EventDefinition>([eventsMap(action)])
: action => getEventsWithMatchingKey(eventsMap, action.type);
function createMiddlewareDynamic(
eventsMap: EventsMap | EventsMapper,
target: Target,
extensions: Extensions = {}
) {
// save the initial (default) events definitions map
let currentEventsMap = eventsMap;
// a function that we expose to update currentEventsMap
const updateEventsMap = (newEventsMap: EventsMap | EventsMapper) => {
currentEventsMap = newEventsMap;
};
// the middleware
const middleware = store => next => action => {
const prevState = store.getState();
const result = next(action);
const nextState = store.getState();
const events = createEvents(
getEvents(currentEventsMap)(action),
prevState,
action,
nextState
);
registerEvents(events, target, extensions, prevState, action, nextState);
return result;
};
return { middleware, updateEventsMap };
} And you'd use the function like so: const { middleware, updateEventsMap } = createMiddlewareDynamic(initialEventsMap, gtmTarget(), { logger })
// use updateEventsMap wherever
updateEventsMap(newEventsMap) Also, the function above would require access to the following utility functions in the main redux-beacon package: import createEvents from './create-events';
import getEventsWithMatchingKey from './get-events-with-matching-key';
import registerEvents from './register-events'; I don't think I expose these. So for now, if you want to test it out I would copy-paste the compiled versions of these functions. If you need help with that, let me know. |
I'll like to add one use case for this feature. As Redux based application grows there are several solutions to make it load faster:
In our company, we're doing 2. so in order to use the For initial app load we fetch only actions/thunks/components that are required for that page. When a user navigates to another page we lazy-load their required files. If we are going to use |
Thanks all for the comments on this issue!
|
This is a...
Which version of Redux Beacon are you using?
Which target(s) are you using?
🚀 📜 What's missing from Redux Beacon that you'd like to add?
I wish I had a possibility to change event map (passed to the metareducer of my ngrx store) in runtime. Our team needs to adjust analytics events data without rebuilding the application
Can you help out?
The text was updated successfully, but these errors were encountered: