Skip to content

Instantly share code, notes, and snippets.

View Codennnn's full-sized avatar

LeoKu Codennnn

View GitHub Profile
@Codennnn
Codennnn / commit-emoji.md
Last active August 24, 2020 07:55
表情可用于 git 提交记录

🚀 代码优化 ⚡️ 功能优化 🏆 新增功能 🎨 样式调整 🔧 修改配置 🛠️ 修复BUG 🎉 发布版本 ⛔️ 删除文件 ✅ 添加组件 🔔 更新通知 ⚠️ 警告通知 ✔️ 同步代码

更多 Emoji 请查看:https://twemoji.maxcdn.com/2/test/preview.html

@Codennnn
Codennnn / Tutorial.md
Last active April 15, 2022 07:48
Windows Terminal 使用教程

美化

安装主题

执行以下命令安装posh-git和oh-my-posh两个模块,遇到提示选y确认即可

Install-Module posh-git -Scope CurrentUser 
Install-Module oh-my-posh -Scope CurrentUser

新增配置文件

@Codennnn
Codennnn / scroll-bar.css
Last active April 24, 2022 08:09
浏览器滚动条样式
/** ========== 滚动条样式 ========== */
::-webkit-scrollbar {
width: 12px !important;
height: 12px !important;
background-color: transparent;
}
::-webkit-scrollbar-thumb {
background-color: rgba(116 120 141 / 0.22) !important;
@Codennnn
Codennnn / type.ts
Last active March 19, 2022 11:41
只对某些属性设置为可选
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
// usage:
interface A {
requireX: string
requireY: string
requireZ: string
}
@Codennnn
Codennnn / XxxContext.tsx
Last active March 19, 2022 11:41
react context 的数据状态管理
import { createContext, useContext, useEffect, useState } from 'react';
const XxxContext = createContext({});
export function XxxContextProvider(props: { children: React.ReactNode }) {
const [state, setState] = useState();
const value = { state, setState };
return <XxxContext.Provider value={value}>{props.children}</XxxContext.Provider>;
import type { FormInstance } from 'antd';
import { Button, Form, Input, Popconfirm, Table } from 'antd';
import React, { useContext, useEffect, useRef, useState } from 'react';
const EditableContext = React.createContext<FormInstance | null>(null);
const EditableRow = ({ index, ...props }: { index: number; [x: string]: any }) => {
const [form] = Form.useForm();
return (
export function highlightJSON(json: string): string {
if (!json) {
return ''
}
if (typeof json !== 'string') {
json = JSON.stringify(json, undefined, 2)
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
/**
* 创建表单 shouldUpdate 函数的简易工具方法
*
* @param namePath - 要响应变化的表单字段,路径格式与调用 Form.getFieldValue 方法的传参一致
*/
export function shouldFormItemUpdate<Values>(
namePath: string | (string | number)[]
): (...value: [Values, Values]) => boolean {
const shouldUpdate = (...value: [Values, Values]) => {
const [prevValue, curValue] = value;
@Codennnn
Codennnn / useJitRef.ts
Last active May 30, 2022 03:47
两种比较好的方式让 useRef 按需初始值,适用于有条件地调用 ref 或者生成初始值的花销很大的情景。代码来源:https://blog.thoughtspile.tech/2021/11/30/lazy-useref/。
const none = Symbol('lazyRef.Uninitialized')
export default useJitRef(init) {
const value = useRef(none)
const ref = useLazyRef(() => ({
get current() {
if (value.current === none) {
value.current = init()
}
return value.current
/**
* RuntimeGlobalsChecker
*
* You can use this utility to quickly check what variables have been added (or
* leaked) to the global window object at runtime (by JavaScript code).
* By running this code, the globals checker itself is attached as a singleton
* to the window object as "__runtimeGlobalsChecker__".
* You can check the runtime globals programmatically at any time by invoking
* "window.__runtimeGlobalsChecker__.getRuntimeGlobals()".
*