import * as React from 'react'; import { IStateliStore } from 'stateli'; import { CreateAppContext } from './app-context'; import { ComponentWithStore } from './component-with-store'; import wrapRedux from './wrap-redux'; const AppContext = CreateAppContext({ store: null as any }); let reduxStore: any = null; export class StateliProvider extends React.Component<{ debug: boolean; store: IStateliStore }> { constructor(props: any) { super(props); if (!reduxStore) { reduxStore = wrapRedux(this.props.store, this.props.debug); } } render() { const props = { store: this.props.store }; return {this.props.children}; } } export function WrapComponentWithStore( Component: any, getState?: (rootState: RootState) => State ) { return class extends ComponentWithStore { constructor(props: any, context?: any) { super(props, context, getState); } render() { return ( {ctx => { const props = { ...this.props, store: ctx.store, }; return ; }} ); } }; }