Skip to content

Instantly share code, notes, and snippets.

View faceyspacey's full-sized avatar

James Gillmore faceyspacey

View GitHub Profile
@faceyspacey
faceyspacey / respond-framework-statecharts.js
Last active March 28, 2019 10:38
Respond Framework support for Statecharts
import { testGenerator } from 'respond-framework/test'
const routes = {
LOGIN: '/login',
SIGNUP: '/signup',
POST: '/post/:slug',
HOME: {
path: '/',
next: {
LOGIN: request => !!request.getState().cookies.existingUser,
@faceyspacey
faceyspacey / route-splitting-manifest.md
Last active March 23, 2019 04:41
Example of our automatically code-split manifest

Our Manifest

Below is our manifest which has the information of every route the app has. It's statically generated by our babel-plugin at compile time.

It has the absolute minimal amount of information necessary so that it's possible for any route to dispatch actions to any other route.

Since createScene() generates action creators from simply our routesMap types/keys, that's all we need to generate ALL ACTIONS. Well, there is a few small edge cases, but you got the idea.

@faceyspacey
faceyspacey / remixx-modules-splitting-planning.md
Last active March 15, 2019 10:14
BRAINSTORM: Remixx Modules is also all about automatic splitting across routes + modules -- our own special manifest is the key

How we assign components to modules

This insures each component only can access the state from the module its part of.

  1. here's the intermediary data structure we generate in a single babel pass:
@faceyspacey
faceyspacey / code-splitting.js
Last active March 13, 2019 05:13
Rudy custom code-splitting middleware (split reducers, components, routes, libs)
// implementation 1
const load = (api) => async (req, next) => {
const { route, action } = req
const hasLoad = route && route.load
if (!hasLoad) return next()
const { components, reducers, chunks, ...res } = await route.load(req) || {}

Rudy Prefetching + Code-Splitting Strategy

We're gonna start by looking at how code splitting works, and build our understanding of the task from there

The Big Picture problem we solve

CODE SPLIT EVERYTHING (NOT JUST COMPONENTS) -- AND DO IT BEFORE YOU NEED IT

The big hidden idea here is that with RUC it's challenging, not perfectly performant, and non-obvious how to code split non-component things like reducers, thunks, etc.

import express from 'express'
import routes from './routes';
import { render, build } from 'react-universal-starter';
const app = express();
const handler = build(async (req, res, stats) => {
try {
const html = await render(routes, stats);
import express from 'express'
import routes from './routes';
import { render, build } from 'react-universal-starter';
const app = express();
const handler = build(async (req, res) => {
try {
const html = await render(routes);
import express from 'express'
import routes from './routes';
import { render, build } from 'react-universal-starter';
const app = express();
const handler = build(async (req, res, clientStats) => {
try {
const html = await render({
export default function connectAdvanced(selectorFactory, options) {
return function wrapWithConnect(WrappedComponent) {
class Connect extends Component {
static contextConsumers = [ReactReduxContext.Consumer]
static getDerivedStateFromProps(nextProps, [context], prevState) {
const { dispatch, state } = context
return this.selector(dispatch, state, nextProps, prevState) // returns `null` if no changes
}
// ASSIGNMENT 2b:
// Make a page switcher called <Website /> . On 2 of the pages, put the <TemperatureInput /> from assignment 2a.
// Lift the shared state into this component. Unlike the example from reactjs.org docs, only one input will show at
// a time. You will learn how to create "pages", navigation (aka links) between pages, and how to "lift" state
// that is shared between all pages to the parent component they all have in common.
//
// This should be done in 2 parts:
// 1) make the page switcher work by changing the `page` state on click of the links
// 2) work on passing the `onTemperatureChange` + `temperature` + `scale` props to the `TemperatureInput` component; then glue it all together.