background preloader

Web Components

Facebook Twitter

Preact + Typescript + Parcel + Redux Zero: Rebuilding the QMENTA Front-End focusing on Performance and Minimalism. At QMENTA we have been rebuilding the front-end from scratch, seeking simplicity and performance not only in design, but also in the technology stack used for it . This article provides a comprehensive overview of the different parts that compound the new platform, such as how decorators are extensively used or the choice of technology stack.

This post was originally posted on Medium The QMENTA platform has been going on for quite some time now. The old platform front-end was built using well established technologies like JQuery, Dojo or D3. One of the main challenges coming into this year was to rebuild the front-end from scratch to accommodate the new necessities of a growing neuroimaging processing hub, to make it clean and in a way that can be easily maintainable, scalable and up to date with the latest technologies on front-end development. Hyperapp is a JavaScript micro-framework for building web applications. Hyperapp 2.0 is coming out soon! Getting Started Interested? Why? Demo How <! John Resig - DOM DocumentFragments. I was playing around with DOM DocumentFragments recently, in JavaScript, seeing what I could make with them.

Roughly speaking, a DocumentFragment is a lightweight container that can hold DOM nodes. It’s part of the DOM 1 specification and is supported in all modern browsers (it was added to Internet Explorer in version 6). In reading up on them I came across an interesting point, from the specification: Furthermore, various operations — such as inserting nodes as children of another Node — may take DocumentFragment objects as arguments; this results in all the child nodes of the DocumentFragment being moved to the child list of this node. This means that if you take a bunch of DOM nodes and append them to a fragment then you can simply append the fragment to the document, instead (and achieve the same result – as if you had appended each node individually). I instantly smelled a possible performance improvement here. I set up a simple demo to test the theory. Normal Append. Inventing your own HTML Elements to build a DOM game. This is a small experiment showing how to invent your own HTML Elements to build a game in the DOM.

What are these custom elements? A custom element is an HTML Element that allows you to add your own properties and methods. For example, the basic HTMLElement has a style property and a click() method. By extending the HTML Element we get all this existing functionality and we can add our own. In this experiment we have an element Car that has an x and y property and an update() method: Before we can add our Car element to the DOM, we have to register it, connecting our class to a HTML tag. Window.customElements.define("car-component", Car); Now you can add cars to the dom by placing tags: In our game we prefer to add cars by code.

Document.body.appendChild(new Car()); This will result in a <car-component></car-component> being added to your HTML structure, and the message A car was created! DOM manipulation Lifecycle Game Loop Our game class will create a player element and start the game loop. Why you should always append DOM elements using DocumentFragments. If you ever find yourself appending a series of elements to the DOM, you should always use a DocumentFragment to do just that. A DocumentFragment is a minimal document object that has no parent. It is used as a light-weight version of document to store well-formed or potentially non-well-formed fragments of XML. Why? Not only is using DocumentFragments to append about 2700 times faster than appending with innerHTML, but it also keeps the recalculation, painting and layout to a minimum. TL;DR: Use DocumentFragments. When normally we would do this to append elements: var i = 0; while (i < 200) { div.innerHTML += '<li>My list item #' + i + '</li>'; i++; } doing this would be much faster (although not optimal): var i = 0; while (i < 200) { var el = document.createElement('li'); el.innerText = 'This is my list item number ' + i; div.appendChild(el); i++; }

Lit-html-server/lib at master · popeindustries/lit-html-server. Have HTTP404 errors when Edge dev tools are open · Issue #869 · webcomponents/webcomponentsjs. IE11 support · Issue #900 · webcomponents/webcomponentsjs. Lit-html. Using JavaScript modules on the web  |  Web Fundamentals  |  Google Developers. JavaScript modules are now supported in all major browsers! This article explains how to use JS modules, how to deploy them responsibly, and how the Chrome team is working to make modules even better in the future. What are JS modules? JS modules (also known as “ES modules” or “ECMAScript modules”) are a major new feature, or rather a collection of new features. You may have used a userland JavaScript module system in the past. Maybe you used CommonJS like in Node.js, or maybe AMD, or maybe something else.

JavaScript now has standardized syntax for exactly that. // 📁 lib.mjsexport const repeat = (string) => `${string} ${string}`;export function shout(string) { return `${string.toUpperCase()}! You can then use the import keyword to import the module from another module. // 📁 main.mjsimport {repeat, shout} from '. You could also export a default value from a module: // 📁 lib.mjsexport default function(string) { return `${string.toUpperCase()}! // 📁 main.mjsimport shout from '. Keep bundling. A bit about lit-html rendering – Kenneth Christiansen. So Zouhir has been asking me a bit about how rendering works with lit-html and custom elements base classes, so I decided it might be best to just write a bit here. So for those who don't know, lit-html is a new mini library for generating and updating HTML content. From a user perspective, lit-html feels a whole lot like JSX, but it's all standard JavaScript and no compile step is required! Lit-html uses "tagged string template literals" from ES2015, and you define your markup using the html`` tag.

The cool thing about string template literals is that, for the same tagged template string, they return the same strings and only the values will differ: This allows lit-html to return a TemplateResult object, which can be rendered to the DOM. The interesting part here is that this is very compatible with the Template Instantiation proposal from Apple, which Google is a supporter of. The clever reader probably noticed that you might end up updating parts that didn't change. Directives. Polyfills and Transpilation for Your Custom Elements. Reactjs - How to import bundle created in webpack? Javascript - How do i prevent a .js file being bundled by webpack. Ts-loader. This is the typescript loader for webpack. Getting Started Examples We have a number of example setups to accomodate different workflows. From "vanilla" ts-loader, to using ts-loader in combination with babel for transpilation, happypack or thread-loader for faster builds and fork-ts-checker-webpack-plugin for performing type checking in a separate process.

Not forgetting Hot Module Replacement. Our examples can be found here. Babel ts-loader works very well in combination with babel and babel-loader. Faster Builds As your project becomes bigger, compilation time increases linearly. You probably don't want to give up type checking; that's rather the point of TypeScript. If you'd like to see a simple setup take a look at our simple example. Parallelising Builds It's possible to parallelise your builds. There's two ways to achieve this: happypack and thread-loader. To read more, look at this post by @johnny_reilly on the webpack publication channel. Installation yarn add ts-loader --dev or Running. Bundling TypeScript with Webpack.

The previous post in this Webpack series got you setup in ASP.NET Core, and added features like minifying and hashing to your Webpack bundles. In this post we'll have a look at loaders and how we can use them to add TypeScript support to Webpack. Webpack Loaders Out of the box, Webpack knows how to bundle your JavaScript files. But what if you wanted to work with other types of files? What if you wanted to add CSS or images to your bundles? Maybe your team just adopted ES2015 or TypeScript and you need your code compiled down to ES5 to support a wider range of browsers. Well, this is where Webpack loaders can help. Loaders provide another way for you to extend your Webpack builds. Adding Some TypeScript TypeScript aims to be a superset of JavaScript. In your project, go ahead and add a greeter.ts file to the Scripts.

The code above was adapted from the TypeScript Playground. In the Scripts folder, rename main.js to main.ts. // main.ts import {Greeter} from '. Compiling TypeScript in Webpack. Provide bundled JavaScript files. · Issue #140 · Polymer/lit-element. TypeScript With Babel: A Beautiful Marriage. TypeScript has never been easier thanks to the TypeScript plugin for Babel (@babel/preset-typescript), an official year-long collaboration between the TypeScript and Babel teams.

Discover 4 reasons why TypeScript and Babel are a perfect pair, and follow a step-by-step guide to upgrade to TypeScript in 10 minutes. Huh? What? Why? I didn’t understand the need for this new preset at first. Aren’t Babel and TypeScript two completely different things? After hours of research, my conclusion:TypeScript and Babel are a beautiful marriage.

Let me show you. You already use Babel (or should). You’re in one of these three categories: You already use Babel. Write modern JavaScript without breaking anything. Your JavaScript code needs to run in an old browser? The TypeScript compiler has a similar feature, enabled by setting target to something like ES5 or ES6. Babel uses compat-table to check which JavaScript features to convert and polyfill for those specific target environments. Want React with JSX? “No! The future of Polymer & lit-html. The JavaScript Learning Landscape in 2018. Share this: monday.com helps you manage your projects. Raise your hand if this sounds like you: You’ve been in the tech industry for a number of years, you know HTML and CSS inside-and-out, and you make a good living. But, you have a little voice in the back of your head that keeps whispering, "It’s time for something new, for the next step in your career.

You need to learn programming. " Yep, same here. I’ve served in a variety of roles in the tech industry for close to a decade. Like a lot of people, though, I’m intimidated by the current JavaScript landscape. #The Burden of Information How about this, does this sound familiar, too? You’ve attempted to learn programming before with a few different languages.

Samesies. I’ve gotten halfway through The Rails Tutorial and Learn Python The Hard Way. I can figure out what a PHP file does and understand a bit of jQuery, but if you asked me to sit down and write the most basic of programs, I’d be hard-pressed to do it. Here’s what I found. #Reading. Vaadin. #litelement hashtag. Babel-plugin-transform-jsx-lit-html. Why lit-html is not transpiled to es5 in npm? · Issue #516 · Polymer/lit-html. Performance and Usability as Top Priorities: Interview with Slim.js Creator. Why I’m Betting on Web Components (and You Should Think About Using Them Too) Houston, We Have a Problem I’m a web developer since 2002 in the days that websites were built mostly with server side rendering, and ASP.NET web forms were the new cool kid in the block. In the last decade there has been a big shift from server to client side rendering.

HTML, CSS and JavaScript became the backbone of many apps and nowadays you can find JavaScript everywhere. There are awesome libraries and frameworks that we use daily such as React and Angular and web development is considered cool. But… Houston, we have a problem… In the last 4 years I’m a freelancer consultant and I helped numerous projects both in development and in architecture. One of the biggest problems that some of my customers struggle with is what I call the “Framework Catholic Wedding”. What is that problem you ask? Let me tell you 3 real world stories from my clients: One of my clients, enterprise size company, started to build a new web project one year ago.

Can you spot the repeating theme in these stories? Styling Your Custom Elements. Attributes and Properties in Custom Elements. Smart Accordion Expand Modes Demo. Webcomponents.org. Custom Element Best Practices  |  Web Fundamentals  |  Google Developers. Custom elements allow you to extend HTML and define your own tags. They're an incredibly powerful feature, but they're also low-level, which means it's not always clear how best to implement your own element. To help you create the best possible experiences we've put together this checklist which breaks down all the things we think it takes to be a well behaved custom element.

Checklist Shadow DOM Attributes and properties Events Explainers Don't override the page author It's possible that a developer using your element might want to override some of its initial state. ConnectedCallback() { if (! Make properties lazy A developer might attempt to set a property on your element before its definition has been loaded. In the following example, Angular is declaratively binding its model's isChecked property to the checkbox's checked property. A custom element should handle this scenario by checking if any properties have already been set on its instance. ConnectedCallback() { ... this. Feedback. Abraham/nutmeg: Build, test, and publish vanilla Web Components with a little spice. A Tale of Four Components - Bendyworks: We Make Web and Mobile Apps. There is more than one way to write a web component. You can build a component from scratch or you can rely on one of a growing number of web component libraries. Libraries are great: they handle both the dullest and the trickiest parts, protecting you from boilerplate code and edge-case errors.

But they also increase your component size and sometimes make testing more difficult. To explore the options, this tutorial will create a web component from scratch and then recreate it with three libraries: Nutmeg, Polymer, and Stencil. All of these are good options, but they come with different trade-offs. Read on to find which approach best suits your style and needs.

A Better Image We will make a simple component, which we'll call better-img, that adds a fallback url, an error-logging function, and a caption to an image. In addition, the component will display text or html (or even another component) below the image as a caption. Defining the Component Testing A brief aside about Shadow DOM. Slaying a UI Antipattern with Web Components (and TypeScript) - Bendyworks. <node-package> is a web component that lets you easily embed details about an npm package on your site. To use it you add a tag to your HTML and get a nice bit of UI rendered. It's a component I built with the Nutmeg web component library for use in projects like the Angular PWA Guide. On the surface it's a fairly simple component: fetch some data and render it. When you start digging under the covers there are some hidden complexities and we'll look at a refactor (#53, #61) implementing the RemoteData pattern.

With web components, properties/attributes can be set or changed at anytime. This makes component architecture more difficult and leaves you with no guarantee that attributes name, in the case of <node-package>, will be set when the constructor or connectedCallback runs. Value never set Value set as an attribute Value set after rendering <node-package></node-package><script> document.querySelector('node-package').name = 'twitter-status';</script> Value changed after rendering if (! True Compile/Run-time privacy in WebComponents with TypeScript 2.7.

Hey everyone! As you’ve may noticed, TypeScript 2.7 was released not long time ago and it brings a lot of new features to the table. In this article we will focus primarily on Unique Symbol Types support, in particular within ES2015 classes, which are also a primary building block for WebComponents. For our demonstration purpose, we will implement a simple WebComponent for showing/hiding projected content, with following features: custom element name: my-toggleableit is both stateful and controllable componentpublic API contains 2 props: title and show and 1 default content projection via slot .title is gonna render within shadow-domshow will toggle the content projection visibility from inside the component, or from parent, by setting values to this property ( controlled component pattern )on host click, it will toggle visibility of projected content Usage: <my-toggleable> <p>Some text Lorem ipsum dolor sit amet.

Demo: Ok lets implement our Toggleable WebComponent: Whoops! Using custom elements. Web-components-todo/native/js at master · shprink/web-components-todo. Stencil - works with Edge and IE well. Lit-element-demo slow in Edge browser. Web Components Todo. Shprink/web-components-todo: A simple todo list built with various Web Components technologies. Wc-catalogue/blaze-elements: Web Component Blaze Elements. Building a custom tag input with Skate.js. The Ultimate Guide to JavaScript Frameworks. Fernandopasik/lit-redux-router: Declarative way of routing for lit-html powered by pwa-helpers, redux and lit-element. Redux and state management – PWA Starter Kit. Building a chat with Twilio, lit-html, Parcel and TypeScript. Stencil.js vs lit-element vs Vanilla vs Shadow DOM vs Vue.js. Disappearing Frameworks – Samsung Internet Developers. Let's Build Web Components! Part 5: LitElement. Lets Build Web Components! Part 1: The Standards. CAPTURING AND ANALYZING AN ETW TRACE (event TRACING FOR WINDOWS) – Real world problems; Real world solutions.

Custom Element Best Practices  |  Web Fundamentals  |  Google Developers. Welcome - Polymer 1.0. Skatejs.netlify. Web Components in 2018 - Blog | SitePen. 6 Reasons You Should Use Native Web Components. Webcomponents.org. Custom-element.github. 6 Reasons You Should Use Native Web Components. Mixpanel/panel: Web Components + Virtual DOM: web standards for powerful UIs. Hello, slim.js! Slimjs/slim.js: Fast & Robust Front-End Micro-framework based on modern standards.