This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from "react"; | |
| export function attachModel<T>(Model: { new (): T }) { | |
| return function<Props, State>(Comp: React.ComponentClass<Props>) { | |
| const ComponentModel = (Comp as any) as React.ComponentClass; | |
| return class extends React.Component<Props, State> { | |
| static displayName = `AttachedModel${ComponentModel.displayName || | |
| ComponentModel.name}`; | |
| render() { | |
| return <ComponentModel {...this.props} />; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function initStore<StoreTypes, Store extends UseBoundStore<StoreApi<unknown>>>( | |
| store: Store, | |
| compare?: (a: StoreTypes, b: StoreTypes) => boolean | |
| ) { | |
| return (newValue: StoreTypes, defaultValue: StoreTypes) => { | |
| if (compare && compare(newValue, store.getState() as unknown as StoreTypes)) { | |
| return | |
| } | |
| store.setState(newValue as any) | |
| } |
OlderNewer