• Stars
    star
    217
  • Rank 182,446 (Top 4 %)
  • Language
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is a WIP draft of the Unity (Single File Web Component) Specification

unity-component-specification

This is a WIP draft of the Unity (Single File Web Component) Specification

Abstract

Unity Component Specification describes a new hypertext-like file format for creating Single-File Web Components (SFWC).

Goals

  • rosetta stone-like capabilities component interop between frameworks.

    • provides a promise for users, companies, lib authors to have a single "meta" description of how their "ui component" should function, meanwhile using modern tooling, and small compiler chains, could compile this "meta" information into the framework's actual representation.
  • allow users to ship way less JavaScript and CSS to the browser

  • 60fps scroll lists, fast dom changes, fast paints. "Does it beat the Ken Wheeler Test" (long term platform goal)

Scenario:

Giant company (A) is silo'd and has a variety of different frameworks that they use in house, and they all love the workflows that they have, however there is massive amounts of overlap because they cannot write components that both teams can use.

With "unity components" (Single File Components) this could be possible: Team A using Preact (Figure 1), could use this component in the same way that Team B using 'Vue' (Figure 2) does.

Figure 1: Using Button.sfc in .js file and consumed with preact render() fn

import {Button} from "material-unity" // returns a SFC "module" .sfc or .vue, etc whatever

render(
    <Button someProp="whatever" />,
    document.body
);

Figure 2: Using same Button.sfc inside of a Vue single file component

<template>
    <div>
        <button some-prop="whatever"></button>
    </div>
</template>
<script>
import {Button} from "material-unity" // returns a SFC "module" .sfc or .vue, etc whatever
export default {
  components: {
    Button
  }
}
</script>
<style>
  /* ... */
</style>

The point is that the framework-specific implementation details of how this "meta information" represented in the Single File Component are hidden through the compiler toolchains.

So although you might see data(){} function that returns state for the component, it may instead compile to state in react/preact, or @tracked in GlimmerJS.

How this relates to the platform (the long term idea if frameworks buy in @first)

Although this statement may be opinionated, it is observed that the number one problem with web components currently is that it is a write only target, not something a framework could consume and then use (like their own systems components) without potentially substantial changes to their respective api's, renders, etc. This poses a huge challenge for adoption.

In addition, until there is cross-platform adoption for Web Components completely, there is really no interest for a majority of users or framework teams to start integrating with this system.

Abstraction not only for Frameworks, but also the Platform

The magic behind what makes Vue's single file component structure so flexible and powerful, is that everything inside of their respective tags, is only a "likeness" to some extent.

For example:

<template>
  <div>I look and smell like HTML, but I'm not HTML. I'm HTML-like</div>
</template>
<style>
.div {
  likeness: to-css;
}
</style>
<script>
export default {
  data() {
    maybe: "Interpreted through the context of the component, but technically this could _not_ really be JavaScript, just a state machine's instructions"
  }
}
</script>

In the same way that:

render(
   <JSX>I look and smell like HTML, but I'm not html, I'm JSX, I'm html-like</JSX>,
   document.body
)

So in the same way that a loader, compiler, etc. statically analyzes a .vue file to create a JavaScript implementation of that components Dom API functionality (via VDOM), we can apply the same principle for the platform to accomplish the same thing.

In a real index.html file

<head>
<module type="unity" name="unity-button" src="./unity-components/button.sfc" />
<head>

<body>
  <unity-button some-prop="whatever">Click Me</unity-button>
</body>

We have fed a single component to the browser, which consumes the SFC module, and instead of creating render functions, vdom, JSX, javascript, or anything else, it is interpreted and compiled to native instructions for the lifecycle, state, and the visual representation and behavior for that element on the DOM.

Side Notes:

Here's some things I want to clarify before they get mentioned

Template "Directives"

A huge motivation for the use of these universal directives, is the same reason why they are great in VueJs. Although at any time, in a single-file .vue component, a user can drop <template></template> and instead opt-in to using render(<JSX/>, document.body) instead.

But in the end (for vue):

<template>
  <div v-for="item of 1000000items">{{item}}</div>
</template>

is just an abstraction that compiles to VDOM/Render functions to perform that ginormous scrolling list. The benefit of the platform consuming this, is that it can read that directive as an instruction to perform the same results, but in a far more, Ken Wheeler-defying-90fps-fashion (because its not DOM, or JS, its native instructions interpreted from the file).

JSX inside of <script>

In the same way that <template></template> can be statically analyzed and compiled, you can take this a step further and say the use of JSX inside of <script></script> could have a similar outcome.

Pros:

  • Native calls are fast, no JavaScript DOM API's are called, the render, layout engines, etc. now can compile and manage these just like another implementation detail as direct "assembly like instructions" for how things must be viewed, laid out, painted et al.
  • There is no need to Custom Elements, it is native instructions, there needs to be no extension of existing elements or behaviors.
  • What might compile to a couple hundred lines of code, and be shipped inside of JS, CSS, could now be shipped in a single file, in a non blocking fashion.
  • (Maybe? I'm not an expert in the browser to understand this piece yet) patterns like <style scoped> provides a css-like scoping solution that doesn't have to rely on shadow dom, etc.
  • It doesn't rely on pieces of the existing web component specification, and browsers, (as long as its implemented), could implement this however they would like for their respective platforms, etc.
  • Using in the browser outside of the FW, could be as simple as just dropping the component into a <tag> and using. And this could potentially create a Rosetta Stone-like api for interop between a variety of frameworks (if not all).
  • webpack users could still leverage their own styling and template tools/preprocessors of choice, and webpack will (if this spec is pushed, or at the least 3+ frameworks can adopt it), create an output target for .sfc. That way loaders can still be used to allow one to customize, extend etc while still compiling to .sfc in browserland.

Cons:

  • Silver bullet syndrome: things that become abstracted, can lose flexibility, or have features removed to create interop. This should be carefully balanced and thought out.

  • Not all frameworks can statically compile these formats? (If not what is the MVP amount of changes that we could make to ensure that not only VDOM-frameworks, but also observer, watcher, and bind based libraries can leverage as well.

  • Can dilute the framework capabilities of a specific component type? What may work with a full rich featureset in .vue, may need to have limited capabilities in GlimmerJS, or Polymer. (Or am I wrong. I don't know enough about them to make this assumption, but would like feedback on this.)

  • Pushback in browserland vs WC v2.: Although this could arise, I'm hopeful that because the .sfc format doesn't mandate creation of API's that affect DOM (besides a new module/script type), that this could be easily worked around, and potentially alongside WC v2.

Use Cases

Currently there are multiple JavaScript web frameworks that use an interoperable Single-File Web Component format. Not only are they a unifying formate between frameworks, but should aim to be a native platform implementation.

Unity Component Module

hello-world.ucm

<template>
    <h1>Hello {{world}}!</h1>
</template>

<style>
    h1 {
        background: "red";
    };
</style>

<script>
  export default {
    data() {
      return {
        world: "world"
      }
    }
  }
</script>

Interface

This file format will support a strict subset of hypertext markup tags that will delimit and distinguish the use of JavaScript, HTML, and CSS in the single file.

<template></template> tags

Syntax

  • Any uses of valid HTML, will be valid inside of the <template></template> tags.
  • Always single element root? (like vdom'y stuff or not needed for native implementation)

Data Binding

  • {{ }} will be the syntax. (should we even try to allow this to be overriden?)
  • Any valid expression within braces
  • v-bind= mentioned here?

Directives

  • Explain what the hell a directive does. Could this specification allow for the creation of JS directives, but all built ins are native for performance?
  • List of Built in Directives?

<style></style> tags

Syntax

  • Any uses of valid CSS is permitted inside of the <style></style> tags.

Scoped? 😬

<script></script> tags

Syntax

  • Any uses of valid JS is permitted inside of the <script></script> tags.
  • Must export default a object of properties describing available data bindings, props, computed properties, other registered UCM's, declarations and all other Unity Component Module options.

UCM Options Object

  • // TODO: Add all the Vue Component options here.

More Repositories

1

webpack-workshop-2018

Learning resources for the webpack academy workshop series for 2018
554
star
2

artsy-webpack-tour

Annotations on webpack source code in a pseudo-guided fashion.
524
star
3

webpack-developer-kit

webpack dev kit for writing custom plugins and loaders on the fly. Education/Exploration tool as well.
JavaScript
224
star
4

angular2-template-loader

Chain-to loader for webpack that inlines all html and style's in angular2 components.
JavaScript
206
star
5

bundle-buddy-webpack-plugin

🐐🐐🐐🐐 bundle-buddy-webpack-plugin 🐐🐐🐐🐐
JavaScript
195
star
6

everything-is-a-plugin

Everything is a Plugin: Mastering webpack from the inside out. NgConf 2017
JavaScript
144
star
7

compare-webpack-target-bundles

Example of all the webpack targets!!! Webpack Playground!
JavaScript
140
star
8

angular-starter-es6-webpack

This is an Angular Starter App with component and service generators using gulp for easy component development. Uses Karma-Mocha-Chai as testing suite and Babel Loader and Webpack for ES6
JavaScript
106
star
9

LazyParseWebpackPlugin

(v8-lazy-parse-webpack-plugin) This is a webpack plugin designed to exploit the V8 engines treatment of functions with parens wrapped around them. This lazy loads the parsing decreasing initial load time.
JavaScript
104
star
10

bundler-performance-benchmark

This is a super tiny example of a transparent comparison between parcel and webpack and anyone else who wants to be involved.
JavaScript
61
star
11

angular2-webpack-lite

Super lite boilerplate of Angular2 with Webpack and Typescript.
TypeScript
43
star
12

js-parser-discussions

Discussions & Collaboration on a Unified/Base set of parser features for JavaScript
42
star
13

virtual-dependency-loader

webpack loader that takes a single file, and declare pieces of that file as "dependencies" as if it existed.
JavaScript
33
star
14

code-splitting-examples

VueJs and webpack Code Splitting Examples
JavaScript
28
star
15

vscode-webpack-extension

VSCode Extention Demo for webpack
JavaScript
23
star
16

simple-webpack-wasm-example

Very alpha alpha example of webpack WASM support (just build output) for JS Engine Teams to look at
JavaScript
20
star
17

vue-d3

A fun experimental learning project where I learn how to use d3 while leveraging the power of VueJS
JavaScript
18
star
18

webpack-academy-starting-out-right

This is the starter github repo from https://webpack.academy/p/web-fundamentals
JavaScript
16
star
19

ngc-loader

Webpack support for the Angular2 offline compiler.
TypeScript
13
star
20

example-webpack-loader

A extremely barebones webpack loader example that conforms to our webpack-defaults repo standards
JavaScript
12
star
21

is-wsl

Check if the process is running inside Windows Subsystem for Linux (Bash on Windows)
Rust
10
star
22

prepack-webpack-plugin

Using prepack on your webpack bundles?
9
star
23

npm-package

A lightweight client for fetching package metadata from the npm registry
Rust
9
star
24

require-id-webpack-plugin

A webpack plugin that decorates `require` to a return module id's.
JavaScript
8
star
25

angular2-multievent-bindings-plugin

A small plugin that allows for binding multiple events into an Angular2 template.
TypeScript
7
star
26

example-vscode-bundled-extension

This is a super small and primitive example of a vscode extension being bundled with webpack for faster load and install times.
JavaScript
7
star
27

mersenne-twister-es

A JavaScript Implementation of MersenneTwiseter writting with ES Modules
JavaScript
7
star
28

AnalyticsWebpackPlugin

Plugin using GA to Report Webpack Statistics
JavaScript
5
star
29

webpack-v4-example

Test project that has webpack v4 linked against it. For personal use.
JavaScript
5
star
30

is-docker

Checks if the process is running inside a Docker container. Rust implementation of `sindresorhus/is-docker`
Rust
4
star
31

threeve

Texas with a dollar sign. Component library for VueJs and ThreeJs [WIP DONT USE]
JavaScript
4
star
32

is-interactive

Rust adaptation of sindresorhus/is-interactive from NodeJS
Rust
4
star
33

puppeteer-webpack-plugin

webpack Plugin for running scripts and tests using the Puppeteer Chrome Remote Protocol API
4
star
34

ansi-regex

A rust implementation of @microsoft/node-core-library's ansi regex detection
Rust
3
star
35

is-unicode-supported

Detect whether the terminal supports unicode or not.
Rust
3
star
36

sonar-webpack-plugin

😊😘😍
3
star
37

strip-ansi

Rust inspired implementation of chalk/strip-ansi.
Rust
3
star
38

has-flag

A rust implementation of sindresorhus/has-flag
Rust
2
star
39

experiment-0001

Experiment Number 0001
2
star
40

krate

Get a Rust crates metadata and release information.
Rust
2
star
41

bcmarinacci.theme-material-operator-1.3.0

2
star
42

webpack-stress-test

Stupid simple example repo that helps highlight some build time lengthiness (lots of modules)
JavaScript
2
star
43

webpack-context-modules

Tiny example of using webpack context modules
2
star
44

moo-angular-accordion

AngularJS Directive Component of the UI-Toolkit's Accordion for Mutual of Omaha's DXD Team
JavaScript
1
star
45

ngconf-webpack-wall-of-awesome

This is the code for the Webpack wall of awesomeness!!!
JavaScript
1
star
46

proposal-dot-last

`.last()` proposal for JavaScript
1
star
47

angular-compiler-plugin

Angular Webpack Compiler Plugin for Angular Offline compiler and code generation.
TypeScript
1
star
48

repro-parcel-112

This is a simple repro repo for ParcelJS Issue 112
HTML
1
star
49

sonar-loader

🙌🤣😁💕❤😂🎶🤞✌😎💖🌹💋 Loader for webpack! Get Hyped.
1
star
50

iPortfolio

An iOS App about my engineering background
Objective-C
1
star
51

angular-webpack-slides-ngconf-2016

Slides for Angular2 + Webpack <3 Presentation for ng-conf2016
JavaScript
1
star
52

string_formatted_date

A simple gem for easy date formatting!
Ruby
1
star
53

typescript-alias-webpack-plugin

This is a typescript webpack plugin that automatically maps `paths` property to webpack's `resolve.alias`
1
star