Skip to content

Commit

Permalink
Merge branch 'master' into refactor/contextLogicDiffing
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 30, 2019
2 parents 5ce6ca1 + 76c4918 commit 6597287
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 21 deletions.
18 changes: 16 additions & 2 deletions compat/src/index.js
Expand Up @@ -344,6 +344,17 @@ options.vnode = vnode => {
if (oldVNodeHook) oldVNodeHook(vnode);
};

/**
* Deprecated way to control batched rendering inside the reconciler, but we
* already schedule in batches inside our rendering code
* @param {(a) => void} callback function that triggers the updatd
* @param {*} [arg] Optional argument that can be passed to the callback
*/
// eslint-disable-next-line camelcase
function unstable_batchedUpdates(callback, arg) {
callback(arg);
}

export {
version,
Children,
Expand All @@ -362,7 +373,9 @@ export {
Component,
PureComponent,
memo,
forwardRef
forwardRef,
// eslint-disable-next-line camelcase
unstable_batchedUpdates
};

// React copies the named exports to the default one.
Expand All @@ -384,5 +397,6 @@ export default assign({
Component,
PureComponent,
memo,
forwardRef
forwardRef,
unstable_batchedUpdates
}, hooks);
2 changes: 2 additions & 0 deletions compat/test/browser/exports.test.js
Expand Up @@ -35,6 +35,7 @@ describe('exports', () => {
expect(Compat.Children.toArray).to.exist.and.be.a('function');
expect(Compat.Children.only).to.exist.and.be.a('function');
expect(Compat.unmountComponentAtNode).to.exist.and.be.a('function');
expect(Compat.unstable_batchedUpdates).to.exist.and.be.a('function');
expect(Compat.version).to.exist.and.be.a('string');
});

Expand Down Expand Up @@ -70,6 +71,7 @@ describe('exports', () => {
expect(Named.Children.toArray).to.exist.and.be.a('function');
expect(Named.Children.only).to.exist.and.be.a('function');
expect(Compat.unmountComponentAtNode).to.exist.and.be.a('function');
expect(Compat.unstable_batchedUpdates).to.exist.and.be.a('function');
expect(Named.version).to.exist.and.be.a('string');
});
});
17 changes: 16 additions & 1 deletion compat/test/browser/index.test.js
Expand Up @@ -5,7 +5,8 @@ import React, {
findDOMNode,
Component,
unmountComponentAtNode,
createFactory
createFactory,
unstable_batchedUpdates
} from '../../src';
import { createElement as preactH } from 'preact';
import { setupScratch, teardown, createEvent } from '../../../test/_util/helpers';
Expand Down Expand Up @@ -302,6 +303,20 @@ describe('preact-compat', () => {
});
});

describe('unstable_batchedUpdates', () => {
it('should call the callback', () => {
const spy = sinon.spy();
unstable_batchedUpdates(spy);
expect(spy).to.be.calledOnce;
});

it('should call callback with only one arg', () => {
const spy = sinon.spy();
unstable_batchedUpdates(spy, 'foo', 'bar');
expect(spy).to.be.calledWithExactly('foo');
});
});

it('should patch events', () => {
let spy = sinon.spy();
render(<div onClick={spy} />, scratch);
Expand Down
58 changes: 43 additions & 15 deletions demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/package.json
Expand Up @@ -28,7 +28,7 @@
"d3-scale": "^1.0.7",
"d3-selection": "^1.2.0",
"mobx": "^5.9.0",
"mobx-preact": "^3.0.0",
"mobx-react": "^5.4.3",
"mobx-state-tree": "^3.12.2",
"preact-render-to-string": "^5.0.2",
"preact-router": "^3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion demo/people/index.tsx
@@ -1,4 +1,4 @@
import { observer } from "mobx-preact"
import { observer } from "mobx-react"
import { Component, h } from "preact"
import { Profile } from "./profile"
import { Link, Route, Router } from "./router"
Expand Down
2 changes: 1 addition & 1 deletion demo/people/profile.tsx
@@ -1,5 +1,5 @@
import { computed, observable } from "mobx"
import { observer } from "mobx-preact"
import { observer } from "mobx-react"
import { Component, h } from "preact"
import { RouteChildProps } from "./router"
import { store } from "./store"
Expand Down

0 comments on commit 6597287

Please sign in to comment.