Skip to content

Instantly share code, notes, and snippets.

View jasonrhodes's full-sized avatar

Jason Rhodes jasonrhodes

View GitHub Profile
@jasonrhodes
jasonrhodes / cv.md
Last active April 22, 2018 02:59
My speaking and writing CV

Jason Rhodes / Speaking and Writing CV

This is a list of links to slides, videos, and other information about tech talks I've given, as well as links to blog posts and articles I've written. They're in reverse chronological order. All of my slide decks can be found on my Speaker Deck profile, as well.

Blog Posts and Articles

What's new with React, 2018 edition

Slides: https://speakerdeck.com/rhodesjason/whats-new-with-react-2018-edition

Links:

// You can chain a list of this type of "chainable" http function with "callback hell"
chainA({ cb: (results) =>
chainB({ results, cb: () =>
chainC({ cb: (results) =>
chainD({ results })
})
})
})
// But I want a helper with this API:
import { Route } from 'react-router-dom'
export default function Redirect({ to, from, ...rest }) {
return <Route path={from} {...rest} render={({ location }) => (
<Redirect to={{ ...location, pathname: to }} />
)} />
}
@jasonrhodes
jasonrhodes / createContextWat.js
Created March 3, 2018 22:49
Trying to understand the new React 16.3 createContext source code
/**
* This file: https://github.com/facebook/react/blob/fb85cf2e9c52a4b2999144a89a6ee8256aec55c7/packages/react/src/ReactContext.js
* if you remove the <flow> stuff and the "calculate changed bits" stuff, it appears to be
* a function that, when called, returns an object literal with some weird circular references?
*
* How is this working / what am I missing here?
*/
export function createContext(defaultValue) {
const context = {
$$typeof: REACT_CONTEXT_TYPE,
@jasonrhodes
jasonrhodes / memoize-throttle-how.md
Last active February 24, 2018 21:44
I want to throttle a function but split up by args, is there an easy way?

Say you have a function that takes a single argument like this:

// return a string date that is "n" days before "right now"
function backInTime(n) {
  return subtract(new Date(), n, 'days').toString();
}

So if you call this (on Thurs, Feb 22) a few times in a row (pretending each one takes a full second to run) you would get:

@jasonrhodes
jasonrhodes / post-merge
Created September 20, 2012 17:10
Checks for changes in composer.json and alerts to update in a post-merge hook
#!/bin/sh
#
# To enable this hook, rename this file to "post-merge".
# We could probably run composer update here, but this is safer for now
if git diff --name-only HEAD^1 | grep composer.json >/dev/null
then
echo ' '
echo '#############################################################################'
@jasonrhodes
jasonrhodes / async-redux-hell.md
Last active November 20, 2017 22:37
Async Redux Hell

The Rules

  1. Action creators must return something "simple". A plain object, a simple function call, or at worst: a thunk.
  2. Internal API call logic must be encapsulated and abstracted away out of sight
    • authorization token decoration
    • refresh and retry logic
    • logout on fail logic
  3. External API calls are subject to the same async processing as internal API calls (pending, success, fail events at minimum)
  4. Internal API results trigger notifications for success and fail, according to a limited set of rules
  5. Calls can be correctly chained (i.e. failures exit the chain), with access to previous call's response
@jasonrhodes
jasonrhodes / bootstrap.php
Last active November 15, 2017 14:12
Once you load WordPress in via Composer (using the GitHub WordPress/WordPress mirror and Composer's "package" repository type), you have to solve a few directory path problems. This Composer script solution helps WordPress find your config file kept in your /config/ directory (You can easily change that path in the bin/wp-config-redirect script)
<?php
/**
* Load WordPress
*
*/
define('WP_USE_THEMES', true);
require 'vendor/wordpress/wordpress/wp-blog-header.php';
@jasonrhodes
jasonrhodes / dont-use-var.js
Last active October 26, 2017 16:09
Looking at using let and const vs using var, semantically
function getNameWithLetAndConst(options) {
// `name` scoped to its nearest parent block (here: the function-block)
let name = 'Jill'
if (options.test) {
// `combined` is scoped to its nearest parent block (here: the if-block)
// because of how block-scoping works, `name` is also available here
const combined = `${name}-tested`
if (options.someCondition) {