Skip to content

Instantly share code, notes, and snippets.

@treshugart
treshugart / README.md
Last active May 6, 2024 05:03
HMR for generic web components

Generic web component HMR

I'm messing around with a generic way to do hot-module-replacement with generic web components whether they be vanilla, or done in a framework like Polymer or Skate.

The idea is that you call hmr(customElementConstructor) in your module files and it will set up the proper hooks.

The const filename should be inserted at build time so that it can remember the original localName of the component for the module.

WTF is "x-layout", "Layout" and "filename"

@treshugart
treshugart / readme.md
Last active May 6, 2024 05:03
Shadow DOM issues
function wrap(func) {
return function(value) {
try {
return func(value);
} catch (e) {
console.error(e);
throw new Error(e);
}
};
}
import { autorun, toJS } from 'mobx';
import { props } from 'skatejs';
export const withObserver = (Base = HTMLElement) =>
class extends Base {
constructor() {
super();
const { stores } = this;
// This dynamically adds props post construction, so this happens for every instance that is created. One way to
@treshugart
treshugart / readme.md
Last active May 6, 2024 05:02
Skate mixin to rehydrate props and state on the client.

withRehydration

This is a Skate mixin for serialising and rehydrating props and state for a component. Essentially it will apply JSON encoded attributes for props and state after rendering on the server. When rendered on the client, it then takes those attributes and decodes them as props, essentially rehydrating the component state.

Notes

  • The didMount callback is specific to Skate and is called after the component is connected.
  • The didRender callback is specific to Skate and is called after the component renders.

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

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.
@treshugart
treshugart / README.md
Last active May 6, 2024 05:01
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)
@kurozumi
kurozumi / amazon-reservation.py
Created November 9, 2015 07:01
【Python】アマゾン・ホビーカテゴリの予約商品のasinと発売日を取得
# coding: utf-8
from selenium import webdriver
import re
asins=[]
driver = webdriver.PhantomJS()
for page in range(1,3):

Flow / TypeScript definition files

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