Skip to content

Commit

Permalink
fix some bugs and improve type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
huang2002 committed Feb 10, 2019
1 parent 2426dfa commit d1f93b6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
51 changes: 26 additions & 25 deletions src/ext/Portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,47 @@ export interface PortalProps {
children?: unknown;
}

export interface PortalStore {
export type PortalStore = Store<{
p: Node;
f: HNode<FragmentProps, EmptyStore, EmptyStore>;
}

export const Portal = define<PortalProps, Store<PortalStore>, EmptyStore>('HUI.Portal', {

effects: [
function ptl_eff(props, store) {

const { parent = _document.body } = props,
fragment = HUI(Fragment, _null, props.children);

store.set('p', parent);
store.set('f', fragment);

return function ptl_clr() {
}, {
c: (frag: HNode<FragmentProps, EmptyStore, EmptyStore>) => void
}>

const { ownNode, nodes } = fragment;
export const Portal = define<PortalProps, PortalStore, EmptyStore>('HUI.Portal', {

storeHandlers: {
c: function ptl_c(fragment) {
const { ownNode, nodes } = fragment;
if (nodes) {
clear(fragment);

nodes!.forEach(node => {
nodes.forEach(node => {
ownNode!.removeChild(node);
});

nodes!.length = 0;

};

nodes.length = 0;
}
}
],
},

init: function ptl_init(props, store) {
const { parent = _document.body } = props,
fragment = HUI(Fragment, _null, props.children);
store.set('p', parent);
store.set('f', fragment);
},

render: function ptl_render(props, store, context) {
renderToDOM(store.get('f'), {
const fragment = store.get('f')!;
store.trigger('c', fragment);
renderToDOM(fragment, {
parent: store.get('p'),
owner: this,
context
});
},

clear: function ptl_clr(props, store) {
store.trigger('c', store.get('f')!);
}

});
Expand Down
2 changes: 1 addition & 1 deletion src/ticker/updateChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const updateChildren = function updChd(
element.removeChild(node);
});
oldChild.nodes!.length = 0;
} else if (childNodes.length) {
} else if (childNodes.length > nodeOffset) {
element.removeChild(childNodes[nodeOffset++]);
}

Expand Down
10 changes: 4 additions & 6 deletions src/ticker/updateComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const updateComponent = function updCom(hNode: HNode<any>) {

oldNodesLength = (oldNodes = old.nodes!).length;

clear(old);

if (isHNode(cur) && old.type === cur.type) {

if (old.desc) {
Expand All @@ -51,9 +53,7 @@ export const updateComponent = function updCom(hNode: HNode<any>) {

mark(cur);

nodeOffset += cur.nodes!.length;

return;
return nodeOffset += oldNodesLength;

} else {

Expand All @@ -79,10 +79,8 @@ export const updateComponent = function updCom(hNode: HNode<any>) {

}

clear(old);

} else if (!isHNode(cur) && HUI.cmp(old, cur)) {
return;
return nodeOffset++;
}

curNodes = toNodeArr(cur, ctx!, ownNode!, hNode);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isHNode } from "./helpers";

export const clear = function clr(hNode: HNode<any>) {

const { desc, out: output, props } = hNode;
const { desc, props } = hNode;

hNode.active = false;

Expand Down Expand Up @@ -42,8 +42,8 @@ export const clear = function clr(hNode: HNode<any>) {
expired.splice(index, 1);
}

if (output) {
output.forEach((child: unknown) => {
if (hNode.out) {
hNode.out.forEach((child: unknown) => {
if (isHNode(child)) {
clear(child);
}
Expand Down

0 comments on commit d1f93b6

Please sign in to comment.