-
-
Save ShopifyEng/3daf1f47da96be35a7f0df4f18866dd5 to your computer and use it in GitHub Desktop.
Remote Rendering: Shopify’s Take on Extensible UI - Sandbox code that enables a host to load and render a 3rd party extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sandbox | |
import { createEndpoint, retain } from "@remote-ui/rpc"; | |
import { createRemoteRoot } from "@remote-ui/core"; | |
// The `regsiter` function will be available (as a global) for extensions to use | |
let renderCallback; | |
self.register = (callback) => { | |
renderCallback = callback; | |
}; | |
// The `load` and `render` functions will be available (via RPC) for the host to use | |
async function load(scriptUrl) { | |
await import(scriptUrl); | |
} | |
function render(remoteChannel, api) { | |
retain([remoteChannel, api]); | |
const root = createRemoteRoot(remoteChannel); | |
renderCallback(root, api); | |
} | |
createEndpoint(self).expose({ load, render }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment