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
sebmarkbage / WhyReact.md
Created Sep 4, 2019
Why is React doing this?
View WhyReact.md

I heard some points of criticism to how React deals with reactivity and it's focus on "purity". It's interesting because there are really two approaches evolving. There's a mutable + change tracking approach and there's an immutability + referential equality testing approach. It's difficult to mix and match them when you build new features on top. So that's why React has been pushing a bit harder on immutability lately to be able to build on top of it. Both have various tradeoffs but others are doing good research in other areas, so we've decided to focus on this direction and see where it leads us.

I did want to address a few points that I didn't see get enough consideration around the tradeoffs. So here's a small brain dump.

"Compiled output results in smaller apps" - E.g. Svelte apps start smaller but the compiler output is 3-4x larger per component than the equivalent VDOM approach. This is mostly due to the code that is usually shared in the VDOM "VM" needs to be inlined into each component. The tr

@sebmarkbage
sebmarkbage / The Rules.md
Last active Nov 20, 2019
The Rules of React
View The Rules.md

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
sebmarkbage / SubscriptionIsHard.js
Last active Oct 6, 2019
Subscription Is Hard?
View SubscriptionIsHard.js
class SubscriptionDoneRight extends Component {
state = {
data: Store.read(props.id)
}
getDerivedStateFromProps(props, state) {
return {
data: Store.read(props.id),
};
}
@sebmarkbage
sebmarkbage / propertynames.txt
Last active Aug 23, 2017
Attribute/Property Name Smoke Test
View propertynames.txt
about
aBoUt
accent-Height
accent-height
accentHeight
accept
accept-charset
accept-Charset
acceptCharset
accessKey
@sebmarkbage
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 = Date.now;
/**
@sebmarkbage
sebmarkbage / Intro.md
Last active Mar 9, 2017
ECMAScript Tagged Object
View Intro.md

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
sebmarkbage / asyncToReact.js
Last active Oct 6, 2019
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
sebmarkbage / react.prod.js
Created Aug 9, 2016
React Isomorphic Package
View react.prod.js
/**
* 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.
*
You can’t perform that action at this time.