codemeasandwich / hyper-element Goto Github PK
View Code? Open in Web Editor NEWCombining the best of hyperHTML and Custom Elements!
Combining the best of hyperHTML and Custom Elements!
someting like:
setup(attachStore){
const onStoreChange = attachStore() // No get state Fn
onIncoming(onStoreChange)
}
const cbs = []
// Called from outside
function messageIn(message){
cbs.forEach(cbOnChange => cbOnChange(message))
}
function onIncoming(cbOnChange){
cbs.push(cbOnChange)
}
How to install and use in a helloworld
Child element NOT re-drawing
class APerson extends hyperElement{
onClick(){
this.attrs.hi("Hello from "+this.attrs.name)
} // note/helper : fucntion automatically have the element "this" bound
render(Html){
console.log("Re-draw?")
Html`${this.attrs.name} <button onclick=${this.onClick}>Say hi! ${ this.attrs.x[0].path }</button>`
}
}
class UsersElem extends hyperElement{
setup(onNext){
const Interval = setInterval(onNext(()=> new Date()),1000)
return () => clearInterval(Interval);
}
onHi(val){
alert(val)
}
render(Html,time){
console.log("Draw!")
const yaml = [{path:"foo",data:{}}]
Html`<a-person hi=${this.onHi} x=${yaml} name=${time+""}></a-person>`
}
}
window.customElements.define("a-person", APerson)
window.customElements.define("users-elem", UsersElem)
window.customElements.define("my-profile", class extends hyperElement {
setup(attachStore) {
autorun(attachStore(s));
}// END setup
render(Html, { names, timeString }) {
Html`Profile: ${timeString}`
}// END render
}
)
results in Uncaught TypeError: Class constructor hyperElement cannot be invoked without 'new'
. I don't think that the api has changed, but the registerElement is supposed to have been deprecated in march.
In Example: Advanced attributes
This done NOT works !!
Html`<a-b></a-b><a-person hi=${this.onHi} x=${{a:2}} name="Beckett"/>`
DOM out put -> <a-b></a-b><a-person hi="function () { [native code] }" name="Beckett" x="[object Object]">
https://codepen.io/codemeasandwich/pen/VOQWeN
Uncaught TypeError: document.registerElement is not a function
Will render without dataset causing errors, screwing jquery for life.
In Example: Advanced attributes
This works
Html`<a-person hi=${this.onHi} name="Beckett"/>`
This works
Html`<a-person hi=${this.onHi} x=${{a:2}} name="Beckett"/>`
This done NOT works !!
Html`<a-person x=${{a:2}} name="Beckett"/>`
DOM out put -> <a-person name="Beckett" x="[object Object]">
Could the template system use something like handlebars?
Example. Text should be RED
class APerson extends hyperElement{
onClick(){
this.attrs.hi("Hello from "+this.attrs.name)
} // note/helper : fucntion automatically have the element "this" bound
render(Html){
console.log("Re-draw?")
Html`${this.attrs.name} <button onclick=${this.onClick}>Say hi! ${ this.attrs.x[0].path }</button>`
}
}
class UsersElem extends hyperElement{
setup(onNext){
const Interval = setInterval(onNext(()=> new Date()),1000)
return () => clearInterval(Interval);
}
onHi(val){
alert(val)
}
render(Html,time){
console.log("Draw!")
const yaml = [{path:"foo",data:{}}]
Html``
Html`<a-person hi=${this.onHi} x=${yaml} name=${time+""} style=${{color:"red"}}></a-person>`
}
}
window.customElements.define("a-person", APerson)
window.customElements.define("users-elem", UsersElem)
In this example you include polyfill for v1, yet it refuses to work in my app, and breaks in the example:
https://jsfiddle.net/fwLbqmsj/
https://jsfiddle.net/fwLbqmsj/
Using your own example, i've appended another element and the second instance won't run.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.