Skip to content

Instantly share code, notes, and snippets.

View Jokcy's full-sized avatar
🎯
Focusing

JokcyLou Jokcy

🎯
Focusing
View GitHub Profile
@Jokcy
Jokcy / effectTag.js
Created November 21, 2018 08:20
React effect tags list 中文注释
// 没有任何副作用
export const NoEffect = /* */ 0b00000000000
// 用来通知在开发者工具这次更新中当前组件有更新
export const PerformedWork = /* */ 0b00000000001
// 需要挂载到DOM上
export const Placement = /* */ 0b00000000010
// 需要执行生命周期方法、
export const Update = /* */ 0b00000000100
// 同时拥有`Placemenet`和`Update`副作用
@Jokcy
Jokcy / scheduler-global-valiables.js
Last active November 16, 2018 11:30
React Fiber Scheduler global variables
// 现在是否有任务正在渲染,这个值在`reader`和`commit`阶段都是`true`
isWorking: boolean
// 现在是否有任务正在`commit`,在`commit`阶段为`true`
isCommitting: boolean
// 在`renderRoot`开始时设置为当前渲染的`root`
nextRoot: FiberRoot
// 在`renderRoot`开始的时候设置为当前任务的`expirationTime`
@Jokcy
Jokcy / ReactFiberExpirationTime.js
Created November 12, 2018 02:41
How React calculate expirationTime
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt';
@Jokcy
Jokcy / fiber.js
Created November 8, 2018 09:30
React Fiber 中文注释版
// Fiber对应一个组件需要被处理或者已经处理了,一个组件可以有一个或者多个Fiber
type Fiber = {|
// 标记不同的组件类型
tag: WorkTag,
// ReactElement里面的key
key: null | string,
// ReactElement.type,也就是我们调用`createElement`的第一个参数
elementType: any,
@Jokcy
Jokcy / fiber-root.js
Last active November 8, 2018 04:14
React FiberRoot 中文注释版
type BaseFiberRootProperties = {|
// root节点,render方法接收的第二个参数
containerInfo: any,
// 只有在持久更新中会用到,也就是不支持增量更新的平台,react-dom不会用到
pendingChildren: any,
// 当前应用对应的Fiber对象,是Root Fiber
current: Fiber,
// 一下的优先级是用来区分
// 1) 没有提交(committed)的任务
@Jokcy
Jokcy / finishHooks.js
Created October 30, 2018 06:28
react hooks finishHooks
function finishHooks(Component, props, children, refOrContext) {
// This must be called after every function component to prevent hooks from
// being used in classes.
while (didScheduleRenderPhaseUpdate) {
// Updates were scheduled during the render phase. They are stored in
// the `renderPhaseUpdates` map. Call the component again, reusing the
// work-in-progress hooks and applying the additional updates on top. Keep
// restarting until no more updates are scheduled.
didScheduleRenderPhaseUpdate = false;
@Jokcy
Jokcy / useReducer.js
Created October 30, 2018 05:58
react hooks useReducer
function useReducer(reducer, initialState, initialAction) {
currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber();
workInProgressHook = createWorkInProgressHook();
var queue = workInProgressHook.queue;
if (queue !== null) {
// Already have a queue, so this is an update.
if (isReRender) {
// This is a re-render. Apply the new render phase updates to the previous
var _dispatch2 = queue.dispatch;
if (renderPhaseUpdates !== null) {
@Jokcy
Jokcy / bash
Last active January 24, 2019 05:39
generate-openssl-cert
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -keyout localhost-privkey.pem -out localhost-cert.pem
@Jokcy
Jokcy / salt-password.js
Created May 7, 2018 08:17
nodejs salt password
import crypto from 'crypto'
const genRandomString = (length) => {
return crypto.randomBytes(Math.ceil(length / 2))
.toString('hex')
.slice(0, length)
}
const sha512 = (password, salt) => {
const hash = crypto.createHmac('sha512', salt)
@Jokcy
Jokcy / controlled-input.jsx
Created July 24, 2017 06:41
vue controlled input
export default {
props: {
value: {
type: [String, Number],
default: '',
},
},
data() {