inferno-component
Advanced tools
Comparing version 0.6.4 to 0.7.2
/*! | ||
* inferno-component v0.6.3 | ||
* inferno-component v0.7.0 | ||
* (c) 2016 Dominic Gannaway | ||
@@ -7,7 +7,2 @@ * Released under the MPL-2.0 License. | ||
var babelHelpers = {}; | ||
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
@@ -54,27 +49,17 @@ babelHelpers.classCallCheck = function (instance, Constructor) { | ||
// TODO! Use object literal or at least prototype? --- class is prototype (jsperf needed for perf verification) | ||
function Lifecycle() { | ||
this._listeners = []; | ||
} | ||
var Lifecycle = function () { | ||
function Lifecycle() { | ||
babelHelpers.classCallCheck(this, Lifecycle); | ||
this._listeners = []; | ||
Lifecycle.prototype = { | ||
addListener: function addListener(callback) { | ||
this._listeners.push(callback); | ||
}, | ||
trigger: function trigger() { | ||
for (var i = 0; i < this._listeners.length; i++) { | ||
this._listeners[i](); | ||
} | ||
} | ||
}; | ||
babelHelpers.createClass(Lifecycle, [{ | ||
key: "addListener", | ||
value: function addListener(callback) { | ||
this._listeners.push(callback); | ||
} | ||
}, { | ||
key: "trigger", | ||
value: function trigger() { | ||
for (var i = 0; i < this._listeners.length; i++) { | ||
this._listeners[i](); | ||
} | ||
} | ||
}]); | ||
return Lifecycle; | ||
}(); | ||
function isNullOrUndefined(obj) { | ||
@@ -91,3 +76,3 @@ return obj === undefined || obj === null; | ||
if (activeNode !== document.body && document.activeElement !== activeNode) { | ||
activeNode.focus(); | ||
activeNode.focus(); // TODO: verify are we doing new focus event, if user has focus listener this might trigger it | ||
} | ||
@@ -107,29 +92,24 @@ } | ||
function applyState(component, force, callback) { | ||
var blockRender = component._blockRender; | ||
if (component._deferSetState === false || force) { | ||
component._pendingSetState = false; | ||
var pendingState = component._pendingState; | ||
var oldState = component.state; | ||
var nextState = babelHelpers.extends({}, oldState, pendingState); | ||
(function () { | ||
component._pendingSetState = false; | ||
var pendingState = component._pendingState; | ||
var oldState = component.state; | ||
var nextState = babelHelpers.extends({}, oldState, pendingState); | ||
component._pendingState = {}; | ||
var nextNode = component._updateComponent(oldState, nextState, component.props, component.props, force); | ||
component._pendingState = {}; | ||
var nextNode = component._updateComponent(oldState, nextState, component.props, component.props, force); | ||
var lastNode = component._lastNode; | ||
var parentDom = lastNode.dom.parentNode; | ||
if (!blockRender) { | ||
(function () { | ||
var lastNode = component._lastNode; | ||
var parentDom = lastNode.dom.parentNode; | ||
var activeNode = getActiveNode(); | ||
var subLifecycle = new Lifecycle(); | ||
component._diffNodes(lastNode, nextNode, parentDom, null, subLifecycle, component.context, false, component.instance); | ||
component._lastNode = nextNode; | ||
subLifecycle.addListener(function () { | ||
subLifecycle.trigger(); | ||
callback && callback(); | ||
}); | ||
resetActiveNode(activeNode); | ||
})(); | ||
} | ||
var activeNode = getActiveNode(); | ||
var subLifecycle = new Lifecycle(); | ||
component._diffNodes(lastNode, nextNode, parentDom, null, subLifecycle, component.context, false, component.instance); | ||
component._lastNode = nextNode; | ||
subLifecycle.addListener(function () { | ||
subLifecycle.trigger(); | ||
callback && callback(); | ||
}); | ||
resetActiveNode(activeNode); | ||
})(); | ||
} | ||
@@ -150,3 +130,2 @@ } | ||
this.refs = {}; | ||
this._blockRender = false; | ||
this._blockSetState = false; | ||
@@ -217,5 +196,5 @@ this._deferSetState = false; | ||
if (prevProps !== nextProps) { | ||
this._blockRender = true; | ||
this._blockSetState = true; | ||
this.componentWillReceiveProps(nextProps); | ||
this._blockRender = false; | ||
this._blockSetState = false; | ||
} | ||
@@ -241,6 +220,2 @@ var shouldUpdate = this.shouldComponentUpdate(nextProps, nextState); | ||
var index = { | ||
Component: Component | ||
}; | ||
export default index; | ||
export default Component; |
{ | ||
"name": "inferno-component", | ||
"version": "0.6.4", | ||
"version": "0.7.2", | ||
"license": "MPL-2.0", | ||
@@ -5,0 +5,0 @@ "description": "Provides ES2015 stateful components (with lifecycle events) to Inferno", |
@@ -17,3 +17,5 @@ # inferno-component | ||
``` | ||
class MyComponent extends InfernoComponent.Component { | ||
const Component = InfernoComponent; | ||
class MyComponent extends Component { | ||
render() { | ||
@@ -20,0 +22,0 @@ return <div></div>; |
import Component from '../../../src/component'; | ||
export default { | ||
Component | ||
}; | ||
export default Component; |
28
6929
192