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
@marvinhagemeister
marvinhagemeister / *valoo.md
Last active July 14, 2018 20:20 — forked from developit/*valoo.md
🐻 Valoo: just the bare necessities of state management. 150b / 120b. https://npm.im/valoo

🐻 valoo

just the bare necessities of state management.

Usage

Hotlink it from https://unpkg.com/valoo.

See Interactive Codepen Demo.

@developit
developit / *valoo.md
Last active November 13, 2023 08:39
🐻 Valoo: just the bare necessities of state management. 150b / 120b. https://npm.im/valoo

🐻 valoo

just the bare necessities of state management.

Usage

Hotlink it from https://unpkg.com/valoo.

See Interactive Codepen Demo.

@searls
searls / router-hack.js
Last active June 17, 2018 16:11
override preact-router so we can synchronously change the route & trigger a render
/*
* override preact-router so we can synchronously change the route & trigger a render
* reason for doing this: often a UI action triggers an XHR which in turn will determine
* where the user needs to go next (it's a flashcard game, so whether they got it right or wrong
* will determine whether their session has concluded, whether to draw the next card, and so on)
* as a result we have a lot of action logic that wants to in one-fell-swoop programmatically route
* the user to a different component and also update the properties passed to the components by
* re-rendering (one big top-level render function, all state just passed by props, no stateful components)
*
* The practical effect of this change versus the built-in router was that it cuts the number of
@developit
developit / preact-unrecycle.js
Last active January 28, 2019 04:27
preact-unrecycle.js
/** Usage:
* const MyView = unrecycle(props => {
* // this is normally a no-go and creates leaking styles, but it won't with unrecycle():
* <input ref={ c => c && c.style.background='red' } />
* })
*/
export default function unrecycle(Component) {
return function Unrecycle(props, context) {
this.componentWillUnmount = dontRecycle;
return Component.call(this, props, context);
@justinfagnani
justinfagnani / README.md
Last active April 21, 2022 08:45
Inline JavaScript Modules Definitions

Inline JavaScript Module Definitions

Motivation

Domenic's blöcks proposal outlines a way to conveniently define functions that run in another worker/worklet as an inline, non-capturing scope, function body.

Blöcks as proposed have a few open questions and lack a few features that could generalize them to more use cases and with more practical ergonomics.

  • Blöcks don't allow static imports, which makes it harder for them to import neccessary library code. They must rely on dynamic import, which is somewhat more difficult to statically analyzer.
@developit
developit / workerize-pool.js
Last active January 5, 2024 15:49
Simple pooling for workerize / workerize-loader.
/**
* Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
import { canRoute, customHistory, routeTo } from './preact-router.local';
import { appRegistry, eventsService } from '../../../services/service-manager';
/**
* Local setURL function overwrite from preact-router
*
* @param {string} url url, applied to router
* @param {string} type optional operation name, default = push
* @param {{ realURL: string, displayURL: string }} newState state object
*/
/**
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ForsakenHarmony
ForsakenHarmony / gql-ws.js
Last active July 10, 2018 15:26
Graphql over websockets
import { watch as watchOnline } from 'is-offline';
import Sockette from 'sockette';
const msg_types = {
GQL_CONNECTION_INIT: 'connection_init', // Client -> Server
GQL_CONNECTION_ACK: 'connection_ack', // Server -> Client
GQL_CONNECTION_ERROR: 'connection_error', // Server -> Client
GQL_CONNECTION_TERMINATE: 'connection_terminate', // Client -> Server
GQL_START: 'start', // Client -> Server
GQL_DATA: 'data', // Server -> Client
@paulirish
paulirish / eqt.js
Last active April 26, 2020 01:14
Expected Queueing Time metric
// Expected Queueing Time
// https://docs.google.com/document/d/1Vgu7-R84Ym3lbfTRi98vpdspRr1UwORB4UV-p9K1FF0/edit
// Initial impl by Nicolás Peña (npm), Tim Dresser (tdresser)
// Usage:
// var eqt = EQT.begin();
// // ...
// const {expectedQueueingTime} = EQT.end();
class EQT {
constructor() {