Code Monkey home page Code Monkey logo

load-web-components-with-javascript's Introduction

Load Web Components With Javascript

A sample project demonstrating how to load web components with pure Javascript.

Usage

  1. Create your component html and css files.
  2. Add a class for each component to components.js as follows (replace COMPONENT_CLASS_NAME with a name for your component's class):
class COMPONENT_CLASS_NAME extends HTMLElement {
  constructor() {
    super();
    this.innerHTML = COMPONENT_CLASS_NAME._html;
  }
}
  1. Add a call to the loadView() function for each component inside the loadComponents() function of components.js.
  2. Call the loadComponents() function form your Javascript as follows:
import loadComponents from "./components.js";

document.addEventListener("DOMContentLoaded", () => {
  loadComponents().then(() => {
    start();
  });
});

function start() {
  // The rest of your Javascript.
}

Timing is important here. The DOM must first finish loading, then loadComponents() is called and allowed to complete, then you can call a start() function for the rest of your Javascript.

Integrating With Automation & Control Systems

Here is a blog post covering how this project can be integrated as part of a larger automation & control system. https://www.learnavprogramming.com/html5-part-i/

Acknowledgments

Thanks to Anton Karsten for helping think this through.

load-web-components-with-javascript's People

Contributors

controlhaus avatar catchtechnologies avatar

Stargazers

Trey Chamrad avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.