Skip to content

Instantly share code, notes, and snippets.

View Jokcy's full-sized avatar
🎯
Focusing

JokcyLou Jokcy

🎯
Focusing
View GitHub Profile
@Jokcy
Jokcy / vue-ref.js
Last active August 28, 2020 08:58
vue3 ref problem
const CompB = {
setup(props) {
const handleChange = (e) => {
props.value.name = e.target.value
props.onChange(props.value)
}
return () => {
@Jokcy
Jokcy / demo.js
Last active August 11, 2020 05:52
props defination in ts
const props: WhatType = {
a: {
type: Object as PropType<MyInterface>
}
}
const CompA = defineComponent({
props: props,
setup(props) {
return () => <div>{props.a.name}</div>
@Jokcy
Jokcy / babel-plugin-transform-taro-hooks.js
Last active August 12, 2019 06:45
把从@tarojs/taro引入的hooks API转变成从nervjs引入
module.exports = function(babel) {
const t = babel.types
const hookTest = /^use[A-Z]/
let hooksImport = new Set()
return {
name: 'babel-plugin-transform-taro-hooks',
visitor: {
@Jokcy
Jokcy / taro-redux-hooks-h5.js
Created July 30, 2019 02:25
taro的redux在h5端不支持hooks,可以用这段代码来兼容
import Taro, { useEffect, useState, useRef } from '@tarojs/taro'
import * as tredux from '@tarojs/redux'
const env = Taro.getEnv()
const { WEB } = Taro.ENV_TYPE
let store
const refEquality = (a, b) => a === b
@Jokcy
Jokcy / newContext.js
Created December 12, 2018 07:54
react next context readContext and ...
export function propagateContextChange(
workInProgress: Fiber,
context: ReactContext<mixed>,
changedBits: number,
renderExpirationTime: ExpirationTime,
): void {
let fiber = workInProgress.child;
if (fiber !== null) {
// Set the return pointer of the child to the work-in-progress fiber.
fiber.return = workInProgress;
@Jokcy
Jokcy / Update.js
Created December 5, 2018 08:49
React Update & UpdateQueue
export type Update<State> = {
// 更新的过期时间
expirationTime: ExpirationTime,
// export const UpdateState = 0;
// export const ReplaceState = 1;
// export const ForceUpdate = 2;
// export const CaptureUpdate = 3;
// 指定更新的类型,值为以上几种
tag: 0 | 1 | 2 | 3,
@Jokcy
Jokcy / ReactSideEffects.js
Created December 3, 2018 09:07
react side effects
/**
* 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
*/
export type SideEffectTag = number;
@Jokcy
Jokcy / ReactWorkTag.js
Created December 3, 2018 09:04
react work tah
export const FunctionComponent = 0;
export const ClassComponent = 1;
export const IndeterminateComponent = 2; // Before we know whether it is function or class
export const HostRoot = 3; // Root of a host tree. Could be nested inside another node.
export const HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
export const HostComponent = 5;
export const HostText = 6;
export const Fragment = 7;
export const Mode = 8;
export const ContextConsumer = 9;
@Jokcy
Jokcy / compiler.js
Last active November 29, 2018 07:54
graphql compiler
const input1 = `User {
id,
name,
age
}`
const input2 = `User( age:21 ){
id,
name,
assigned Task( content: 'run' ): {
@Jokcy
Jokcy / bus.js
Last active November 27, 2018 08:57
面试题1
const listeners = {}
// 不是很理解第三条。。。
const bus = {
on(event, fun) {
let handler
let before
if (typeof fun === 'object' && fun.fn) {
handler = fun.fn