The Raspberry Pi continues to deliver on cool projects to spend time with the family on. As a non-serious entrant for this year’s wood car race, we used a Pi Zero, Pi Camera Module, USB Wi-Fi adapter, and UPS PIco to send it down the track while streaming the video.
We were able to build simply and get it under “regulation weight” by limiting the amount of hardware attached, and fastening everything with thumb tacks and hot glue. There’s a lot of functionality on the UPS PIco that could be used to make the process easier, like accessible pins, push buttons, LEDs, and a tiny speaker—but I opted to SSH into the car and run the following script manually to start the video stream:
While building using the custom elements v1 standard is achievable in a normal workflow, high quality libraries providing a wrapper on top of the standard seem like a more productive choice for my usage—especially any that offer a unified way to support Internet Explorer 11. After investigating a few, I decided to give LitElement a closer look. The guide says that it “is a simple base class for creating fast, lightweight web components that work in any web page with any framework.” I want that, and it’s coming from the Polymer project, so it seems like a good choice.
The small Web Component I built to try it out has its main functionality in the render method. It has the primary job of returning a template composed of styles, slotted content, and the articles loaded using the until directive from lit-html.
Then declare the x-postpress element with the apiHost attribute set to the appropriate WordPress installation. There are other attributes that can be set to control the requested results. In the example below, the per_page attribute specifies that only one article for each “page” in the payload should be returned.
The repository also includes a few basic unit and integration tests. These start on Travis CI after a pull request is issued on GitHub. While the Chrome and Firefox tests are executed inside of a Docker image (Mocha for unit and Puppeteer for integration), unit tests are also sent to Sauce Labs for Windows and macOS browser testing.
The most exciting part of the whole thing in my opinion is its shareability. Whether loading the element in a script tag, or including it in a project as part of a build step—getting the results into the browser is easier than ever (based on my past experience anyway). For a live example, try it out at CodeSandbox.
They are made using “three main technologies, which can be used together to create versatile custom elements with encapsulated functionality that can be reused wherever you like without fear of code collisions.” – MDN web docs.
These three are listed as, Custom Elements, Shadow DOM, and HTML templates. When used by the consumer of the Web Component, the tag essentially has to be lowercase, contain a hyphen, can contain custom attributes, and cannot be self closing. For example:
While I’m hopeful for better server side rendering support and will continue to watch how the future looks in regard to React, the thought of composing a site with a text editor, a few tags, and the F5 key sounds a bit refreshing. 🙂