Skip to content

Instantly share code, notes, and snippets.

@bketelsen
Created November 24, 2018 17:49
Show Gist options
  • Save bketelsen/3fe17de697139602b2595c33edb9042e to your computer and use it in GitHub Desktop.
Save bketelsen/3fe17de697139602b2595c33edb9042e to your computer and use it in GitHub Desktop.
observed attributes
import
dom, jsffi, jsconsole, macros, strutils,
nes
type
WelcomeProps = ref object of JsObject
prop1: cstring
type StringArray = array[0..1, cstring]
class Welcome(HTMLElement):
args: varargs[JsObject]
constructorBody:
this.html = bindLit(this)
welcomeTempl = html_templ:
h1: "Hello, ${this.getAttribute('name')}"
h2: "This is an H2"
input(type="password"): "Something"
observedAttributes = proc(): StringArray =
var r: StringArray
r=["name","blue"]
result r
connectedCallback = proc(w: Welcome): Element =
w.render()
attributeChangedCallback = proc(name: JsObject, oldValue: JsObject, newValue: JsObject) =
console.log("thing")
render = proc(w: Welcome): Element =
result = tagCustomElement(w.html, w.welcomeTempl, w)
customElements.define("h-welcome", WelcomeConstructor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment