import {ReactRender} from "@gongt/ts-stl-client/react/render"; import {createLogger} from "@gongt/ts-stl-library/debug/create-logger"; import {LOG_LEVEL} from "@gongt/ts-stl-library/debug/levels"; import {GlobalVariable} from "@gongt/ts-stl-library/pattern/global-page-data"; import {Provider, ProviderProps} from "react-redux"; import {ReduxStoreExpress} from "./redux"; const debug = createLogger(LOG_LEVEL.SILLY, 'react-redux'); export function reactUseRedux(react: ReactRender, redux: ReduxStoreExpress) { const preventDuplicate = new GlobalVariable(react); if (preventDuplicate.has('redux')) { throw new TypeError('reactUseRedux(): duplicate call to one react instance.') } preventDuplicate.set('redux', true); react.wrapComponent('Provider', Provider, (global: GlobalVariable) => { const store = redux.createStore(global); debug('create store: ', store); if (!store) { throw new Error('ReduxStoreExpress: createStore() not return.'); } return { store: store, }; }); }