Skip to content

Commit

Permalink
Merge pull request #7248 from sebmarkbage/fibercleanup
Browse files Browse the repository at this point in the history
[Fiber] Various minor tweaks and a few big ones
(cherry picked from commit a8c8191)
  • Loading branch information
sebmarkbage authored and zpao committed Oct 3, 2016
1 parent bed4c05 commit 5a540f7
Show file tree
Hide file tree
Showing 14 changed files with 799 additions and 292 deletions.
12 changes: 11 additions & 1 deletion src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { HostChildren } from 'ReactFiberReconciler';

var ReactFiberReconciler = require('ReactFiberReconciler');

type DOMContainerElement = Element & { _reactRootContainer: Object };
type DOMContainerElement = Element & { _reactRootContainer: ?Object };

type Container = Element;
type Props = { };
Expand Down Expand Up @@ -92,6 +92,16 @@ var ReactDOM = {
}
},

unmountComponentAtNode(container : DOMContainerElement) {
const root = container._reactRootContainer;
if (root) {
// TODO: Is it safe to reset this now or should I wait since this
// unmount could be deferred?
container._reactRootContainer = null;
DOMRenderer.unmountContainer(root);
}
},

};

module.exports = ReactDOM;
25 changes: 17 additions & 8 deletions src/renderers/noop/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var scheduledLowPriCallback = null;
const TERMINAL_TAG = 99;

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

var instanceCounter = 0;

Expand All @@ -58,17 +58,16 @@ function flattenChildren(children : HostChildren<Instance>) {
var NoopRenderer = ReactFiberReconciler({

updateContainer(containerInfo : Container, children : HostChildren<Instance>) : void {
console.log('Update container #' + containerInfo.rootID);
containerInfo.children = flattenChildren(children);
},

createInstance(type : string, props : Props, children : HostChildren<Instance>) : Instance {
console.log('Create instance #' + instanceCounter);
const inst = {
tag: TERMINAL_TAG,
id: instanceCounter++,
type: type,
children: flattenChildren(children),
prop: props.prop,
};
// Hide from unit tests
Object.defineProperty(inst, 'tag', { value: inst.tag, enumerable: false });
Expand All @@ -77,17 +76,15 @@ var NoopRenderer = ReactFiberReconciler({
},

prepareUpdate(instance : Instance, oldProps : Props, newProps : Props, children : HostChildren<Instance>) : boolean {
console.log('Prepare for update on #' + instance.id);
return true;
},

commitUpdate(instance : Instance, oldProps : Props, newProps : Props, children : HostChildren<Instance>) : void {
console.log('Commit update on #' + instance.id);
instance.children = flattenChildren(children);
instance.prop = newProps.prop;
},

deleteInstance(instance : Instance) : void {
console.log('Delete #' + instance.id);
},

scheduleHighPriCallback(callback) {
Expand Down Expand Up @@ -170,9 +167,21 @@ var ReactNoop = {

function logFiber(fiber : Fiber, depth) {
console.log(
' '.repeat(depth) + '- ' + (fiber.type ? fiber.type.name || fiber.type : '[root]'),
' '.repeat(depth) + '- ' + (fiber.type ? fiber.type.name || fiber.type : '[root]'),
'[' + fiber.pendingWorkPriority + (fiber.pendingProps ? '*' : '') + ']'
);
const childInProgress = fiber.childInProgress;
if (childInProgress) {
if (childInProgress === fiber.child) {
console.log(' '.repeat(depth + 1) + 'ERROR: IN PROGRESS == CURRENT');
} else {
console.log(' '.repeat(depth + 1) + 'IN PROGRESS');
logFiber(childInProgress, depth + 1);
if (fiber.child) {
console.log(' '.repeat(depth + 1) + 'CURRENT');
}
}
}
if (fiber.child) {
logFiber(fiber.child, depth + 1);
}
Expand Down
Loading

0 comments on commit 5a540f7

Please sign in to comment.