Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d9393ee
Add Fragment fiber type
sebmarkbage Sep 13, 2016
e8c1cb4
Add Text node types
sebmarkbage Sep 14, 2016
d7322d8
Silence Fiber warning when the feature flag is on
sebmarkbage Sep 13, 2016
e05ab67
Fix MultiChild tests so they work with Fiber
sebmarkbage Sep 13, 2016
8c7409b
Add comment about bug in yields
sebmarkbage Sep 15, 2016
4ed67f1
Enable text updates in ReactNoop
sebmarkbage Sep 19, 2016
dff0faf
Fiber child reconciliation
sebmarkbage Sep 20, 2016
51f2bf9
Add index field to each fiber
sebmarkbage Sep 21, 2016
bcbceae
Don't track side-effects unless needed
sebmarkbage Sep 21, 2016
c49a91c
Fast path for create child
sebmarkbage Oct 4, 2016
be0acf8
Deletion tracking
sebmarkbage Oct 4, 2016
76725fe
Tag the fiber with the kind of side-effect that was applied to it
sebmarkbage Oct 4, 2016
86e854e
Append deletions to the effect list
sebmarkbage Oct 4, 2016
eabed69
Move child updates to use the reconciled effects
sebmarkbage Oct 5, 2016
31ca1e7
Remove beginWork shortcut
sebmarkbage Oct 6, 2016
0262e70
Reset effect list when we recompute children
sebmarkbage Oct 7, 2016
f3d7116
Always override priority level when visiting children
sebmarkbage Oct 7, 2016
40989f8
Call componentWillUnmount during deletion phase
sebmarkbage Oct 7, 2016
8360088
Fire componentDidMount/componentDidUpdate life-cycles
sebmarkbage Oct 7, 2016
48cf81c
Resolve ref callbacks
sebmarkbage Oct 7, 2016
8721ec1
Invoke all null ref calls before any new ref calls
sebmarkbage Oct 7, 2016
d9efde7
Fix resuming bug
sebmarkbage Oct 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import type { HostChildren } from 'ReactFiberReconciler';

var ReactFiberReconciler = require('ReactFiberReconciler');
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');

var warning = require('warning');

Expand All @@ -23,13 +24,14 @@ type DOMContainerElement = Element & { _reactRootContainer: ?Object };
type Container = Element;
type Props = { };
type Instance = Element;
type TextInstance = Text;

function recursivelyAppendChildren(parent : Element, child : HostChildren<Instance>) {
function recursivelyAppendChildren(parent : Element, child : HostChildren<Instance | TextInstance>) {
if (!child) {
return;
}
/* $FlowFixMe: Element should have this property. */
if (child.nodeType === 1) {
/* $FlowFixMe: Element and Text should have this property. */
if (child.nodeType === 1 || child.nodeType === 3) {
/* $FlowFixMe: Refinement issue. I don't know how to express different. */
parent.appendChild(child);
} else {
Expand All @@ -43,15 +45,17 @@ function recursivelyAppendChildren(parent : Element, child : HostChildren<Instan

var DOMRenderer = ReactFiberReconciler({

updateContainer(container : Container, children : HostChildren<Instance>) : void {
updateContainer(container : Container, children : HostChildren<Instance | TextInstance>) : void {
// TODO: Containers should update similarly to other parents.
container.innerHTML = '';
recursivelyAppendChildren(container, children);
},

createInstance(type : string, props : Props, children : HostChildren<Instance>) : Instance {
createInstance(type : string, props : Props, children : HostChildren<Instance | TextInstance>) : Instance {
const domElement = document.createElement(type);
recursivelyAppendChildren(domElement, children);
if (typeof props.children === 'string') {
if (typeof props.children === 'string' ||
typeof props.children === 'number') {
domElement.textContent = props.children;
}
return domElement;
Expand All @@ -60,22 +64,36 @@ var DOMRenderer = ReactFiberReconciler({
prepareUpdate(
domElement : Instance,
oldProps : Props,
newProps : Props,
children : HostChildren<Instance>
newProps : Props
) : boolean {
return true;
},

commitUpdate(domElement : Instance, oldProps : Props, newProps : Props, children : HostChildren<Instance>) : void {
domElement.innerHTML = '';
recursivelyAppendChildren(domElement, children);
if (typeof newProps.children === 'string') {
commitUpdate(domElement : Instance, oldProps : Props, newProps : Props) : void {
if (typeof newProps.children === 'string' ||
typeof newProps.children === 'number') {
domElement.textContent = newProps.children;
}
},

deleteInstance(instance : Instance) : void {
// Noop
createTextInstance(text : string) : TextInstance {
return document.createTextNode(text);
},

commitTextUpdate(textInstance : TextInstance, oldText : string, newText : string) : void {
textInstance.nodeValue = newText;
},

appendChild(parentInstance : Instance, child : Instance | TextInstance) : void {
parentInstance.appendChild(child);
},

insertBefore(parentInstance : Instance, child : Instance | TextInstance, beforeChild : Instance | TextInstance) : void {
parentInstance.insertBefore(child, beforeChild);
},

removeChild(parentInstance : Instance, child : Instance | TextInstance) : void {
parentInstance.removeChild(child);
},

scheduleAnimationCallback: window.requestAnimationFrame,
Expand All @@ -87,8 +105,9 @@ var DOMRenderer = ReactFiberReconciler({
var warned = false;

function warnAboutUnstableUse() {
// Ignore this warning is the feature flag is turned on. E.g. for tests.
warning(
warned,
warned || ReactDOMFeatureFlags.useFiber,
'You are using React DOM Fiber which is an experimental renderer. ' +
'It is likely to have bugs, breaking changes and is unsupported.'
);
Expand Down
69 changes: 55 additions & 14 deletions src/renderers/noop/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ var scheduledAnimationCallback = null;
var scheduledDeferredCallback = null;

const TERMINAL_TAG = 99;
const TEXT_TAG = 98;

type Container = { rootID: number, children: Array<Instance> };
type Container = { rootID: number, children: Array<Instance | TextInstance> };
type Props = { prop: any };
type Instance = { tag: 99, type: string, id: number, children: Array<Instance>, prop: any };
type Instance = { tag: 99, type: string, id: number, children: Array<Instance | TextInstance>, prop: any };
type TextInstance = { tag: 98, text: string };

var instanceCounter = 0;

function recursivelyAppendChildren(flatArray : Array<Instance>, child : HostChildren<Instance>) {
function recursivelyAppendChildren(flatArray : Array<Instance | TextInstance>, child : HostChildren<Instance | TextInstance>) {
if (!child) {
return;
}
if (child.tag === TERMINAL_TAG) {
if (child.tag === TERMINAL_TAG || child.tag === TEXT_TAG) {
flatArray.push(child);
} else {
let node = child;
Expand All @@ -53,19 +55,19 @@ function recursivelyAppendChildren(flatArray : Array<Instance>, child : HostChil
}
}

function flattenChildren(children : HostChildren<Instance>) {
function flattenChildren(children : HostChildren<Instance | TextInstance>) {
const flatArray = [];
recursivelyAppendChildren(flatArray, children);
return flatArray;
}

var NoopRenderer = ReactFiberReconciler({

updateContainer(containerInfo : Container, children : HostChildren<Instance>) : void {
updateContainer(containerInfo : Container, children : HostChildren<Instance | TextInstance>) : void {
containerInfo.children = flattenChildren(children);
},

createInstance(type : string, props : Props, children : HostChildren<Instance>) : Instance {
createInstance(type : string, props : Props, children : HostChildren<Instance | TextInstance>) : Instance {
const inst = {
tag: TERMINAL_TAG,
id: instanceCounter++,
Expand All @@ -79,16 +81,51 @@ var NoopRenderer = ReactFiberReconciler({
return inst;
},

prepareUpdate(instance : Instance, oldProps : Props, newProps : Props, children : HostChildren<Instance>) : boolean {
prepareUpdate(instance : Instance, oldProps : Props, newProps : Props) : boolean {
return true;
},

commitUpdate(instance : Instance, oldProps : Props, newProps : Props, children : HostChildren<Instance>) : void {
instance.children = flattenChildren(children);
commitUpdate(instance : Instance, oldProps : Props, newProps : Props) : void {
instance.prop = newProps.prop;
},

deleteInstance(instance : Instance) : void {
createTextInstance(text : string) : TextInstance {
var inst = { tag: TEXT_TAG, text : text };
// Hide from unit tests
Object.defineProperty(inst, 'tag', { value: inst.tag, enumerable: false });
return inst;
},

commitTextUpdate(textInstance : TextInstance, oldText : string, newText : string) : void {
textInstance.text = newText;
},

appendChild(parentInstance : Instance, child : Instance | TextInstance) : void {
const index = parentInstance.children.indexOf(child);
if (index !== -1) {
parentInstance.children.splice(index, 1);
}
parentInstance.children.push(child);
},

insertBefore(parentInstance : Instance, child : Instance | TextInstance, beforeChild : Instance | TextInstance) : void {
const index = parentInstance.children.indexOf(child);
if (index !== -1) {
parentInstance.children.splice(index, 1);
}
const beforeIndex = parentInstance.children.indexOf(beforeChild);
if (beforeIndex === -1) {
throw new Error('This child does not exist.');
}
parentInstance.children.splice(beforeIndex, 0, child);
},

removeChild(parentInstance : Instance, child : Instance | TextInstance) : void {
const index = parentInstance.children.indexOf(child);
if (index === -1) {
throw new Error('This child does not exist.');
}
parentInstance.children.splice(index, 1);
},

scheduleAnimationCallback(callback) {
Expand Down Expand Up @@ -166,11 +203,15 @@ var ReactNoop = {
bufferedLog.push(...args, '\n');
}

function logHostInstances(children: Array<Instance>, depth) {
function logHostInstances(children: Array<Instance | TextInstance>, depth) {
for (var i = 0; i < children.length; i++) {
var child = children[i];
log(' '.repeat(depth) + '- ' + child.type + '#' + child.id);
logHostInstances(child.children, depth + 1);
if (child.tag === TEXT_TAG) {
log(' '.repeat(depth) + '- ' + child.text);
} else {
log(' '.repeat(depth) + '- ' + child.type + '#' + child.id);
logHostInstances(child.children, depth + 1);
}
}
}
function logContainer(container : Container, depth) {
Expand Down
Loading