Skip to content

Instantly share code, notes, and snippets.

Ian Stewart ianmstew

  • Arcesium
  • New York
Block or report user

Report or block ianmstew

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
ianmstew / Avatar.tsx
Last active Nov 25, 2019
asyncComputed example
View Avatar.tsx
// Parallel implementation to Avatar example from
import { useObserver, useLocalStore } from 'mobx-react';
// WIP library inspired by `import { promisedComputed } from 'async-computed-mobx'`
import asyncComputed from 'utils/mobx/asyncComputed';
const DEFAULT_AVATAR = '/assets/img/default-avatar.png';
function Avatar(props: { userName: string }) {
ianmstew /
Created Nov 8, 2019
imperative vs declarative object initialization
const toggleButtonProps = {
  key: index,
if (props.disabled) toggleButtonProps.disabled = props.disabled;

Hot tip!! Try to challenge yourself to not imperatively update an object or array when you can use ES6 syntax to declare your logic at initialization/object creation time. The progression of developer into declarative/functional programming looks like this:


TypeScript makes JavaScript classes actually useful ^^

By fixing a fatal ES6 class flaw

The conspicuous absence of a way to reference constructor arguments within inline class property initializers

Which IMO after a year of struggles completely hobbles ES6 classes

View native-timezone.js
(() => {
function getLocale() {
// IE 11 does not support navigator.languages
return navigator.languages ? navigator.languages[0] : navigator.language;
function isTimezoneSupported(timezone) {
try {
new Date().toLocaleDateString(getLocale(), { timeZone: timezone });
} catch (err) {
if (err instanceof RangeError) {
ianmstew / hoc-renderprop-hook.js
Last active Oct 22, 2019
HOC vs Render Prop vs Custom Hook
View hoc-renderprop-hook.js
/* Loader that renders empty unless `` is true */
function Loader(props) {
const { active } = props;
return active && <div>Loading...</div>;
/* Loader class component that renders empty until a timeout */
class LoaderWithDelay extends React.Component {
ianmstew /
Last active Oct 11, 2019
Plain objects as maps in TypeScript

So another 🤯 about TypeScript. We use plain objects as arbitrary maps all the time, but TypeScript deems that usage (correctly) too flexible.

const map = {}; = 'foo'; // Error: Property 'foo' does not exist on type '{}'.

Okay, then we need to type our object as a map:

View higher-order-generator.js
(() => {
function MappedYieldGenerator(generator, mapYield) {
return function*() {
const gen = generator();
let genResult;
let resolvedValue;
do {
genResult =;
resolvedValue = yield mapYield(genResult.value);
} while (!genResult.done);
View schema.json
"type": "object",
"properties": {
"name": {
"type": "string"
"surname": {
"type": "string"
You can’t perform that action at this time.