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
@andrewiggins
andrewiggins / Readme.md
Last active March 27, 2018 13:21
Preact componentDidCatch performance

Preact componentDidCatch performance

Environment

  • The benchmark was run on a HP Z440 (3.5 GHz Intel Xeon E5-1650 v3, 32 GB RAM, Windows 10 1709, Chrome 64.0.3282.186 (64-bit))
  • Ran npm run selenium -- --count 10 --framework preact in the webdriver-ts of this js-framework-benchmarks fork

Duration in milliseconds ± standard deviation (Slowdown = Duration / Fastest)

@janbaykara
janbaykara / Piranhas.js
Last active October 8, 2018 10:39
Organise batch operations on an array by Web Workers, in conjunction with workerize-loader (or any other promise-ified Web Worker implementation!)
/**
* Handles multithread processing on an array through promise-ified Web Workers
* (through workerize-loader https://github.com/developit/workerize-loader)
*
* @example
* const piranhas = new Piranhas(
* Worker,
* // Listens for messages from workers
* e => { e.data.type === 'INCREMENT' && someIncrementer() }
* )
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="./clooney.min.js"></script>
<script>
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.greenlet=n()}(this,function(){return function(e){var n=new Worker(URL.createObjectURL(new Blob(["onmessage=("+function(e){return function(n){var t=n.data;return Promise.resolve().then(function(){return e.apply(e,t[1])}).then(function(e){postMessage([t[0],null,e])},function(e){postMessage([t[0],""+e])})}}+")("+e+")"]))),t=0,o={};return n.onmessage=function(e){var n=e.data,t=n[0],r=n[1];o[t][r?1:0](r||n[2]),delete o[t]},function(){for(var e=[],r=arguments.length;r--;)e[r]=arguments[r];return new Promise(function(r,u){o[++t]=[r,u],n.postMessage([t,e])})}}});
//# sourceMappingURL=greenlet.umd.js.map
</script>
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

import App from './components/app';
import { h, render } from 'preact';
import { default as renderToString } from 'preact-render-to-string';
import { ServerStyleSheet } from 'styled-components'
if(typeof window === undefined) {
const sheet = new ServerStyleSheet()
const html = renderToString(sheet.collectStyles(<App />))
const styleTags = sheet.getStyleTags() // or sheet.getStyleElement()
}
@SaraVieira
SaraVieira / gist file.md
Last active December 5, 2023 11:59
The Origin of Furries

In this talk we will be all discussing the origin of the furry fandom. How we will thogheter create a new furry-in-js framework. We will going over how they have changed the current fandom world, our hearts and the js world in 5 very awesome minutes! This talk is to prove a point that stars mean nothing in this case.

https://reactiveconf.com/

@zz85
zz85 / greenlet.js
Last active June 17, 2019 20:52
Greenlet.js Annotated
// This is @zz85's attempt to understand and annotate the greenlet.js lib
// from https://github.com/developit/greenlet/blob/master/greenlet.js
/** Move an async function into its own thread.
* @param {Function} fn The (async) function to run in a Worker.
*/
export default function greenlet(fn) { // greenlet takes in a function as argument
let w = new Worker( // creates a web worker
URL.createObjectURL( // that has a local url
new Blob([ // created from a blob that has the following content
@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', {
@adactio
adactio / minimal-serviceworker.js
Last active August 18, 2023 09:15
An attempt at a minimal viable service worker.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
// HTML files: try the network first, then the cache.
// Other files: try the cache first, then the network.
// Both: cache a fresh version if possible.
// (beware: the cache will grow and grow; there's no cleanup)
const cacheName = 'files';