Skip to content

Instantly share code, notes, and snippets.

View TotooriaHyperion's full-sized avatar

Elaina Cherudim TotooriaHyperion

  • Bytedance Inc.
  • China Shanghai
View GitHub Profile
@TotooriaHyperion
TotooriaHyperion / reactBatch.ts
Last active February 20, 2021 09:19
react - rxjs & reactive
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({
@TotooriaHyperion
TotooriaHyperion / type.ts
Created October 20, 2020 09:59
PartPartial
type PartPartial<T, PartielKeys extends keyof T> = Partial<T> &
{
[K in Exclude<keyof T, PartielKeys>]: T[K];
};
@TotooriaHyperion
TotooriaHyperion / useStableCallback.tsx
Created October 20, 2020 06:43
useStableCallback
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);
}),
[],
);
};
@TotooriaHyperion
TotooriaHyperion / get_free_vars.ts
Created August 28, 2020 07:06 — forked from buhichan/get_free_vars.ts
js get free variables hack
/**
* 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 = ()=>{};
@TotooriaHyperion
TotooriaHyperion / example.ts
Created April 6, 2020 08:11
using FriendlyErrorsWebpackPlugin with ForkTsChecker
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;
}> = [];
@TotooriaHyperion
TotooriaHyperion / cloudSettings
Created April 6, 2020 02:46
hyperion's vscode config
{"lastUpload":"2020-04-06T02:47:14.995Z","extensionVersion":"v3.4.3"}
@TotooriaHyperion
TotooriaHyperion / textEllipse.ts
Last active December 11, 2019 09:03
pixijs wordWrap and ellipse, support Asian charactors(breakWord = true)
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);