Last active
April 14, 2017 13:17
-
-
Save jgwhite/affcc1d4fe958facac12bad6cf226a0f to your computer and use it in GitHub Desktop.
Passing web components attributes to glimmer components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==> https://github.com/glimmerjs/glimmer-application/compare/master...jgwhite:attributes | |
diff --git a/src/application.ts b/src/application.ts | |
index 3ae3a49..e16e6b8 100644 | |
--- a/src/application.ts | |
+++ b/src/application.ts | |
@@ -39,7 +39,8 @@ export interface AppRoot { | |
id: number, | |
component: string | ComponentDefinition<Component>, | |
parent: Simple.Node, | |
- nextSibling: Option<Simple.Node> | |
+ nextSibling: Option<Simple.Node>, | |
+ attributes: { string: any } | |
} | |
export default class Application implements Owner { | |
@@ -140,8 +141,8 @@ export default class Application implements Owner { | |
this._renderResult = result.value; | |
} | |
- renderComponent(component: string | ComponentDefinition<Component>, parent: Simple.Node, nextSibling: Option<Simple.Node>): void { | |
- this._roots.push({ id: this._rootsIndex++, component, parent, nextSibling }); | |
+ renderComponent(component: string | ComponentDefinition<Component>, parent: Simple.Node, nextSibling: Option<Simple.Node>, attributes: { string: any }): void { | |
+ this._roots.push({ id: this._rootsIndex++, component, parent, nextSibling, attributes }); | |
this.scheduleRerender(); | |
} | |
diff --git a/src/templates/main.hbs b/src/templates/main.hbs | |
index fe72042..89825da 100644 | |
--- a/src/templates/main.hbs | |
+++ b/src/templates/main.hbs | |
@@ -1,5 +1,5 @@ | |
{{#each roots key="id" as |root|~}} | |
{{~#-in-element root.parent nextSibling=root.nextSibling~}} | |
- {{~component root.component~}} | |
+ {{~component root.component attributes=root.attributes~}} | |
{{~/-in-element~}} | |
{{~/each~}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==> https://github.com/glimmerjs/glimmer-web-component/compare/master...jgwhite:attributes | |
diff --git a/src/initialize-custom-elements.ts b/src/initialize-custom-elements.ts | |
index eec1010..4002814 100644 | |
--- a/src/initialize-custom-elements.ts | |
+++ b/src/initialize-custom-elements.ts | |
@@ -16,11 +16,17 @@ function initializeCustomElement(app: Application, name: string): void { | |
value: function connectedCallback() { | |
let placeholder = document.createTextNode(''); | |
let parent = this.parentNode; | |
+ let attributes = {}; | |
+ | |
+ for (let i = 0; i < this.attributes.length; i++) { | |
+ let attribute = this.attributes[i]; | |
+ attributes[attribute.name] = attribute.value; | |
+ } | |
parent.insertBefore(placeholder, this); | |
parent.removeChild(this); | |
- app.renderComponent(name, parent, placeholder); | |
+ app.renderComponent(name, parent, placeholder, attributes); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment