bug: only use redux plugin in dev [GT#21]

This commit is contained in:
Yanick Champoux 2022-04-06 19:41:57 -04:00
parent 9e36f38225
commit ea3c438227

View File

@ -1,4 +1,4 @@
import { browser } from "$app/env";
import { browser, dev } from "$app/env";
import { readable, get, derived } from "svelte/store";
import { compose, applyMiddleware } from "redux";
@ -6,27 +6,27 @@ import shipDux from "../shipDux/index.js";
let composeEnhancers = compose;
if (browser) {
// composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
if (dev && browser && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) {
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
}
export default () => {
const duxStore = shipDux.createStore(undefined, (mw) =>
composeEnhancers(applyMiddleware(mw))
);
const duxStore = shipDux.createStore(undefined, (mw) =>
composeEnhancers(applyMiddleware(mw))
);
let previous;
const state = readable(duxStore.getState(), (set) => {
duxStore.subscribe(() => {
if (previous === duxStore.getState()) return;
previous = duxStore.getState();
set(previous);
let previous;
const state = readable(duxStore.getState(), (set) => {
duxStore.subscribe(() => {
if (previous === duxStore.getState()) return;
previous = duxStore.getState();
set(previous);
});
});
});
return {
dispatch: duxStore.dispatch,
state,
shipMass: derived( state, state => state.reqs.mass )
};
return {
dispatch: duxStore.dispatch,
state,
shipMass: derived(state, (state) => state.reqs.mass),
};
};