Skip to content

Instantly share code, notes, and snippets.

Sebastian Markbåge sebmarkbage

Block or report user

Report or block sebmarkbage

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
sebmarkbage / The
Last active Aug 17, 2019
The Rules of React
View The

The Rules of React

All libraries have subtle rules that you have to follow for them to work well. Often these are implied and undocumented rules that you have to learn as you go. This is an attempt to document the rules of React renders. Ideally a type system could enforce it.

What Functions Are "Pure"?

A number of methods in React are assumed to be "pure".

On classes that's the constructor, getDerivedStateFromProps, shouldComponentUpdate and render.

View Infrastructure.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
if (pending.has(url)) {
throw pending.get(url);
sebmarkbage / SubscriptionIsHard.js
Last active Jun 27, 2019
Subscription Is Hard?
View SubscriptionIsHard.js
class SubscriptionDoneRight extends Component {
state = {
getDerivedStateFromProps(props, state) {
return {
sebmarkbage / propertynames.txt
Last active Aug 23, 2017
Attribute/Property Name Smoke Test
View propertynames.txt
sebmarkbage / API.js
Last active Apr 20, 2018
Custom Stack Frames
View API.js
type FrameScope = {
[key:string]: mixed
type StackFrame = {
name?: string,
fileName?: string,
lineNumber?: number,
columnNumber?: number,
scope?: FrameScope
View shortout.js
(function() {
/** Used to detect hot functions by number of calls within a span of milliseconds. */
var HOT_COUNT = 800,
HOT_SPAN = 16;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeNow =;
sebmarkbage /
Last active Mar 9, 2017
ECMAScript Tagged Object

Tagged Objects

The goal is to implement a form of pattern matching that works well in the existing dynamic environment of ECMAScript.

The goal is to find a way to do efficient pattern matching such as using an object tag. JS VMs already have a field for this that is used to tag various kinds of built-in objects.

This tag could be extended to also include a user space range.

The Mechanism

sebmarkbage / asyncToReact.js
Last active Sep 24, 2018
Convert Async Function to React Component
View asyncToReact.js
function asyncToReact(fn) {
class PromiseComponent extends React.Component {
state = { waiting: true, result: null };
componentDidMount() {
fn(...this.props.args).then(result => this.setState({ waiting: false, result }));
componentDidUpdate() {
fn(...this.props.args).then(result => this.setState({ waiting: false, result }));
shouldComponentUpdate(newProps) {
sebmarkbage /
Created Aug 9, 2016
React Isomorphic Package
* React v16.0.0-alpha
* 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.
View shallowCompare.js
function shallowCompare(a, b) {
if (a === b) {
return true;
if (typeof a === 'object' && typeof b === 'object' && hiddenClass(a) === hiddenClass(b)) {
return !memcmp(a, b, sizeOfClass(a));
if (typeof a === 'function' && typeof b === 'function') {
if (sourceLocation(a) === sourceLocation(b)) {
return shallowCompare(getClosureContextOf(a), getClosureContextOf(b));
You can’t perform that action at this time.