Stencil: The Time for Vanilla Web Components has Arrived

Similar documents
One language to rule them all: TypeScript. Gil Fink CEO and Senior Consultant, sparxys

Angular 4 Syllabus. Module 1: Introduction. Module 2: AngularJS to Angular 4. Module 3: Introduction to Typescript

Lab 1 - Introduction to Angular

International Research Journal of Engineering and Technology (IRJET) e-issn: Volume: 05 Issue: 06 June p-issn:

"Charting the Course... Comprehensive Angular. Course Summary

AngularJS Fundamentals

Full Stack boot camp

Advanced React JS + Redux Development

High Performance Single Page Application with Vue.js

Templates and Databinding. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Frontend UI Training. Whats App :

ANGULAR 2.X,4.X + TYPESRCIPT by Sindhu

Getting Started with ReactJS

Web Development for Dinosaurs An Introduction to Modern Web Development

PHP WITH ANGULAR CURRICULUM. What you will Be Able to Achieve During This Course

An Brief Introduction to a web browser's Document Object Model (DOM) Lecture 20 COMP110 Spring 2018

Advance Mobile& Web Application development using Angular and Native Script

welcome to BOILERCAMP HOW TO WEB DEV

Arjen de Blok. Senior Technical Consultant bij ICT Groep ( sinds 1995 Programmeren sinds 1990 Technologiën. Links

International Research Journal of Engineering and Technology (IRJET) e-issn: Volume: 05 Issue: 05 May p-issn:

"Charting the Course... Comprehensive Angular 5. Course Summary

55249: Developing with the SharePoint Framework Duration: 05 days

ANGULAR2 OVERVIEW. The Big Picture. Getting Started. Modules and Components. Declarative Template Syntax. Forms

Vue.js Developer friendly, Fast and Versatile

Angular 2 Programming

Building Your own Widget with ArcGIS API for JavaScript

DECOUPLING PATTERNS, SERVICES AND CREATING AN ENTERPRISE LEVEL EDITORIAL EXPERIENCE

An Brief Introduction to a web browser's Document Object Model (DOM) Lecture 24

STARCOUNTER. Technical Overview

Angular 2 and TypeScript Web Application Development

"Charting the Course... MOC A: Developing with the SharePoint Framework. Course Summary

Front End Nanodegree Syllabus

Modern and Responsive Mobile-enabled Web Applications

Chapter 1 - Development Setup of Angular

Treating Framework Fatigue With JavaScript

Lecture 8. ReactJS 1 / 24

RequireJS Javascript Modules for the Browser. By Ben Keith Quoin, Inc.

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

IN4MATX 133: User Interface Software

Cisco Spark Widgets Technical drill down

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Decoupled Drupal with Angular

Deep Dive on How ArcGIS API for JavaScript Widgets Were Built

Welcome. Quick Introductions

CodeHub. Curran Kelleher 8/18/2012

Approaches to wrapping React. Thursday 3 September 15

JavaScript Rd2. -Kyle Simpson, You Don t Know JS

React. HTML code is made up of tags. In the example below, <head> is an opening tag and </head> is the matching closing tag.

Single Page Applications using AngularJS

Ten interesting features of Google s Angular Project

THE PRAGMATIC INTRO TO REACT. Clayton Anderson thebhwgroup.com WEB AND MOBILE APP DEVELOPMENT AUSTIN, TX

a Very Short Introduction to AngularJS

Course Outline. ProTech Professional Technical Services, Inc. Comprehensive Angular 7 Course Summary. Description

An Overview of. Eric Bollens ebollens AT ucla.edu Mobile Web Framework Architect UCLA Office of Information Technology

Angular 2 and Hexo. Static Meets Dynamic For the Best of Both Worlds! Copyright 2016 Code Career Academy

The Eclipse Rich Ajax Platform

Front End Nanodegree Syllabus

Extending Blue Ocean Keith Zantow

Introduction to. Angular. Prof. Dr.-Ing. Thomas Wiedemann.

A Closer Look at XPages in IBM Lotus Domino Designer 8.5 Ray Chan Advisory I/T Specialist Lotus, IBM Software Group

"Charting the Course... Comprehensive Angular 6 Course Summary

Data Types and the main Function

React(.js) the Domino Way High-Performance Client for Domino. Knut Herrmann

Angular 5 vs. React When to Choose Which?

Pro JavaScript. Development. Coding, Capabilities, and Tooling. Den Odell. Apress"

Front-End Web Developer Nanodegree Syllabus

Full Stack Developer with Java

CISC 1600 Lecture 2.4 Introduction to JavaScript

React + React Native. Based on material by Danilo Filgueira

React.js. a crash course. Jake Zimmerman January 29th, 2016

Offline-first PWA con Firebase y Vue.js

Advanced Angular & Angular 6 Preview. Bibhas Bhattacharya

Angular 2 and TypeScript Web Application Development

Interactor Tree. Edith Law & Mike Terry

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

AEM React. History. 1 Introduction. AEM components written in React. Why React and AEM? Features. Projects. date author message changed chapters

Introduction to Sencha Ext JS

JavaScript Fundamentals_

Introduction to the SharePoint Framework Bob German Principal Architect - BlueMetal. An Insight company

McLab tools on the web. Deepanjan Roy Supervisor: Prof. Laurie Hendren

HOW REACT NATIVE AND NATIVESCRIPT CHANGE YOUR MOBILE STRATEGY SEBASTIAN

Concepts of programming languages

WebApp development. Outline. Web app structure. HTML basics. 1. Fundamentals of a web app / website. Tiberiu Vilcu

Beyond JavaScript Frameworks: Writing Reliable Web Apps With. Elm. Erik Wendel DevDays Vilnius 2018

Web Components. Reactive Architecture for the Front End. Steven Skelton. Reactive Programming Toronto December 3, 2014

Future Web App Technologies

Vue.js Framework. Internet Engineering. Spring Pooya Parsa Professor: Bahador Bakhshi CE & IT Department, Amirkabir University of Technology

Getting Started with

Modern SharePoint and Office 365 Development

Learn Web Development CodersTrust Polska course outline. Hello CodersTrust! Unit 1. HTML Structuring the Web Prerequisites Learning pathway.

Calendar Management A Demonstration Application of TopBraid Live

Comprehensive AngularJS Programming (5 Days)

Developing ASP.NET MVC Web Applications (486)

IN4MATX 133: User Interface Software

An Introduction to TypeScript. Personal Info

Nick Senger & Jesse van den Kieboom

Front End Summit - Sep 27th

HTML version of slides:

Lesson: Web Programming(6) Omid Jafarinezhad Sharif University of Technology

Ur/Web: A Simple Model for Programming the Web. Adam Chlipala MIT CSAIL POPL 2015 January 15, 2015

Transcription:

Stencil: The Time for Vanilla Web Components has Arrived Gil Fink sparxys CEO @gilfink / www.gilfink.net

Typical Application Web Page Design

From Design to Implementation Session List Day tabs Component Child component <session-list /> <tabs /> Agenda Child component <agenda /> Agenda filters Child component <agenda-filters />

How would you build that page?

Do we really need all these frameworks/libraries?

What if we could teach the browser new elements?

Each Element Instance Will be a DOM element Creates its own DOM tree Can be accessed and manipulated using DOM functions or its own API Is a JavaScript object Is this possible?

This is where our journey begins

About Me sparxys CEO and senior consultant Microsoft MVP in the last 9 years Pro Single Page Application Development (Apress) co-author 4 Microsoft Official Courses (MOCs) co-author GDG Rishon and AngularUP co-organizer

Agenda The Problems We Faced Web Components APIs Stencil

Undescriptive Markup Markup Example

Poor Separation of Concerns You want HTML, CSS and JavaScript to work together You end up with a mess The wiring gets in your way!

Bundling is Hard You want to bundle a complex component The component includes HTML, CSS and JavaScript how would you do that? Use a server side mechanism? Bundler? (Webpack/Browserify)

Web Components Standard to The Rescue Natively-supported, standardized JavaScript components Some general goals: Code Reuse Encapsulation Separation of Concerns Composition Theming Expressive Semantic

The Web Components Standard Templates Reusable DOM fragments Imports Load HTML declaratively Shadow DOM Custom Elements DOM encapsulation Create your own elements

Custom Elements Enable to extend or create custom HTML elements Defined using the customelements.define function: var myinput = window.customelements.define( my-input, class x extends HTMLElement { }); or extend an existing element: var myinput = window.customelements.define( my-input, class y extends HTMLInputElement {...});

Custom Elements Usage Use the element in your DOM: <my-input></my-input> or use the createelement function: var elm = document.createelement( my-input );

Custom Element Life Cycle Events connectedcallback disconnectedcallback attributechangedcallback class MyInput extends HTMLElement { constructor() { super(); // your initialization code goes here } connectedcallback() { } disconnectedcallback() { } attributechangedcallback() { } }

Demo Custom Elements

A Problem with Web Development Today Catholic wedding with frameworks/libraries Infrastructure is based on a framework/library Infrastructure isn t reusable if other company projects use another framework/library

Problem with Web Development Today Cont. Custom Elements can remove the barrier of framework/library coupling Can be used by any framework/library Encapsulate their functionality and style Suitable for component infrastructure development

But there are problems with custom elements

Problems with Custom Elements We are used to runtime framework/library goodies such as: Virtual DOM Data binding Performance Server side rendering And etc.

Problems with Custom Elements Cont. Verbose syntax Too much boilerplate We need to craft everything by ourselves

Problems with Custom Elements Cont. Still W3C working draft Need Polyfills in some browsers

Is there a better way?

What if I told you that you can solve all the previous problems?

What is Stencil? A compiler that generates Custom Elements Not a framework/library Output is 100% standards-compliant web components Adds powerful framework features to Web Components Virtual DOM Reactivity JSX TypeScript And etc. Created and used by Ionic Framework

Stencil Component Example import { Component, Prop } from '@stencil/core'; @Component({ tag: 'my-name', styleurl: 'my-name.scss' }) export class MyName { @Prop() name: string; render() { return ( <p> Hello, my name is {this.name} </p> ); } }

From Stencil to Custom Elements Stencil Code Stencil Compiler JavaScript Code import { Component, Prop } from '@stencil/core'; @Component({ }) export class CollapsiblePanel { } Stencil Compiler var CollapsiblePanel = (function () { function CollapsiblePanel() { } // implementation return CollapsiblePanel; }());

Getting Started with Stencil git clone https://github.com/ionic-team/stencil-component-starter.git my-component cd my-component git remote rm origin npm install npm start

Demo Hello Stencil

Stencil Generated Component Advantages Virtual DOM fast DOM updates without common DOM performance pitfalls Lazy Loading By default components load asynchronously and can be bundled with related components Reactivity Efficient updates based on property and state changes High-performance Rendering async rendering system, similar to React Fiber

Stencil API Based on JavaScript decorators Written with TypeScript You can use the following decorators: @Component() @Prop() @State() @Event() @Listen() @Element() @Method()

@Component Decorator The main Stencil decorator Configures the entire component including Tag Style Shadow DOM Host Assets import { Component } from '@stencil/core'; @Component({ tag: 'st-comp', styleurl: 'comp.scss', shadow: true }) export class Comp {... }

@Prop and @State Decorators The Prop decorator is used to indicate that a member is exposed as component attribute The State decorator is used to indicate that a member is part of the component state Reactivity import {Component, Prop, State} from '@stencil/core'; @Component({ tag: 'collapsible-panel', styleurl: 'collapsible-panel.css' }) export class CollapsiblePanel { @Prop() title: string; @State() collapsed: boolean;... }

@Method Decorator The Method decorator is used to expose component API import { Component, Element, Method } from '@stencil/core'; @Component({... }) export class Toaster { @Element() toasterdiv: HTMLElement; } @Method() showtoast() { this.toasterdiv.style.display = 'block'; };

Demo Creating a Stencil Component

Deploying a Stencil Component Update the stencil.config.js file, if needed stencil.config.js in Stencil starter already has these things configured exports.config = { namespace: 'myname', generatedistribution: true, generatewww: false,... };

Deploying a Stencil Component Cont. Update the package.json file, if needed { "main": "dist/collection/index.js", "types": "dist/collection/index.d.ts", "collection": "dist/collection/collection-manifest.json", "files": [ "dist/" ], "browser": "dist/myname.js",... }

How Stencil Solves the Frameworks Problem? Stencil works primarily in build time Any framework/library (such as React or Angular) can consume the generated component As a script tag As a node module Using the stencil-starter-app Stencil is suitable for infrastructure components

Demo Consuming a Stencil component from Angular

A Word About Micro Frontends Micro-app 1 Micro-app 2 Micro-app 3 Shared Components and Behaviors Generate

Summary Web Component standard is very powerful But still in development Stencil compiler can ease the pain of creating custom elements Includes a lot of advantages such as JSX, TypeScript and more Generates standard-compliant web components

Resources Stencil website: https://stenciljs.com/ Custom Elements: https://developer.mozilla.org/en- US/docs/Web/Web_Components/Custom_Elements My Website http://www.gilfink.net Follow me on Twitter @gilfink

#UseThePlatform

Thank You!