Skip to content

Instantly share code, notes, and snippets.

View ngryman's full-sized avatar

Nicolas Gryman ngryman

View GitHub Profile
@ngryman
ngryman / dropdown-menu.js
Last active January 31, 2018 10:53
Gradual usages
class DropdownMenu {
state = {
isMenuOpened: this.props.isMenuOpened
}
static defaultProps = {
togglerLabel: 'Show menu'
}
componentDidMount() {
const Editor = () => {
const update = (e, actions) => {
// strip html and get the text only
const source = e.target.innerText
// parse text into tokens stored in `state.tokens`
actions.parse(source)
}
// render tokens to vnodes
@ngryman
ngryman / example.js
Created July 9, 2017 14:05
Router extensions
import { Route, RouterEvents } from './router-exts'
const TrackScreen = html`
<section class="track-screen'
onenter=${() => console.log('enter track screen')}
onleave=${() => console.log('leave track screen')}
></section>
`
const HomeScreen = html`
@ngryman
ngryman / readme.md
Last active July 9, 2017 08:44
Hydration

The aim of hydratation is to avoid trashing out of existing DOM rendered by SSR, but use them and attach eventual event listeners (like a regular patch pass).

Hydratation would happen at the app level and at the first render. Basically it needs a way to know that some part of the DOM tree is something to patch so it does not have to mount.

Before going on, some terminology:

  • The root is the root DOM node generated by HyperApp, the toplevel DOM element.
  • The host is the DOM node that will hold the root, it's currently defined as app.root.
/**
* Having a constructor tells the VM that this object as a given "shape".
* If this shape is constant, all the code manipulating it will eventually
* be optimized into specialized stubs. This has a HUGE performance impact
* and that's why sometimes JavaScript can be so close to the metal.
*/
function VNode(tag, data, children) {
this.tag = tag
this.data = data
this.children = children || []
@ngryman
ngryman / type-feedback-leak.js
Created June 20, 2017 20:38
Prevent type feedback leakage.
// Need to generate core of the benchmark dynamically to ensure
// that type feedback does not leak between individual sample runs.
var code = " /* " + (UID++) + " */ " + " for (var i = 0; i < N; i++) {" +
" var obj = arr[i];" +
" result += obj.x + obj.y + i;" +
"}" +
"return result";
@ngryman
ngryman / output.txt
Last active September 16, 2016 00:04
nyc issue
v6.5.0
3.10.3
/Users/ngryman/Projects/arbre
├─┬ babel-plugin-istanbul@2.0.1
│ ├─┬ find-up@1.1.2
│ │ └─┬ pinkie-promise@2.0.1
│ │ └── pinkie@2.0.4
│ ├─┬ istanbul-lib-instrument@1.1.1
│ │ ├─┬ babel-generator@6.14.0
│ │ │ └─┬ detect-indent@3.0.1
@ngryman
ngryman / index.js
Last active May 26, 2016 17:57
Browserify incremental memory cache bug
'use strict'
const browserify = require('browserify')
const concat = require('concat-stream')
const delay = require('delay')
const fs = require('fs')
const incremental = require('browserify-incremental')
const forceMode = '--force' === process.argv[2]
@ngryman
ngryman / umd.js
Last active September 26, 2017 16:01
Simple UMD
!function(root, factory) {
if ('function' === typeof define && define.amd)
define('mymodule', [], function() { return (root.mymodule = factory()) })
else if ('object' === typeof module && module.exports)
module.exports = factory()
else
root.mymodule = factory()
}(this, function() {
'use strict'
@ngryman
ngryman / octo-search.js
Created February 11, 2016 17:04
Search something on Github - wip
function checkValidity(url) {
return /https:\/\/github.com\/[\w-.]+\/[\w+.]/i.test(url)
}
function setup(baton) {
baton.baseUrl = 'https://api.github.com/repos/' + baton.owner + '/' + baton.repo + '/git'
return Promise.resolve(baton)
}
function fetchMasterRef(baton) {