Skip to content

Commit

Permalink
More tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sampo Kivistö committed May 28, 2017
1 parent da45c36 commit 27170e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
24 changes: 8 additions & 16 deletions packages/inferno-component/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ export interface ComponentLifecycle<P, S> {
componentWillUnmount?(): void;
}

function addToQueue<P, S>(component: Component<P, S>, force: boolean, callback?: Function): void {
const queueStateChange = component._queueStateChange;

if (queueStateChange !== null) {
queueStateChange(component, force, callback);
}
}

function queueStateChanges<P, S>(component: Component<P, S>, newState: S, callback?: Function): void {
if (isFunction(newState)) {
newState = (newState as any)(component.state, component.props, component.context) as S;
Expand All @@ -56,7 +48,7 @@ function queueStateChanges<P, S>(component: Component<P, S>, newState: S, callba
}

if (isBrowser && !component._pendingSetState && !component._blockRender) {
addToQueue(component, false, callback);
queueStateChange(component, false, callback);
} else {
const state = component.state;

Expand Down Expand Up @@ -153,7 +145,8 @@ function updateComponent<P, S>(component: Component<P, S>, prevState: S, nextSta

/* Update if scu is not defined, or it returns truthy value or force */
// When force is true we should not call scu
if (force || (isFunction(component.shouldComponentUpdate) && component.shouldComponentUpdate(nextProps, nextState, context) !== false)) {
const hasSCU = isFunction(component.shouldComponentUpdate);
if (force || !hasSCU || (hasSCU && (component.shouldComponentUpdate as Function)(nextProps, nextState, context) !== false)) {
if (isFunction(component.componentWillUpdate)) {
component._blockSetState = true;
component.componentWillUpdate(nextProps, nextState, context);
Expand All @@ -165,12 +158,12 @@ function updateComponent<P, S>(component: Component<P, S>, prevState: S, nextSta
component.context = context;

if (isFunction(options.beforeRender)) {
options.beforeRender(this);
options.beforeRender(component);
}
const render = component.render(nextProps, nextState, context);

if (isFunction(options.afterRender)) {
options.afterRender(this);
options.afterRender(component);
}

return render;
Expand All @@ -190,9 +183,9 @@ function patchComponent(lastVNode, nextVNode, parentDom, lifecycle: LifecycleCla
if (instance._unmounted) {
return true;
} else {
nextVNode.dom = handleUpdate(instance, instance.state, nextVNode.props || EMPTY_OBJ, context, false, false);
nextVNode.dom = handleUpdate(instance, instance.state, nextVNode.props || EMPTY_OBJ, context, false, false);
nextVNode.children = instance;
}

instance._updating = false;

return false;
Expand Down Expand Up @@ -332,7 +325,6 @@ export default class Component<P, S> implements ComponentLifecycle<P, S> {
public _lifecycle: LifecycleClass;
public _childContext: object|null = null;
public _isSVG = false;
public _queueStateChange = null;
public _updating: boolean = true;

constructor(props?: P, context?: any) {
Expand Down Expand Up @@ -365,7 +357,7 @@ export default class Component<P, S> implements ComponentLifecycle<P, S> {
return;
}

addToQueue(this, true, callback);
queueStateChange(this, true, callback);
}

public setState(newState: S|Function, callback?: Function) {
Expand Down
2 changes: 1 addition & 1 deletion packages/inferno-router/__tests__/transition.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('Router (jsx) #transitions', () => {

it('should passed query parameters when URL is changed by using the history API', (done) => {
const TestQueryParams = ({ params }) => <div>Query Params { params.foo }</div>;

debugger;
render(
<Router history={ browserHistory }>
<IndexRoute component={ TestQueryParams }/>
Expand Down
6 changes: 5 additions & 1 deletion packages/inferno/src/DOM/patching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ function patchChildren(lastFlags: VNodeFlags, nextFlags: VNodeFlags, lastChildre
}
} else if (isStringOrNumber(lastChildren)) {
unmountChildren(lastChildren, dom, lifecycle, isRecycling);
mount(nextChildren, dom, lifecycle, context, isSVG);
if (isArray(nextChildren)) {
mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG);
} else {
mount(nextChildren, dom, lifecycle, context, isSVG);
}
} else if (isArray(nextChildren)) {
if (isArray(lastChildren)) {
patchArray = true;
Expand Down

0 comments on commit 27170e4

Please sign in to comment.