Skip to content

Instantly share code, notes, and snippets.

View treshugart's full-sized avatar
😅
🍊 ⛸

Trey Shugart treshugart

😅
🍊 ⛸
  • Looker
  • Santa Cruz
View GitHub Profile

Glimmer SkateJS (web component) renderer

Currently this is just a spike to see how to do a renderer in Skate for Glimmer.

Rationale

Custom element support for Glimmer is currently minimal and Skate already has most of this stuff solved, and since it is web component DOM abstarction over renderers, it makes sense for Glimmer to be one of those targets.

Things to work out:

Flow / TypeScript definition files

These are the definition files generated from the SkateJS source, written in Flow, for both Flow and TypeScript.

@treshugart
treshugart / source-branch.sh
Created June 1, 2017 17:13
Returns the branch that a given branch was branched off of with acceptable accuracy. Obviously it doesn't work for master.
git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'
@treshugart
treshugart / README.md
Last active August 11, 2017 23:33
Web component that allows you to define a split point in your code at the component level.

Trying to attempt a similar pattern in Web Components that was done here in React. Props to James Kyle for the original idea :)

@treshugart
treshugart / deferred.js
Last active August 11, 2017 23:33
SkateJS code-splitting with Webpack 2
import { Component, h } from 'skatejs';
class Deferred extends Component {
renderCallback () {
return <span>Yay! Loaded!!!</span>;
}
}
customElements.define('x-deferred', Deferred);
@treshugart
treshugart / slot.js
Created September 5, 2016 02:48
SkateJS stateless function for doing stuff with slotted nodes on first render and subsequent renders (slotchange event only fires on updates)
const $slotRendered = Symbol();
const Slot = (props, chren) => {
const { changed } = props;
function onSlotchange(e) {
const slot = e.target;
if (slot[$slotRendered]) {
if (changed) {
changed(slot);
}
@treshugart
treshugart / README.md
Last active August 19, 2017 20:38
Declaratively import declarative custom elements built on SkateJS.

This allows you to define a custom element declaratively in HTML using lit-html and SkateJS. Ideally you wouldn't need either, but they exemplify what a platform-like solution could look like that gives you:

  • One-way attribute to property reflection.
  • Semantic props (i.e. boolean)
  • Functional rendering pipeline, like a vDOM (lit-html)
import React, { Component } from 'react';
import { render } from 'react-dom';
import { props, withProps } from 'skatejs/esnext/with-props';
import { withRender } from 'skatejs/esnext/with-render';
// This is the React renderer mixin.
const withReact = Base => class extends withRender(withProps(Base || HTMLElement)) {
get props () {
// We override props so that we can satisfy most use
// cases for children by using a slot.
const express = require('express');
const app = express();
const delay = (...args) =>
args.reduce(
(prev, curr) =>
prev.then(() => new Promise(yey => setTimeout(() => yey(curr()), 2000))),
Promise.resolve()
);

Declarative / composed Shadow DOM

This is a light proposal for Shadow DOM (no pun intended). The purpose of this proposal is to flesh out how we can take the current state of Shadow DOM and allow certain aspects of it to be used separately and composed together. The goals are:

  1. Being able to use CSS encapsulation separately from DOM encapsulation (SSR is one beneficiary of this)
  2. Being able to enable DOM encapsulation on a previously CSS-only encapsulated node (rehydration)
  3. Maintaining backward compatibility

CSS-only encapsulation