preact-batteries
Version:
Batteries for you projects with Preact, TypeScript (or Babel)
19 lines (17 loc) • 511 B
text/typescript
export interface ComponentModule<ComponentType> {
init(c: ComponentType): void;
}
export interface CompatibleComponentInterface<PropsType, StateType> {
state: Object;
render(props: PropsType, state: StateType): any;
setState(state: Object);
componentWillMount?(): void;
componentWillUnmount?(): void;
forceUpdate?(): void;
}
export function modules<ComponentType>(
component: ComponentType,
modules: Array<ComponentModule<ComponentType>> = []
) {
modules.forEach(m => m.init(component));
}