Skip to content

Commit

Permalink
Restore DOM selection and suppress events
Browse files Browse the repository at this point in the history
This makes Draft mostly work.
  • Loading branch information
sophiebits committed Nov 23, 2016
1 parent c7129ce commit 5d037a0
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 16 deletions.
3 changes: 0 additions & 3 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ src/renderers/dom/shared/eventPlugins/__tests__/SimpleEventPlugin-test.js
* should not forward clicks when it becomes disabled
* should work correctly if the listener is changed

src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js
* should control a value in reentrant events

src/renderers/dom/stack/client/__tests__/ReactDOM-test.js
* throws in render() if the mount callback is not a function
* throws in render() if the update callback is not a function
Expand Down
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMIframe-test.js

src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js
* should properly control a value even if no event listener exists
* should control a value in reentrant events
* should control values in reentrant events with different targets
* should display `defaultValue` of number 0
* only assigns defaultValue if it changes
Expand Down
22 changes: 17 additions & 5 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@ import type { Fiber } from 'ReactFiber';
import type { HostChildren } from 'ReactFiberReconciler';
import type { ReactNodeList } from 'ReactTypes';

var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
var ReactControlledComponent = require('ReactControlledComponent');
var ReactDOMComponentTree = require('ReactDOMComponentTree');
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
var ReactDOMFiberComponent = require('ReactDOMFiberComponent');
var ReactDOMInjection = require('ReactDOMInjection');
var ReactFiberReconciler = require('ReactFiberReconciler');
var ReactInputSelection = require('ReactInputSelection');
var ReactInstanceMap = require('ReactInstanceMap');
var ReactPortal = require('ReactPortal');

var findDOMNode = require('findDOMNode');
var invariant = require('invariant');
var warning = require('warning');

ReactDOMInjection.inject();
ReactControlledComponent.injection.injectFiberControlledHostComponent(
ReactDOMFiberComponent
);

var {
createElement,
setInitialProperties,
Expand All @@ -55,6 +52,7 @@ type Container = Element;
type Props = { className ?: string };
type Instance = Element;
type TextInstance = Text;
type EnvironmentState = {| eventsEnabled : boolean, selectionInformation : mixed |};

function recursivelyAppendChildren(parent : Element, child : HostChildren<Instance | TextInstance>) {
if (!child) {
Expand All @@ -75,6 +73,20 @@ function recursivelyAppendChildren(parent : Element, child : HostChildren<Instan

var DOMRenderer = ReactFiberReconciler({

prepareForCommit() : EnvironmentState {
var eventsEnabled = ReactBrowserEventEmitter.isEnabled();
ReactBrowserEventEmitter.setEnabled(false);
return {
eventsEnabled,
selectionInformation: ReactInputSelection.getSelectionInformation(),
};
},

resetAfterCommit(state : EnvironmentState) : void {
ReactInputSelection.restoreSelection(state.selectionInformation);
ReactBrowserEventEmitter.setEnabled(state.eventsEnabled);
},

updateContainer(container : Container, children : HostChildren<Instance | TextInstance>) : void {
// TODO: Containers should update similarly to other parents.
container.innerHTML = '';
Expand Down
6 changes: 6 additions & 0 deletions src/renderers/noop/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ var NoopRenderer = ReactFiberReconciler({
scheduledDeferredCallback = callback;
},

prepareForCommit() : void {
},

resetAfterCommit(state : void) : void {
},

});

var rootContainers = new Map();
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/shared/fiber/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ var {
var ReactCurrentOwner = require('ReactCurrentOwner');
var ReactFiberClassComponent = require('ReactFiberClassComponent');

module.exports = function<T, P, I, TI, C>(
config : HostConfig<T, P, I, TI, C>,
module.exports = function<T, P, I, TI, C, ES>(
config : HostConfig<T, P, I, TI, C, ES>,
scheduleUpdate : (fiber: Fiber) => void
) {

Expand Down
4 changes: 2 additions & 2 deletions src/renderers/shared/fiber/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var {
Callback,
} = require('ReactTypeOfSideEffect');

module.exports = function<T, P, I, TI, C>(
config : HostConfig<T, P, I, TI, C>,
module.exports = function<T, P, I, TI, C, ES>(
config : HostConfig<T, P, I, TI, C, ES>,
trapError : (failedFiber : Fiber, error: Error, isUnmounting : boolean) => void
) {

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shared/fiber/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var {
Callback,
} = ReactTypeOfSideEffect;

module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
module.exports = function<T, P, I, TI, C, ES>(config : HostConfig<T, P, I, TI, C, ES>) {

const createInstance = config.createInstance;
const createTextInstance = config.createTextInstance;
Expand Down
7 changes: 5 additions & 2 deletions src/renderers/shared/fiber/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type HostChildren<I> = null | void | I | HostChildNode<I>;

type OpaqueNode = Fiber;

export type HostConfig<T, P, I, TI, C> = {
export type HostConfig<T, P, I, TI, C, ES> = {

// TODO: We don't currently have a quick way to detect that children didn't
// reorder so we host will always need to check the set. We should make a flag
Expand All @@ -66,6 +66,9 @@ export type HostConfig<T, P, I, TI, C> = {
scheduleAnimationCallback(callback : () => void) : void,
scheduleDeferredCallback(callback : (deadline : Deadline) => void) : void,

prepareForCommit() : ES,
resetAfterCommit(state : ES) : void,

useSyncScheduling ?: boolean,
};

Expand All @@ -91,7 +94,7 @@ getContextForSubtree._injectFiber(function(fiber : Fiber) {
return processChildContext(fiber, findCurrentUnmaskedContext(fiber));
});

module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) : Reconciler<C, I, TI> {
module.exports = function<T, P, I, TI, C, ES>(config : HostConfig<T, P, I, TI, C, ES>) : Reconciler<C, I, TI> {

var {
scheduleWork,
Expand Down
6 changes: 5 additions & 1 deletion src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type TrappedError = {
error: any,
};

module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
module.exports = function<T, P, I, TI, C, ES>(config : HostConfig<T, P, I, TI, C, ES>) {
const { beginWork } = ReactFiberBeginWork(config, scheduleUpdate);
const { completeWork } = ReactFiberCompleteWork(config);
const { commitInsertion, commitDeletion, commitWork, commitLifeCycles } =
Expand Down Expand Up @@ -161,6 +161,8 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
}

function commitAllWork(finishedWork : Fiber) {
const environmentState = config.prepareForCommit();

// Commit all the side-effects within a tree.
// First, we'll perform all the host insertions, updates, deletions and
// ref unmounts.
Expand Down Expand Up @@ -238,6 +240,8 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {

// The task work includes batched updates and error handling.
performTaskWork();

config.resetAfterCommit(environmentState);
}

function resetWorkPriority(workInProgress : Fiber) {
Expand Down

0 comments on commit 5d037a0

Please sign in to comment.