Skip to content

Instantly share code, notes, and snippets.

View trueadm's full-sized avatar

Dominic Gannaway trueadm

View GitHub Profile
@trueadm
trueadm / inferno.md
Last active December 28, 2016 01:10

Inferno

Overview

Inferno is a JavaScript library for creating UIs for dynamic/complex web applications. Inferno is insanely fast, lightweight (8kb gzip), familiar (it uses much of the same API as React), modular and offers some compelling features to help developers craft awesome web apps. You can get started straight away by using inferno-create-app (available on NPM) or by viewing our installation and getting started guides.

Similar to React

Inferno intentionally aims to have the same developer look and feel as React – meaning that Inferno supports the majority of React's API and also utilises a "virtual DOM" behind the scenes. This decision was made due to the stability and high adoption of React in a relatively short period of time. The React API is well-recieved, documented, understood and battle-tested. Inferno could have created its own API, but that would have pushed people into having to learn yet another way of doing things.

@trueadm
trueadm / flatten.js
Created November 2, 2016 17:14
flatten arrays
/**
* Normalizes recursive VNode lists by flattening all nodes, filtering out `null` children and converting strings to
* text nodes.
*/
export function normalizeVNodes(nodes: VNodeRecursiveList): VNode<any>[] {
for (let i = 0; i < nodes.length; i++) {
const n = nodes[i];
if (n === null || Array.isArray(n)) {
let copy = nodes.slice(i);
function clickButton({ setState, state }) {
setState({
counter: state.counter != null ? state.counter + 1 || 0
})
}
function StatefulComponent(props, state, setState) {
return <button onClick={ linkEvent({ setState, state }, clickButton) }>Number is { state.counter || 0 }</button>
}
// spec, both interfaces are lightweight objects that should be creatable in workers and on the main thread
createVirtualElement(
tagName: string,
ref?: Function,
key?: string, // or should it accept key like ES2015 Map keys do?
): VirtualElement
createVirtualTextNode(
text: string,
ref?: Function,
/**
* ReactDOMFiber v16.0.0-alpha.3
*
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
/**
* React v16.0.0-alpha.3
*
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
// imagine if:
function MyComponent(props, state, update) {
return <div>{ props.foo }</div>;
}
// compiled to:
let MyComponent;
'use strict'
var Benchmark = require('benchmark')
var suite = new Benchmark.Suite;
function createList() {
return [1, 2, 3, [[4]], [[[5]]], [6], [[7]]];
}
function flattenRecursive (list) {
"use strict";
class Example1 {
constructor() {
this.counter = 0;
this.settings = {
countTimes: 1000,
};
//
const randomValue = false;
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",