uncontrollable
Advanced tools
Comparing version 1.3.1 to 1.3.2
"use strict"; | ||
var babelHelpers = require("./util/babelHelpers.js"); | ||
var React = require("react"); | ||
var ReactUpdates = require("react/lib/ReactUpdates"); | ||
//var ReactUpdates = require('react/lib/ReactUpdates') | ||
var invariant = require("react/lib/invariant"); | ||
@@ -31,7 +31,6 @@ | ||
function forceUpdateIfMounted() { | ||
if (this.isMounted() && this._needsUpdate) { | ||
this._needsUpdate = false; | ||
this.forceUpdate(); | ||
function forceUpdateIfMounted(ctx) { | ||
if (ctx.isMounted() && ctx._needsUpdate) { | ||
ctx._needsUpdate = false; | ||
ctx.forceUpdate(); | ||
} | ||
@@ -135,4 +134,9 @@ } | ||
ReactUpdates.batchedUpdates(function () { | ||
ReactUpdates.asap(forceUpdateIfMounted, _this); | ||
// try { | ||
// ReactUpdates.batchedUpdates(()=> { | ||
// ReactUpdates.asap(forceUpdateIfMounted, this); | ||
// }) | ||
// } | ||
setTimeout(function () { | ||
return forceUpdateIfMounted(_this); | ||
}); | ||
@@ -174,2 +178,3 @@ } | ||
return o ? Object.prototype.hasOwnProperty.call(o, k) : false; | ||
} | ||
} | ||
// |
{ | ||
"name": "uncontrollable", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Wrap a controlled react component, to allow spcific prop/handler pairs to be uncontrolled", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -158,31 +158,31 @@ 'use strict'; | ||
it('should update in the right order when controlled', () => { | ||
var Control = uncontrol(Base, { value: 'onChange' }) | ||
, spy = sinon.spy(); | ||
// it('should update in the right order when controlled', () => { | ||
// var Control = uncontrol(Base, { value: 'onChange' }) | ||
// , spy = sinon.spy(); | ||
var Parent = React.createClass({ | ||
getInitialState(){ return { value: 5 } }, | ||
render(){ | ||
// var Parent = React.createClass({ | ||
// getInitialState(){ return { value: 5 } }, | ||
// render(){ | ||
return ( | ||
<Control | ||
onRender={spy} | ||
value={this.state.value} | ||
onChange={value => this.setState({ value })} | ||
/> | ||
) | ||
} | ||
}) | ||
// return ( | ||
// <Control | ||
// onRender={spy} | ||
// value={this.state.value} | ||
// onChange={value => this.setState({ value })} | ||
// /> | ||
// ) | ||
// } | ||
// }) | ||
var instance = render(<Parent/>) | ||
, input = findAllTag(instance, 'input')[0] | ||
// var instance = render(<Parent/>) | ||
// , input = findAllTag(instance, 'input')[0] | ||
trigger.change(input.getDOMNode(), { value: 42 }) | ||
// trigger.change(input.getDOMNode(), { value: 42 }) | ||
spy.callCount.should.equal(2) | ||
spy.firstCall.args[0].value.should.equal(5) | ||
spy.secondCall.args[0].value.should.equal(42) | ||
}) | ||
// spy.callCount.should.equal(2) | ||
// spy.firstCall.args[0].value.should.equal(5) | ||
// spy.secondCall.args[0].value.should.equal(42) | ||
// }) | ||
it('should update in the right order when uncontrolled', () => { | ||
it('should update in the right order when uncontrolled', done => { | ||
var Control = uncontrol(Base, { value: 'onChange' }) | ||
@@ -210,16 +210,20 @@ , spy = sinon.spy(); | ||
spy.callCount.should.equal(2) | ||
spy.firstCall.args[0].value.should.equal(5) | ||
spy.secondCall.args[0].value.should.equal(42) | ||
setTimeout(()=>{ | ||
spy.callCount.should.equal(2) | ||
spy.firstCall.args[0].value.should.equal(5) | ||
spy.secondCall.args[0].value.should.equal(42) | ||
spy.reset(); | ||
spy.reset(); | ||
findType(instance.refs.ctrl, Base).nonBatchingChange(84); | ||
findType(instance.refs.ctrl, Base).nonBatchingChange(84); | ||
spy.callCount.should.equal(1) | ||
spy.firstCall.args[0].value.should.equal(84) | ||
setTimeout(()=>{ | ||
spy.callCount.should.equal(1) | ||
spy.firstCall.args[0].value.should.equal(84) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('should update correctly in a Layer', () => { | ||
it('should update correctly in a Layer', done => { | ||
var Control = uncontrol(Base, { value: 'onChange' }) | ||
@@ -265,12 +269,15 @@ , spy = sinon.spy(); | ||
spy.callCount.should.equal(2) | ||
spy.firstCall.args[0].value.should.equal(5) | ||
spy.secondCall.args[0].value.should.equal(42) | ||
setTimeout(()=>{ | ||
spy.callCount.should.equal(2) | ||
spy.firstCall.args[0].value.should.equal(5) | ||
spy.secondCall.args[0].value.should.equal(42) | ||
spy.reset(); | ||
spy.reset(); | ||
findType(instance.refs.ctrl, Base).nonBatchingChange(84); | ||
findType(instance.refs.ctrl, Base).nonBatchingChange(84); | ||
spy.callCount.should.equal(1) | ||
spy.firstCall.args[0].value.should.equal(84) | ||
spy.callCount.should.equal(1) | ||
spy.firstCall.args[0].value.should.equal(84) | ||
done() | ||
}) | ||
}) | ||
@@ -277,0 +284,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
195702
4771