Skip to content

Instantly share code, notes, and snippets.

View developit's full-sized avatar
🦊
write, the codes

Jason Miller developit

🦊
write, the codes
View GitHub Profile
import { Component } from 'preact';
import Snackbar from 'preact-material-components/Snackbar';
const TIMEOUT = 3;
export default class Toaster extends Component {
seen = [];
queue = [];
snackbarRef = c => {

transpiler-lite

So, you need to transpile classes to ES5 for some reason, but you need to do it in the browser.

Could we use a gross regular expression to get that done? Yes.

Should we? No, but it's far too late for that now.

JSFiddle Demo

@developit
developit / *lit-html + unistore.md
Created January 29, 2018 15:17
unistore + lit-html

lit-html + unistore

import { html, render } from 'lit'
import { provide, connect } from './unlit'

const app = provide(store)( () => html`<div>${counter}</div>` )

const counter = connect('count', {
let get = worker(async url => {
let res = await fetch(url)
//throw Error('carp')
return await res.json()
})
setTimeout(async () => {
let obj = await get('https://api.github.com/users/developit')
output.textContent = JSON.stringify(obj, 0, 2);
})
@developit
developit / preact.config.js
Created January 8, 2018 17:08
preact-cli config to push code-splitted css into lazy loaded JS chunks
export default (config, env, helpers) => {
let extract = helpers.getPluginsByName(config, 'ExtractTextPlugin')[0];
if (extract) extract.plugin.options.allChunks = false;
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

preact-cli async/await demo

CLI Commands

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev
@developit
developit / *preact-cli-css-demo.md
Last active November 17, 2017 09:04
Basic preact-cli demo with CSS

Just a basic preact-cli demo with CSS

if (typeof window!=='undefined' && navigator.serviceWorker && navigator.serviceWorker.controller) {
let reloadOnNext = false;
let pushState = history.pushState;
history.pushState = function(state, title, url) {
pushState.call(this, state, title, url);
if (reloadOnNext===true) location.reload(true);
};
navigator.serviceWorker.controller.addEventListener('statechange', e => {
@developit
developit / className-polyfill.js
Created October 16, 2017 13:30
Sets up bidirectional aliasing of props.className <-> props.class in Preact.
import { options } from 'preact';
let def = {
get() {
return this.class;
},
set(v) {
this.class = v;
}
};