Skip to content

Instantly share code, notes, and snippets.

View evatrium's full-sized avatar

Weston Blair Ross evatrium

View GitHub Profile

Preact CLI with styled-components

This shows how to use styled-components with preact-cli.

Styles are collected and inlined during pre-rendering, with no extra build or configuration step required.

The only configuration change required is to add a constant, just to prevent SSR-specific styled-components code from being loaded on the client.

@marvinhagemeister
marvinhagemeister / little-vdom-decompiled.js
Created March 8, 2020 14:13
Jason little-vdom decompiled
/* eslint-disable no-unused-vars */
/* eslint-disable no-else-return */
// JSX constructor, similar to createElement()
export const h = (type, props, ...children) => {
return {
type,
// Props will be an object for components and DOM nodes, but a string for
// text nodes
props,
export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({children:e.c},e.p),e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props
@rakannimer
rakannimer / add-jest-to-nwb.sh
Last active April 14, 2019 02:29
Adding jest tests to nwb project
yarn add -D jest babel-jest babel-preset-es2015 babel-preset-react react-test-renderer
#Edit package.json adding the jest command :
"scripts": {
"build": "nwb build-react-component",
"clean": "nwb clean-module && npm clean-demo",
"start": "nwb serve-react-demo",
"test": "nwb test",
"test:coverage": "nwb test --coverage",
"test:watch": "nwb test --server",
"test:jest": "jest"
@pygy
pygy / cancelPromise.md
Last active October 30, 2023 09:22
You can already cancel ES6 Promises

The gist: by having a Promise adopt the state of a forever pending one, you can suspend its then handlers chain.

Promise.pending = Promise.race.bind(Promise, [])

let cancel

new Promise(function(fulfill, reject) {
  cancel = function() {fulfill(Promise.pending())}
  setTimeout(fulfill, 1000, 5)