Skip to content

Instantly share code, notes, and snippets.

View treshugart's full-sized avatar
😅
🍊 ⛸

Trey Shugart treshugart

😅
🍊 ⛸
  • Looker
  • Santa Cruz
View GitHub Profile
@treshugart
treshugart / duct.js
Last active May 6, 2024 04:59
Promised-based testing using console / error / info in ~60 LoC complete with suites, custom reporters, summaries and a few assertions via Error.
const done = () => {}
const indent = (depth, info) => [...Array(depth)].reduce(p => `${p} `, '') + info;
const reporter = {
fail: ({ depth, message, name }) => {
console.info(indent(depth, `✗ ${name}`));
console.error(indent(depth + 1, message));
},
pass: ({ depth, name }) => console.info(indent(depth, `✓ ${name}`)),
suite: ({ depth, name }) => console.info(indent(depth, name)),
test: () => {}
@treshugart
treshugart / example.jsx
Last active May 6, 2024 04:53
Give yourself full control over the DOM that any hyperscript VDOM style function creates http://www.webpackbin.com/4kR0ZnXFf
import hify from './create-element';
import React from 'react';
import { render } from 'react-dom';
const h = hify(React.createElement.bind(React));
class Test extends HTMLElement {
static observedAttributes = ['attr']
attributeChangedCallback (name, oldValue, newValue) {
this.innerHTML = `Hello, ${this.getAttribute('attr')}!`;
@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 {
@treshugart
treshugart / dom-context.js
Last active May 6, 2024 05:00
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 / example.js
Last active May 6, 2024 05:01
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 / 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 / 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 :)

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/[\^~].*//'