Skip to content

Commit

Permalink
Fixed Component ref on diff and Component typings.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjohnsonaz committed Jan 19, 2017
1 parent 6f10863 commit 857b5d0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/scripts/cascade/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import VirtualNode from './VirtualNode';
import { IVirtualNode, IVirtualNodeProps } from './IVirtualNode';
import Diff, { DiffOperation } from './Diff';

var componentContexts: Component<any>[][] = [];
var context: Component<any>[] = undefined;
var componentContexts: Component<IVirtualNodeProps>[][] = [];
var context: Component<IVirtualNodeProps>[] = undefined;

export abstract class Component<T extends IVirtualNodeProps> implements IVirtualNode<T> {
// TODO: Remove unused uniqueId?
Expand All @@ -15,7 +15,7 @@ export abstract class Component<T extends IVirtualNodeProps> implements IVirtual
key: string;
root: any;
element: Node;
context: Component<any>[];
context: Component<IVirtualNodeProps>[];
rendered: boolean = false;

constructor(props?: T, ...children: any[]) {
Expand Down Expand Up @@ -185,7 +185,7 @@ export abstract class Component<T extends IVirtualNodeProps> implements IVirtual

}

diffComponents(newRoot: Component<any>, oldRoot: Component<any>, oldElement: Node) {
diffComponents(newRoot: Component<IVirtualNodeProps>, oldRoot: Component<IVirtualNodeProps>, oldElement: Node) {
var innerRoot = Graph.peek(newRoot, 'root');
var innerOldRoot = Graph.peek(oldRoot, 'root');
if (!innerOldRoot) {
Expand Down Expand Up @@ -252,6 +252,12 @@ export abstract class Component<T extends IVirtualNodeProps> implements IVirtual
}
}
}

// Call the ref for newRoot
if (newRoot.props.ref) {
newRoot.props.ref(oldElement);
}

return oldElement;
}

Expand Down

0 comments on commit 857b5d0

Please sign in to comment.