diff --git a/src/core/HNode.ts b/src/core/HNode.ts index 98d4405..33f5322 100644 --- a/src/core/HNode.ts +++ b/src/core/HNode.ts @@ -71,6 +71,7 @@ export const toNodeArr = function toNodes( src.ownerNode = ownerNode; src.owner = owner; + src.context = context; if (desc) { @@ -80,7 +81,7 @@ export const toNodeArr = function toNodes( src.active = false; - initComponent(src, store, context); + initComponent(src, store); return src.nodes = toNodeArr( src.output = toArr( diff --git a/src/core/initComponent.ts b/src/core/initComponent.ts index 1995ff5..3e0a61e 100644 --- a/src/core/initComponent.ts +++ b/src/core/initComponent.ts @@ -2,9 +2,9 @@ import { HNode } from "./HNode"; import { Store } from "./Store"; import { supply } from "../utils/helpers"; -export const initComponent = function (hNode: HNode, store: Store, ctxStore: Store) { +export const initComponent = function (hNode: HNode, store: Store) { - const { props } = hNode, + const { props, context: ctxStore } = hNode, desc = hNode.desc!, { defaultProps, defaultStore, storeHandlers, state, context, init } = desc; @@ -23,13 +23,12 @@ export const initComponent = function (hNode: HNode, store: Store, ctxStore store.handleSome(storeHandlers); } - hNode.context = ctxStore; if (context) { - ctxStore.bind(hNode, context); + ctxStore!.bind(hNode, context); } if (init) { - init.call(hNode, props, store, ctxStore); + init.call(hNode, props, store, ctxStore!); } }; \ No newline at end of file diff --git a/src/ticker/updateChildren.ts b/src/ticker/updateChildren.ts index 02c73b5..f81f05a 100644 --- a/src/ticker/updateChildren.ts +++ b/src/ticker/updateChildren.ts @@ -104,7 +104,7 @@ export const updateChildren = function ( renderToDOM(newChildren.slice(oldChildrenCount), { parent: element, owner: hNode, - context: hNode.context! + context: hNode.context }); } diff --git a/test/src/Greeting.tsx b/test/src/Greeting.tsx index d9fd35d..2ccf615 100644 --- a/test/src/Greeting.tsx +++ b/test/src/Greeting.tsx @@ -46,7 +46,7 @@ const Greeting = HUI.define('ShowTarget', { context: ['target'], render(props, store, context) { - return

context.target: {context.get('target')}

; + return `context.target: ${context.get('target')}`; } }); diff --git a/test/src/test.tsx b/test/src/test.tsx index 2666bb8..cd4f012 100644 --- a/test/src/test.tsx +++ b/test/src/test.tsx @@ -25,7 +25,9 @@ HUI.render(
- +

+ +