Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stylemistake committed Nov 8, 2019
1 parent b5ce411 commit d1b1385
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgui-next/packages/inferno/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"private": true,
"name": "inferno",
"version": "7.3.2",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions tgui-next/packages/inferno/src/DOM/mounting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { mountProps } from './props';
import { createClassComponentInstance } from './utils/componentUtil';
import { validateKeys } from '../core/validate';
import { mountRef } from '../core/refs';
import { options } from './utils/common';

export function mount(vNode: VNode, parentDOM: Element | null, context: Object, isSVG: boolean, nextNode: Element | null, lifecycle: Function[]): void {
const flags = (vNode.flags |= VNodeFlags.InUse);
Expand Down Expand Up @@ -186,5 +187,8 @@ export function mountFunctionalComponentCallbacks(vNode: VNode, lifecycle: Funct
if (isFunction(ref.onComponentDidMount)) {
lifecycle.push(createOnMountCallback(ref, vNode));
}
if (options.beforeRender) {
options.beforeRender(vNode);
}
}
}
6 changes: 6 additions & 0 deletions tgui-next/packages/inferno/src/DOM/patching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ function patchFunctionalComponent(lastVNode, nextVNode, parentDOM, context, isSV
if (nextHooksDefined && isFunction(nextRef.onComponentWillUpdate)) {
nextRef.onComponentWillUpdate(lastProps, nextProps);
}
if (options.beforeUpdate) {
options.beforeUpdate(nextVNode);
}
const type = nextVNode.type;
const nextInput = normalizeRoot(nextVNode.flags & VNodeFlags.ForwardRef ? type.render(nextProps, nextRef, context) : type(nextProps, context));

Expand All @@ -466,6 +469,9 @@ function patchFunctionalComponent(lastVNode, nextVNode, parentDOM, context, isSV
if (nextHooksDefined && isFunction(nextRef.onComponentDidUpdate)) {
nextRef.onComponentDidUpdate(lastProps, nextProps);
}
if (options.afterUpdate) {
options.afterUpdate(nextVNode);
}
} else {
nextVNode.children = lastInput;
}
Expand Down
4 changes: 4 additions & 0 deletions tgui-next/packages/inferno/src/DOM/unmounting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { VNode } from '../core/types';
import { syntheticEvents, unmountSyntheticEvent } from './events/delegation';
import { EMPTY_OBJ, findDOMfromVNode, removeVNodeDOM } from './utils/common';
import { unmountRef } from '../core/refs';
import { options } from './utils/common';

export function remove(vNode: VNode, parentDOM: Element) {
unmount(vNode);
Expand Down Expand Up @@ -53,6 +54,9 @@ export function unmount(vNode) {
if (!isNullOrUndef(ref) && isFunction(ref.onComponentWillUnmount)) {
ref.onComponentWillUnmount(findDOMfromVNode(vNode, true) as Element, vNode.props || EMPTY_OBJ);
}
if (options.beforeUnmount) {
options.beforeUnmount(vNode);
}

unmount(children);
} else if (flags & VNodeFlags.Portal) {
Expand Down
5 changes: 5 additions & 0 deletions tgui-next/packages/inferno/src/DOM/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export const options: {
createVNode: ((vNode: VNode) => void) | null;
renderComplete: ((rootInput: VNode | InfernoNode, parentDOM: Element | SVGAElement | ShadowRoot | DocumentFragment | HTMLElement | Node) => void) | null;
reactStyles?: boolean;
// Hooks
beforeRender?: any,
beforeUpdate?: any,
afterUpdate?: any,
beforeUnmount?: any,
} = {
componentComparator: null,
createVNode: null,
Expand Down

0 comments on commit d1b1385

Please sign in to comment.