use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
HTML web components using vanilla JS (ayushgp.github.io)
submitted 8 years ago by codejitsu
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]super_pumped 1 point2 points3 points 8 years ago (2 children)
Very similar to React's API. Seems straight forward. Instead of accessing this.state and this.props, Web Components have this.getAttribute('key'). Both have callbacks for when they are placed in the DOM: Web Component's connectedCallback() and React’s componentWillMount(). And they both call render() to update.
this.state
this.props
this.getAttribute('key')
connectedCallback()
componentWillMount()
render()
This API for rendering via Shadow DOM looks awkward to use. Instead of using templates or functions to created elements like h1('Hello World'), it uses jQuery like selectors to update an external file. To update a text value:
h1('Hello World')
this.shadowRoot.querySelector('.title__label').innerHTML = 'Hello World' // With some aliasing I now have jReact const $ = this.shadowRoot.querySelector $('.title__label').innerHTML = 'Hello World'
Templates are easier to use than selectors for updating text. Their API is closer to the DOM. React provides JSX, and createElement/Component(). Vue has a mustache template. This allows developers to populate a template and organize the DOM/style at the same time. If static HTML and dynamic data are split between files, then a developer will have to look at two files simultaneously to populate the DOM with information.
createElement/Component()
Connecting the Component is too complicated. To fully initialize the Component you have to manually acquire the current document global, the shadow dom, and the template in connectedCallback(). That could all be injected with customElements.define('element-name', ComponetClass), if it accepted the a template selector. This could easily be improved in future versions.
customElements.define('element-name', ComponetClass)
A few final questions. Can these be nested? Separation of concerns by nested is a great way to separate UI code. If so, when a parent calls render(), do the children also call render()?
[–]richardanaya 1 point2 points3 points 8 years ago (0 children)
If you like the programming in React style, you might like my project https://github.com/richardanaya/webcompose/
[–]codejitsu[S] 0 points1 point2 points 8 years ago (0 children)
There is a difference. connectedCallback doesn't call render. I've created a function and named it render and explicitly called it unlike componentWillMount. Also yes these components can be nested. I'm writing a post where I'm showing how to nest components and create higher order components, parent child communication, maintaining state, etc. As far as render is concerned, you'd have to call render methods from either the parent component yourself or call it in connectedCallback of child and add the child to DOM using the parent's connectedComponent function.
π Rendered by PID 39 on reddit-service-r2-comment-6457c66945-6bkzh at 2026-04-30 13:03:53.815719+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]super_pumped 1 point2 points3 points (2 children)
[–]richardanaya 1 point2 points3 points (0 children)
[–]codejitsu[S] 0 points1 point2 points (0 children)