Skip to content

Instantly share code, notes, and snippets.

View treshugart's full-sized avatar
😅
🍊 ⛸

Trey Shugart treshugart

😅
🍊 ⛸
  • Looker
  • Santa Cruz
View GitHub Profile
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 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)
@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/[\^~].*//'

Flow / TypeScript definition files

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

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:

@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 / example.js
Last active December 7, 2020 04:02
Pseudo shadow DOM at the custom element level. When element is updated, `childNodes` is set, thus it's a single entry point for updates. Custom distribution is required.
/** @jsx h */
// You only need custom elements for this!!!
import 'skatejs-web-components/src/native-shim';
import { Component, define, h, prop } from 'skatejs';
import ShadowNode, { scopeCss, scopeTree } from './shadow-node';
// Converts real DOM nodes into Incremental DOM nodes.
//
// This is orthogonal to this gist, but makes it so we can distribute real
@treshugart
treshugart / dom-context.js
Last active February 23, 2017 01:38
Setting context props at specific DOM tree levels on elements.
const _context = Symbol();
let currentContext = null;
function getContext (elem) {
elem.dispatchEvent(new Event('__context', {
bubbles: true,
cancelable: true,
composed: true,
scoped: true
}));
@treshugart
treshugart / test.js
Created February 3, 2017 03:15
I used https://github.com/lelandrichardson/enzyme-example-karma-webpack for a default setup and then put the following in the test file.
import React, { Component } from 'react';
import styled from 'styled-components';
import { mount } from 'enzyme';
describe("A suite", function() {
it("should select an element using standard and non-standard DOM attributes", function() {
const StyledComponent = styled.div`
background-color: black;
`;
class Test extends Component {