-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* @Author: chenjianfeng chenjianfeng93@163.com | ||
* @Date: 2023-11-07 23:33:32 | ||
* @Description: | ||
*/ | ||
import * as ReactDOM from './src/root' | ||
|
||
export default ReactDOM |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "react-dom", | ||
"version": "1.0.0", | ||
"description": "", | ||
"module": "index.ts", | ||
"dependencies": { | ||
"shared": "workspace:*", | ||
"react-reconciler": "workspace:*" | ||
}, | ||
"peerDependencies": { | ||
"react": "workspace:*" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* @Author: chenjianfeng chenjianfeng93@163.com | ||
* @Date: 2023-11-03 14:58:51 | ||
* @Description: | ||
*/ | ||
export type Container = Element | ||
export type Instance = Element | ||
|
||
// export const createInstance = (type: string, props: any): Instance => { | ||
export const createInstance = (type: string): Instance => { | ||
const element = document.createElement(type) | ||
return element | ||
} | ||
|
||
export const appendInitialChild = ( | ||
parent: Instance | Container, | ||
child: Instance | ||
) => { | ||
parent.appendChild(child) | ||
} | ||
|
||
export const createTextInstance = (content: string) => { | ||
return document.createTextNode(content) | ||
} | ||
|
||
export const appendChildToContainer = appendInitialChild |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* @Author: chenjianfeng chenjianfeng93@163.com | ||
* @Date: 2023-11-07 22:25:43 | ||
* @Description: | ||
*/ | ||
import { | ||
createContainer, | ||
updateContainer | ||
} from 'react-reconciler/src/fiberReconciler' | ||
import { Container } from './hostConfig' | ||
import { ReactElementType } from 'shared/ReactTypes' | ||
|
||
export const createRoot = (container: Container) => { | ||
const root = createContainer(container) | ||
|
||
return { | ||
render(element: ReactElementType) { | ||
updateContainer(element, root) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* @Author: chenjianfeng chenjianfeng93@163.com | ||
* @Date: 2023-11-07 16:04:55 | ||
* @Description: | ||
*/ | ||
import { Container, appendChildToContainer } from 'hostConfig' | ||
import { FiberNode, FiberRootNode } from './fiber' | ||
import { MutationMask, NoFlags, Placement } from './fiberFlags' | ||
import { HostComponent, HostRoot, HostText } from './workTags' | ||
|
||
export const commitMutationEffects = (finishedWork: FiberNode) => { | ||
let nextEffect = finishedWork | ||
|
||
while (nextEffect !== null) { | ||
const child = nextEffect.child | ||
if ( | ||
(nextEffect.subtreeFlags & MutationMask) !== NoFlags && | ||
child !== null | ||
) { | ||
nextEffect = child | ||
} else { | ||
up: while (nextEffect !== null) { | ||
commitMutationEffectsOnFiber(nextEffect) | ||
const sibling = nextEffect.sibling | ||
if (sibling !== null) { | ||
nextEffect = sibling | ||
break up | ||
} | ||
nextEffect = nextEffect.return! | ||
} | ||
} | ||
} | ||
} | ||
|
||
const commitMutationEffectsOnFiber = (finishedWork: FiberNode) => { | ||
const flags = finishedWork.flags | ||
if ((flags & Placement) !== NoFlags) { | ||
commitPlacement(finishedWork) | ||
// remove Placement from flags | ||
finishedWork.flags &= ~Placement | ||
} | ||
|
||
// update | ||
|
||
// childDelection | ||
} | ||
|
||
const commitPlacement = (finishedWork: FiberNode) => { | ||
// insert dom to parent's dom | ||
if (__DEV__) { | ||
console.warn('execute Placement operation') | ||
} | ||
|
||
const hostParent = getHostParent(finishedWork) | ||
if (hostParent) { | ||
appendPlacementNodeIntoContainer(finishedWork, hostParent) | ||
} | ||
} | ||
|
||
const getHostParent = (fiber: FiberNode): Container | null => { | ||
let parent = fiber.return | ||
while (parent) { | ||
const parentTag = parent.tag | ||
if (parentTag === HostComponent) { | ||
return parent.stateNode | ||
} | ||
if (parentTag === HostRoot) { | ||
return (parent.stateNode as FiberRootNode).container | ||
} | ||
parent = parent.return | ||
} | ||
if (__DEV__) { | ||
console.warn('can not find host parent') | ||
} | ||
|
||
return null | ||
} | ||
|
||
const appendPlacementNodeIntoContainer = ( | ||
finishedWork: FiberNode, | ||
hostParent: Container | ||
) => { | ||
if (finishedWork.tag === HostComponent || finishedWork.tag === HostText) { | ||
appendChildToContainer(hostParent, finishedWork.stateNode) | ||
return | ||
} | ||
const child = finishedWork.child | ||
if (child !== null) { | ||
appendPlacementNodeIntoContainer(child, hostParent) | ||
let sibling = child.sibling | ||
while (sibling !== null) { | ||
appendPlacementNodeIntoContainer(sibling, hostParent) | ||
sibling = sibling.sibling | ||
} | ||
} | ||
} |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.