Skip to content

Instantly share code, notes, and snippets.

Avatar
🍑
be sweet

Suyan suyanhanx

🍑
be sweet
View GitHub Profile
View hook-form.tsx
import * as React from "react"
import { BehaviorSubject } from 'rxjs';
const ERROR_DETAIL = Symbol("errors")
const HAS_ERROR = Symbol("has error")
const InternalSymbolKeys = [ERROR_DETAIL,HAS_ERROR]
enum FieldType {
arrayItem,
@suyanhanx
suyanhanx / resetVueData.ts
Created Apr 17, 2020
重置 Vue 组件的数据
View resetVueData.ts
/**
* 重置 Vue 组件的数据
* @param {Vue} instance
*/
export function resetVueData(instance: Vue): void {
Object.assign(instance.$data, (instance.$option.data as any).call(instance))
}
@suyanhanx
suyanhanx / get_free_vars.ts
Created Aug 27, 2020 — forked from buhichan/get_free_vars.ts
js get free variables hack
View get_free_vars.ts
/**
* 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 = ()=>{};
View ts-try-catch-promise-tuple.ts
/**
* 获取 promise 的 tuple
*
* @export
* @template T
* @template R
* @param promise 需要获取结果的 promise 对象
* @returns {(Promise<[R] | [null, T]>)}
*/