This content moved here: https://exploringjs.com/impatient-js/ch_arrays.html#quickref-arrays
// After you think you understand this program, try writing it yourself until | |
// you can get it to work, the first time, without error ^_^ | |
// | |
// ALSO: remember: | |
// $ gcc program.c # compile | |
// $ ./a.out # run | |
// We'll get `printf` from standard input/output's header file | |
#include <stdio.h> |
import React from 'react'; | |
import lively from 'lively'; | |
// Global registry and resize handler | |
let _registeredInstances = []; | |
function register(inst) { | |
if (_registeredInstances.length === 0) { | |
window.addEventListener('resize', onResize); | |
} |
class Info extends Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { | |
return <Modal><Text text=“This is the text” /></Modal>; | |
} | |
} |
How do you send information between clients and servers? What format should that information be in? What happens when the server changes the format, but the client has not been updated yet? What happens when the server changes the format, but the database cannot be updated?
These are difficult questions. It is not just about picking a format, but rather picking a format that can evolve as your application evolves.
By now there are many approaches to communicating between client and server. These approaches tend to be known within specific companies and language communities, but the techniques do not cross borders. I will outline JSON, ProtoBuf, and GraphQL here so we can learn from them all.
tl;dr I built a demo illustrating what it might look like to add async rendering to Facebook's commenting interface, while ensuring it appears on the screen simultaneous to the server-rendered story.
A key benefit of async rendering is that large updates don't block the main thread; instead, the work is spread out and performed during idle periods using cooperative scheduling.
But once you make something async, you introduce the possibility that things may appear on the screen at separate times. Especially when you're dealing with multiple UI frameworks, as is often the case at Facebook.
How do we solve this with React?
Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".
Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).
Let's dig in:
import fetch from 'node-fetch'; | |
import { observable, action, runInAction } from 'mobx'; | |
export default class GithubStore { | |
@observable searchName; | |
@observable user; | |
@observable repos; | |
@observable fetchingData; | |
constructor() { |
import express from 'express'; | |
import React from 'react'; | |
import ReactDOMServer from 'react-dom/server'; | |
import App from './components/App'; | |
import {flushServerSideRequires} from 'react-loadable'; | |
let app = express(); | |
let webpackStats = require('./output-webpack-stats.json'); |