import * as React from "react"; import StoreCaller from "./StoreCaller"; import StoreGetter from "./StoreGetter"; import StoreSetter from "./StoreSetter"; import ValueMap from "./ValueMap"; import { StoreValue, KeyMap } from "./types/ValueMap"; const { Provider, Consumer } = React.createContext({}); class StoreProvider extends React.Component< // Props { children: any; store: KeyMap; staticKeys?: string[]; }, // State { [key: string]: Function | StoreValue; } > { constructor(props: any) { super(props); const { store, staticKeys = [] } = this.props; this.state = { get: (keys?: string | string[]) => StoreGetter(this.state, keys), set: (keyValue: { [key: string]: any }) => this.setState(previousState => StoreSetter(previousState, keyValue)), call: (key: string, value: any) => this.setState(previousState => StoreCaller(previousState, key, value)), ...ValueMap(store, staticKeys) }; } render() { return ; } } export { StoreProvider, Consumer };