import { createContext, Component, FunctionComponent } from "react"; import { Emitter } from "@Model/Emitter"; /** * 主题模式 */ enum Themes { light = 1, dark = 2 } class Setting extends Emitter< Setting & {change: keyof Setting} > { /** * 主题 */ public themes: Themes = Themes.light; /** * 设置参数 */ public setProps

(key: P, value: Setting[P]) { this[key] = value as any; this.emit("change", key); this.emit(key as any, value as any); } } interface IMixinSettingProps { setting?: Setting; } const SettingContext = createContext(new Setting()); SettingContext.displayName = "Setting"; const SettingProvider = SettingContext.Provider; const SettingConsumer = SettingContext.Consumer; type RenderComponent = (new (...p: any) => Component) | FunctionComponent; /** * 修饰器 */ function useSetting(components: R): R { return ((props: any) => { const C = components; return {(setting: Setting) => } }) as any; } export { Themes, Setting, SettingContext, useSetting, IMixinSettingProps, SettingProvider, SettingConsumer };