Skip to content

Commit c974026

Browse files
committed
pass importSource to bind()
1 parent 462bdbf commit c974026

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

docs/source/javascript-components.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ adheres to the following interface:
7373
loadImportSource(source: string, sourceType: "NAME" | "URL") => Module;
7474
}
7575
76-
type bind = (node: HTMLElement, context: LayoutContext) => ({
76+
type ImportSource = {
77+
source: string;
78+
sourceType: string;
79+
}
80+
81+
type bind = (node: HTMLElement, context: LayoutContext, source: ImportSource) => ({
7782
render(component: any, props: Object, childModels: Array<any>): void;
7883
unmount(): void;
7984
});

src/client/packages/idom-client-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "idom-client-react",
33
"description": "A client for IDOM implemented in React",
4-
"version": "0.9.2",
4+
"version": "0.10.0",
55
"author": "Ryan Morshead",
66
"license": "MIT",
77
"type": "module",

src/client/packages/idom-client-react/src/component.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ export function Element({ model }) {
3636
}
3737
}
3838

39+
export function elementChildren(modelChildren) {
40+
if (!modelChildren) {
41+
return [];
42+
} else {
43+
return modelChildren.map((child) => {
44+
switch (typeof child) {
45+
case "object":
46+
return html`<${Element} key=${child.key} model=${child} />`;
47+
case "string":
48+
return child;
49+
}
50+
});
51+
}
52+
}
53+
54+
export function elementAttributes(model, sendEvent) {
55+
const attributes = Object.assign({}, model.attributes);
56+
57+
if (model.eventHandlers) {
58+
for (const [eventName, eventSpec] of Object.entries(model.eventHandlers)) {
59+
attributes[eventName] = eventHandler(sendEvent, eventSpec);
60+
}
61+
}
62+
63+
return attributes;
64+
}
65+
3966
function StandardElement({ model }) {
4067
const config = React.useContext(LayoutConfigContext);
4168
const children = elementChildren(model.children);
@@ -95,33 +122,6 @@ function RenderImportedElement({ model, importSource }) {
95122
return html`<div ref=${mountPoint} />`;
96123
}
97124

98-
export function elementChildren(modelChildren) {
99-
if (!modelChildren) {
100-
return [];
101-
} else {
102-
return modelChildren.map((child) => {
103-
switch (typeof child) {
104-
case "object":
105-
return html`<${Element} key=${child.key} model=${child} />`;
106-
case "string":
107-
return child;
108-
}
109-
});
110-
}
111-
}
112-
113-
export function elementAttributes(model, sendEvent) {
114-
const attributes = Object.assign({}, model.attributes);
115-
116-
if (model.eventHandlers) {
117-
for (const [eventName, eventSpec] of Object.entries(model.eventHandlers)) {
118-
attributes[eventName] = eventHandler(sendEvent, eventSpec);
119-
}
120-
}
121-
122-
return attributes;
123-
}
124-
125125
function eventHandler(sendEvent, eventSpec) {
126126
return function () {
127127
const data = Array.from(arguments).map((value) => {
@@ -152,7 +152,11 @@ function loadImportSource(config, importSource) {
152152
return {
153153
data: importSource,
154154
bind: (node) => {
155-
const binding = module.bind(node, config);
155+
const shortImportSource = {
156+
source: importSource.source,
157+
sourceType: importSource.sourceType,
158+
};
159+
const binding = module.bind(node, config, shortImportSource);
156160
if (
157161
typeof binding.render == "function" &&
158162
typeof binding.unmount == "function"

0 commit comments

Comments
 (0)