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
@developit
developit / array-indexed property access benchmark.js
Created September 16, 2018 00:56
deoptigate -- node --allow-natives-syntax *.js
const { performance } = require('perf_hooks');
const h1 = (tag, props, children) => ({ tag, props, children })
const h2 = (tag, props, children) => ({ tag, props, children })
function serializeProps(props) {
let out = '';
for (let i in props) out += ` ${i}="${props[i]}"`;
return out;
}
import preact from 'preact';
import PropTypes from 'prop-types';
// installs global prop type checking for app preact components
preact.options.vnode = vnode => {
let Component = vnode.nodeName;
if (Component.propTypes) {
PropTypes.checkPropTypes(
Component.propTypes,
vnode.attributes
[{"_id":"5b881b2beccf112e7fa48589","index":0,"guid":"8246c6fb-7cba-4cc6-b1d2-ff22f4a1ae91","isActive":true,"balance":"$3,618.71","picture":"http://placehold.it/32x32","age":32,"eyeColor":"blue","name":{"first":"Henderson","last":"Ball"},"company":"GEOFORMA","email":"henderson.ball@geoforma.us","phone":"+1 (892) 523-3044","address":"277 Bryant Street, Bawcomville, Oregon, 7682","about":"Lorem et in tempor elit mollit irure enim voluptate sint consequat sint fugiat sint. Aute fugiat dolor ullamco aliqua dolor occaecat. Cillum incididunt tempor mollit officia deserunt eu quis commodo adipisicing enim pariatur quis Lorem. Adipisicing eiusmod do et eiusmod ad ut. Sint ea exercitation nisi officia quis consectetur ad. Enim adipisicing officia veniam enim anim voluptate incididunt laborum irure et officia eu.","registered":"Monday, April 28, 2014 3:31 PM","latitude":"-50.104304","longitude":"87.683747","tags":["consectetur","est","quis","nostrud","cillum"],"range":[0,1,2,3,4,5,6,7,8,9],"friends":[{"id":0,"name":"Bra
import { createElement, cloneElement, Component } from 'react'
import { render, findDOMNode } from 'react-dom'
Object.defineProperty(Component.prototype, 'base', {
get() { return findDOMNode(this) }
})
export { createElement, createElement as h, cloneElement, Component }
export { render }
@developit
developit / *valoo.md
Last active July 25, 2026 07:42
🐻 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 / 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);
/*
* Stateless Classful Components
*
* - no access to setState() or forceUpdate()
* - render is still just: props => Element
*/
class Events {
componentDidMount() {
for (let i in this.props) {
@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
/**
* 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
function getClipboardText(e) {
return Promise.resolve().then(function(){
return navigator.permissions.query({ name: 'clipboard-read' })
}).then(function(r) {
return r.state=='granted' && navigator.clipboard.readText()
}).catch(Object).then(function(t) {
return typeof t=='string' ? t : e.clipboardData.getData('text/plain')
})
}