Skip to content

Commit

Permalink
Added flush to CWM and synthetic events
Browse files Browse the repository at this point in the history
  • Loading branch information
Sampo Kivistö committed May 28, 2017
1 parent 27170e4 commit 03dc14b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/inferno-component/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import VNodeFlags from 'inferno-vnode-flags';
/* Add ES6 component implementations for Inferno-core to use */
options.component.create = createInstance;
options.component.patch = patchComponent;
options.component.flush = flushQueue;

const handleInput = options.component.handleInput;
let noOp = ERROR_MSG;
Expand Down Expand Up @@ -82,6 +83,7 @@ function createInstance(vNode: VNode, Component, props: Props, context: Object,
if (isFunction(instance.componentWillMount)) {
instance._blockRender = true;
instance.componentWillMount();
flushQueue();
instance._blockRender = false;
}

Expand Down
10 changes: 9 additions & 1 deletion packages/inferno/src/DOM/events/delegation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isBrowser } from 'inferno-shared';
import { options } from './../../core/options';
import { isBrowser, isFunction } from 'inferno-shared';

const isiOS = isBrowser && !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
const delegatedEvents: Map<string, IDelegate> = new Map();
Expand All @@ -12,6 +13,8 @@ interface IEventData {
dom: Element;
}

const C = options.component;

export function handleEvent(name, lastEvent, nextEvent, dom) {
let delegatedRoots = delegatedEvents.get(name);

Expand Down Expand Up @@ -53,6 +56,9 @@ function dispatchEvent(event, target, items, count: number, isClick: boolean, ev
eventsToTrigger(event);
}
if (event.cancelBubble) {
if (isFunction(C.flush)) {
C.flush();
}
return;
}
}
Expand All @@ -67,6 +73,8 @@ function dispatchEvent(event, target, items, count: number, isClick: boolean, ev
}

dispatchEvent(event, parentDom, items, count, isClick, eventData);
} else if (isFunction(C.flush)) {
C.flush();
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/inferno/src/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const options: {
createVNode: null|Function,
component: {
create: null|Function,
flush: null|Function,
handleInput: Function
patch: null|Function
},
Expand All @@ -31,6 +32,7 @@ export const options: {
beforeUnmount: null,
component: {
create: null,
flush: null,
handleInput: handleComponentInput,
patch: null
},
Expand Down

0 comments on commit 03dc14b

Please sign in to comment.