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
export interface Something { | |
rules: Something.Rule[]; | |
} | |
export namespace Something { | |
/** | |
* Rule is a pretty common name | |
* use namespace so we can easily avoid name collision without named import like | |
* import { Rule as ARule } from ./Something; | |
* import { Rule as BRule } from ./Otherthing; |
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 ReactDOM from "react-dom"; | |
import { Observable } from "rxjs"; | |
// wrap this on every [source] of observable(eg: from(), subject, fromEvent(), fromFetch()) | |
// to let all subscriber to run in unstable_batchedUpdates | |
export const reactBatch = <T>(obs: Observable<T>): Observable<T> => { | |
return new Observable<T>((observer) => { | |
// 如果是测试环境(对model进行单元测试) | |
// 则需要把 unstable_batchedUpdates 替换成直接执行 | |
return obs.subscribe({ |
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
type PartPartial<T, PartielKeys extends keyof T> = Partial<T> & | |
{ | |
[K in Exclude<keyof T, PartielKeys>]: T[K]; | |
}; |
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
export const useStableCallback = <T extends (...args: any[]) => any>(cb: T): T => { | |
const cbRef = useRef(cb); | |
cbRef.current = cb; | |
return useCallback( | |
<T>((...args) => { | |
return cbRef.current?.(...args); | |
}), | |
[], | |
); | |
}; |
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
/** | |
* some insane hack, just want to avoid using expensive parser. | |
*/ | |
export function getFreeVariables(expr:string, knownSymbols:Record<string,unknown>){ | |
const freeVariables = new Set<string>(); | |
//eslint-disable-next-line | |
const anyThingPrimitive = ()=>{}; |
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 webpack from "webpack"; | |
import * as ForkTsChecker from "fork-ts-checker-webpack-plugin"; | |
import * as FriendlyError from "friendly-errors-webpack-plugin"; | |
import { debounce } from "lodash"; | |
const forkTsStack: Array<{ | |
type: "info" | "error" | "warn"; | |
message: string; | |
}> = []; |
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
{"lastUpload":"2020-04-06T02:47:14.995Z","extensionVersion":"v3.4.3"} |
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
export default function textEllipse( | |
text: string, | |
style: ConstructorParameters<typeof TextStyle>[0], | |
maxLines: number = Infinity, | |
) { | |
if (maxLines === Infinity) { | |
return text; | |
} | |
const { wordWrapWidth = 750, breakWords } = style!; | |
const pixiStyle = new TextStyle(style); |