-
Notifications
You must be signed in to change notification settings - Fork 0
Concepts: code forward
Code-forward lets a page fire requests and apply config before double-meh (or your app) has
finished loading, then adopts the results seamlessly — the network never waits on
script-download → parse → execute. It is driven by a single global, globalThis.__doubleMeh.
import io from 'double-meh'; // installs code-forward automaticallyBefore the library loads, __doubleMeh is a plain command queue. An inline <head> script pushes to
three arrays:
<script>
window.__doubleMeh = window.__doubleMeh || {};
var dm = window.__doubleMeh;
// 1. Fire the request NOW and hand the promise over to be adopted:
(dm.arrived = dm.arrived || []).push(['/api/me', fetch('/api/me')]);
// 2. Register interest in an in-flight key (dedupe a request made elsewhere):
(dm.inFlight = dm.inFlight || []).push('/api/config');
// 3. Queue setup to run once io is live:
(dm.setup = dm.setup || []).push(function (io) {
io.inspect.request(injectAuth);
});
</script>When double-meh loads it drains the queue — setup callbacks run with io, inFlight keys are
registered on track, and each arrived [target, response] pair is adopted (into
track for in-flight sharing and into cache for durability — the cache is on by
default, so a bare io.get reads the seeded entry with no options). Your normal call then resolves
from the early fetch instead of hitting the network again:
import io from 'double-meh';
const me = await io.get('/api/me'); // resolves from the <head> fetch — no second requestAfter draining, __doubleMeh stays a small protocol marker: exactly three functions remain
live — dm.use(fn), dm.fly(target), and dm.arrived(target, response) — so late deliveries still
land. It is deliberately not upgraded into the io object (a copied handle would diverge from
the live instance the moment io is reconfigured); an inline script that wants the API asks for it:
__doubleMeh.use(io => io.inspect.request(injectAuth));Installation fires a one-time event: io.on('ready', () => …).
Guides
Concepts
Services
Modules
- fetch transport
- keys & URLs
- helpers
- records
- sse
- storage backends
- compression encoders
- Service Worker integration
Cookbook