mirror of
https://github.com/uetchy/namae.git
synced 2025-03-17 04:30:31 +09:00
chore: compose history middleware
This commit is contained in:
parent
bf39c3293f
commit
d313dbd680
@ -218,6 +218,7 @@ const Suggestion: React.FC<{
|
|||||||
return () => {
|
return () => {
|
||||||
isEffective = false;
|
isEffective = false;
|
||||||
};
|
};
|
||||||
|
// eslint-disable-next-line
|
||||||
}, [query]);
|
}, [query]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -117,6 +117,7 @@ export const DedicatedAvailability: React.FC<{
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
increaseCounter(response.availability);
|
increaseCounter(response.availability);
|
||||||
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -164,6 +165,7 @@ export const ExistentialAvailability: React.FC<{
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
increaseCounter(availability);
|
increaseCounter(availability);
|
||||||
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import {Router} from 'react-router-dom';
|
import {Router} from 'react-router-dom';
|
||||||
import {StoreProvider, createStore} from 'easy-peasy';
|
import {StoreProvider} from 'easy-peasy';
|
||||||
import {createBrowserHistory} from 'history';
|
import {createBrowserHistory} from 'history';
|
||||||
|
|
||||||
import App from './App';
|
import App from './App';
|
||||||
@ -9,18 +9,18 @@ import * as serviceWorker from './serviceWorker';
|
|||||||
import {FullScreenSuspense} from './util/suspense';
|
import {FullScreenSuspense} from './util/suspense';
|
||||||
import {wrapHistoryWithGA, initSentry} from './util/analytics';
|
import {wrapHistoryWithGA, initSentry} from './util/analytics';
|
||||||
import {initCrisp} from './util/crip';
|
import {initCrisp} from './util/crip';
|
||||||
import {storeModel} from './store';
|
import {compose} from './util/array';
|
||||||
|
import {store, wrapHistoryWithStoreHandler} from './store';
|
||||||
import './util/i18n';
|
import './util/i18n';
|
||||||
|
|
||||||
initSentry();
|
initSentry();
|
||||||
initCrisp();
|
initCrisp();
|
||||||
|
|
||||||
const store = createStore(storeModel);
|
const history = compose(
|
||||||
const history = wrapHistoryWithGA(createBrowserHistory());
|
createBrowserHistory(),
|
||||||
history.listen(() => {
|
wrapHistoryWithStoreHandler,
|
||||||
// reset stats counter
|
wrapHistoryWithGA,
|
||||||
store.getActions().stats.reset();
|
);
|
||||||
});
|
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<StoreProvider store={store}>
|
<StoreProvider store={store}>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {action, createTypedHooks, Action} from 'easy-peasy';
|
import {History} from 'history';
|
||||||
|
import {action, createTypedHooks, Action, createStore} from 'easy-peasy';
|
||||||
|
|
||||||
interface StatsModel {
|
interface StatsModel {
|
||||||
availableCount: number;
|
availableCount: number;
|
||||||
@ -26,10 +27,20 @@ const statsModel: StatsModel = {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const storeModel: StoreModel = {
|
const storeModel: StoreModel = {
|
||||||
stats: statsModel,
|
stats: statsModel,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const store = createStore(storeModel);
|
||||||
|
|
||||||
|
export function wrapHistoryWithStoreHandler(history: History) {
|
||||||
|
history.listen(() => {
|
||||||
|
// reset stats counter
|
||||||
|
store.getActions().stats.reset();
|
||||||
|
});
|
||||||
|
return history;
|
||||||
|
}
|
||||||
|
|
||||||
const typedHooks = createTypedHooks<StoreModel>();
|
const typedHooks = createTypedHooks<StoreModel>();
|
||||||
export const useStoreActions = typedHooks.useStoreActions;
|
export const useStoreActions = typedHooks.useStoreActions;
|
||||||
export const useStoreDispatch = typedHooks.useStoreDispatch;
|
export const useStoreDispatch = typedHooks.useStoreDispatch;
|
||||||
|
@ -19,3 +19,7 @@ export function fillArray<T>(array: T[], filler: string, maximum: number): T[] {
|
|||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function compose<T>(arg: T, ...fn: ((arg: T) => T)[]): T {
|
||||||
|
return fn.reduce((arg, f) => f(arg), arg);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user