-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Automatic lazy loading of resources during the rendering pipeline works pretty well using the backpressure module. The declarative usage uses the imperative form ripple.pull() under the hood. This is very similar to the dynamic import proposal import() which looks pretty neat, and I think it would be better to align the API with that. In addition, I think this means we should be able to keep everything in one function rather than define the component's dependencies in the needs header (aka getInitialProps). Proposal:
export default async function component(node, state){
const { import, subscribe } = ripple
, moment = await import('moment')
, events = await subscribe(node)('events')
}importwould just load from the core cache, or fetch and load.subscribewould do the same, but also redraw that component when there are updates to the resource.
The spec only mentions how to resolve module specifiers that start with /, ./ or ../ and leaves resolving "bare" import specifiers for later. However, I'm not sure how these paths can ever be interpreted in a universal context (i.e. as files in Node, but URLs in browser?). I think starting with bare specifiers would be a small change, more useful and make the most sense (e.g. import("moment")).
The core is also the equivalent of what the standard calls module map. The placeholder object whilst a fetch is in-flight just needs to be changed to a Promise however.
/cc @rauchg @developit @jordwalke for thoughts following on from this twitter discussion.. do you think this would work?