Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions src/ReactARTFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ class Surface extends Component {

const ARTRenderer = ReactFiberReconciler({
appendChild(parentInstance, child) {
if (child.parentNode === parentInstance) {
child.eject();
}

child.inject(parentInstance);
},

Expand Down Expand Up @@ -450,7 +454,16 @@ const ARTRenderer = ReactFiberReconciler({
// Noop
},

getChildHostContext() {
return null;
},

insertBefore(parentInstance, child, beforeChild) {
invariant(
child !== beforeChild,
'ReactART: Can not insert node before itself'
);

child.injectBefore(beforeChild);
},

Expand All @@ -472,10 +485,21 @@ const ARTRenderer = ReactFiberReconciler({
// Noop
},

resetTextContent(domElement) {
// Noop
},

scheduleAnimationCallback: window.requestAnimationFrame,

scheduleDeferredCallback: window.requestIdleCallback,

shouldSetTextContent(props) {
return (
typeof props.children === 'string' ||
typeof props.children === 'number'
);
},

useSyncScheduling: true,
});

Expand Down
92 changes: 52 additions & 40 deletions src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ function testDOMNodeStructure(domNode, expectedStructure) {
}
}

describe('ReactART', function() {
describe('ReactART', () => {

beforeEach(function() {
beforeEach(() => {
ARTCurrentMode.setCurrent(ARTSVGMode);

Group = ReactART.Group;
Shape = ReactART.Shape;
Surface = ReactART.Surface;

TestComponent = React.createClass({
render: function() {
TestComponent = class extends React.Component {
render() {

var a =
<Shape
Expand Down Expand Up @@ -96,18 +96,18 @@ describe('ReactART', function() {
</Surface>
);
}
});
};
});

it('should have the correct lifecycle state', function() {
it('should have the correct lifecycle state', () => {
var instance = <TestComponent />;
instance = ReactTestUtils.renderIntoDocument(instance);
var group = instance.refs.group;
// Duck type test for an ART group
expect(typeof group.indicate).toBe('function');
});

it('should render a reasonable SVG structure in SVG mode', function() {
it('should render a reasonable SVG structure in SVG mode', () => {
var instance = <TestComponent />;
instance = ReactTestUtils.renderIntoDocument(instance);

Expand Down Expand Up @@ -138,7 +138,7 @@ describe('ReactART', function() {
testDOMNodeStructure(realNode, expectedStructure);
});

it('should be able to reorder components', function() {
it('should be able to reorder components', () => {
var container = document.createElement('div');
var instance = ReactDOM.render(<TestComponent flipped={false} />, container);

Expand Down Expand Up @@ -182,19 +182,19 @@ describe('ReactART', function() {
testDOMNodeStructure(realNode, expectedNewStructure);
});

it('should be able to reorder many components', function() {
it('should be able to reorder many components', () => {
var container = document.createElement('div');

var Component = React.createClass({
render: function() {
class Component extends React.Component {
render() {
var chars = this.props.chars.split('');
return (
<Surface>
{chars.map((text) => <Shape key={text} title={text} />)}
</Surface>
);
},
});
}
}

// Mini multi-child stress test: lots of reorders, some adds, some removes.
var before = 'abcdefghijklmnopqrst';
Expand All @@ -210,16 +210,19 @@ describe('ReactART', function() {
ReactDOM.unmountComponentAtNode(container);
});

it('renders composite with lifecycle inside group', function() {
it('renders composite with lifecycle inside group', () => {
var mounted = false;
var CustomShape = React.createClass({
render: function() {

class CustomShape extends React.Component {
render() {
return <Shape />;
},
componentDidMount: function() {
}

componentDidMount() {
mounted = true;
}
});
}

ReactTestUtils.renderIntoDocument(
<Surface>
<Group>
Expand All @@ -230,18 +233,21 @@ describe('ReactART', function() {
expect(mounted).toBe(true);
});

it('resolves refs before componentDidMount', function() {
var CustomShape = React.createClass({
render: function() {
it('resolves refs before componentDidMount', () => {
class CustomShape extends React.Component {
render() {
return <Shape />;
}
});
}

var ref = null;
var Outer = React.createClass({
componentDidMount: function() {

class Outer extends React.Component {
componentDidMount() {
ref = this.refs.test;
},
render: function() {
}

render() {
return (
<Surface>
<Group>
Expand All @@ -250,26 +256,31 @@ describe('ReactART', function() {
</Surface>
);
}
});
}

ReactTestUtils.renderIntoDocument(<Outer />);
expect(ref.constructor).toBe(CustomShape);
});

it('resolves refs before componentDidUpdate', function() {
var CustomShape = React.createClass({
render: function() {
it('resolves refs before componentDidUpdate', () => {
class CustomShape extends React.Component {
render() {
return <Shape />;
}
});
}

var ref = {};
var Outer = React.createClass({
componentDidMount: function() {

class Outer extends React.Component {
componentDidMount() {
ref = this.refs.test;
},
componentDidUpdate: function() {
}

componentDidUpdate() {
ref = this.refs.test;
},
render: function() {
}

render() {
return (
<Surface>
<Group>
Expand All @@ -278,15 +289,16 @@ describe('ReactART', function() {
</Surface>
);
}
});
}

var container = document.createElement('div');
ReactDOM.render(<Outer />, container);
expect(ref).not.toBeDefined();
ReactDOM.render(<Outer mountCustomShape={true} />, container);
expect(ref.constructor).toBe(CustomShape);
});

it('adds and updates event handlers', function() {
it('adds and updates event handlers', () => {
const container = document.createElement('div');

function render(onClick) {
Expand Down