Skip to content

Instantly share code, notes, and snippets.

View githubxiaowen's full-sized avatar
💭
I may be slow to respond.

萧文 githubxiaowen

💭
I may be slow to respond.
  • Beijing China
View GitHub Profile
@githubxiaowen
githubxiaowen / scheduleRootUpdate.js
Created September 14, 2019 04:58
React-scheduleRootUpdate
function scheduleRootUpdate(
current: Fiber,
element: ReactNodeList,
expirationTime: ExpirationTime,
suspenseConfig: null | SuspenseConfig,
) {
const update = createUpdate(expirationTime, suspenseConfig);
update.payload = {element};
@githubxiaowen
githubxiaowen / updateContainer.js
Created September 13, 2019 14:43
React-updateContainer
export function updateContainer(
element: ReactNodeList,
container: OpaqueRoot,
parentComponent: ?React$Component<any, any>,
callback: ?Function,
): ExpirationTime {
const current = container.current;
const currentTime = requestCurrentTime();
const suspenseConfig = requestCurrentSuspenseConfig();
const expirationTime = computeExpirationForFiber(
@githubxiaowen
githubxiaowen / legacyRenderSubtreeIntoContainer.js
Created September 13, 2019 13:36
React-legacyRenderSubtreeIntoContainer
function legacyRenderSubtreeIntoContainer(
parentComponent: ?React$Component<any, any>,
children: ReactNodeList,
container: DOMContainer,
forceHydrate: boolean,
callback: ?Function,
) {
let root;
let fiberRoot;
root = container._reactRootContainer = legacyCreateRootFromDOMContainer(
@githubxiaowen
githubxiaowen / React-ReactElement.js
Created September 13, 2019 13:15
React-ReactElemen
const ReactElement = function(type, key, ref, self, source, owner, props) {
const element = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: REACT_ELEMENT_TYPE,
// 内置属性
type: type,
key: key,
ref: ref,
props: props,
@githubxiaowen
githubxiaowen / React-createElement.js
Last active September 13, 2019 13:15
React-createElement
export function createElement(type, config, children) {
let propName;
// 这里的type可以是HTML标签字符串,也可以是一个函数,或者一个ReactClass(本质上还是一个函数)
// Reserved names are extracted
const props = {};
let key = null;
let ref = null;
let self = null;
@githubxiaowen
githubxiaowen / simpleReact.js
Last active September 13, 2019 13:00
reactjs-snippets
function App() {
return React.createElement('h1', null, ['Hello World'])
}
ReactDOM.render(React.createElement(App), document.querySelector('#root'));
@githubxiaowen
githubxiaowen / v8.md
Created August 13, 2019 04:58 — forked from kevincennis/v8.md
V8 Installation and d8 shell usage

Installing V8 on a Mac

Prerequisites

  • Install Xcode (Avaliable on the Mac App Store)
  • Install Xcode Command Line Tools (Preferences > Downloads)
  • Install depot_tools
    • git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
    • sudo nano ~/.bash_profile
  • Add export PATH=/path/to/depot_tools:"$PATH" (it's important that depot_tools comes first here)
{
// 直接debug当前文件
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
@githubxiaowen
githubxiaowen / rxjs.js
Last active January 26, 2019 08:12
tiny-rxjs
// Subscriber 订阅者,持有next,error,complete方法
// Subscribable 可订阅者,持有subscribe方法
// Subscription 订阅,用于绑定关系的模块 持有unsubscribe方法,即取消订阅后的回调逻辑
function pipeFromArray(fns) {
if(!fns) return () => {}
if(fns.length === 1) return fns[0]
return input$ => fns.reduce((prev, fn) => fn(prev), input$)
}
class Observable {