Skip to content

Instantly share code, notes, and snippets.

View iShawnWang's full-sized avatar
🤗
2333

Shawn Wang iShawnWang

🤗
2333
View GitHub Profile
@iShawnWang
iShawnWang / vtrack.vue
Last active November 1, 2023 07:26
v-track
// Sample Usage
<template>
<button v-track="xxxEvent" />
<input v-track="xxxEvent" />
<input v-track="() => new Date().getTime()" />
</template>
<script>
// v-track directive
Vue.directive("track", {
@iShawnWang
iShawnWang / launch.json
Last active May 8, 2023 05:55
VSCode + tsx + Auto Attach Debugger : https://github.com/esbuild-kit/tsx
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run current script",
"runtimeExecutable": "npx",
"runtimeArgs": ["tsx"],
"program": "${file}",

Track Color Platte

Assign Track Color by Frequencies

Track Color
Kick #FF364D #FF364D
Snare #1AA1FF #1AA1FF
Clap #D68EA4 #D68EA4
Open HiHat #03C539 #03C539
@iShawnWang
iShawnWang / immer.js
Created April 28, 2022 09:40
ES6 Proxy Immer.js
const PROXY_STATE = Symbol('immer-proxy-state')
class State {
srcObj
copy
touched
parent
constructor(srcObj, parent) {
this.srcObj = srcObj
@iShawnWang
iShawnWang / optional.js
Last active April 28, 2022 09:13
ES6 Proxy Optional Chain
const optional = (srcObj) => {
return new Proxy(() => {}, {
apply: () => {
return srcObj
},
get: (__, prop) => {
if (srcObj && srcObj.hasOwnProperty(prop)) {
return optional(srcObj[prop])
} else {
return optional(undefined)
@iShawnWang
iShawnWang / Example.tsx
Last active October 31, 2021 05:19
Use Ant Design Modal in Imperative Mode
import {ModalProvider, ModalContext, Modalman} from './Modalman'
import {useContext} from 'react'
import {Modal} from 'antd'
// App.tsx
// export default () => {
// return <ModalProvider><App /><ModalProvider>
// }
export default () => {
@iShawnWang
iShawnWang / analytics.js
Created August 5, 2021 06:27 — forked from zmmbreeze/analytics.js
GA的源码 analytics.js
(function() {
/**
* 记录方法使用情况的类
* @param {Array.<boolean>} umMap 初始的使用情况
*/
var UsageManager = function(umMap) {
this.umMap = umMap || [];
};
/**
* 记录新的使用情况
@iShawnWang
iShawnWang / enum_demo.ts
Created November 25, 2019 01:57
Typescript 枚举 扩展
interface Enum {
[id: number]: string
}
const getEnumKeys = (e: Enum) => {
return Object.keys(e)
.map(key => e[key])
.filter(value => typeof value === 'string') as string[]
}
@iShawnWang
iShawnWang / useRouter.ts
Last active July 27, 2019 05:52
react-router backward hooks, support react-router 4.x | 5.x
import { __RouterContext as RouterContext, RouteComponentProps } from 'react-router'
import { useContext, useMemo, useCallback } from 'react'
import qs from 'qs'
import { Location } from 'history'
interface ParsedQuery {
[whatever: string]: any
}
export const useRouter = <T>(): RouteComponentProps<T> =>