UNPKG

remotion

Version:

Make videos programmatically

38 lines (37 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.waitForRoot = exports.getRoot = exports.registerRoot = void 0; let Root = null; let listeners = []; /* * @description Registers the root component of the Remotion project. * @see [Documentation](https://www.remotion.dev/docs/register-root) */ const registerRoot = (comp) => { if (!comp) { throw new Error(`You must pass a React component to registerRoot(), but ${JSON.stringify(comp)} was passed.`); } if (Root) { throw new Error('registerRoot() was called more than once.'); } Root = comp; listeners.forEach((l) => { l(comp); }); }; exports.registerRoot = registerRoot; const getRoot = () => { return Root; }; exports.getRoot = getRoot; const waitForRoot = (fn) => { if (Root) { fn(Root); return () => undefined; } listeners.push(fn); return () => { listeners = listeners.filter((l) => l !== fn); }; }; exports.waitForRoot = waitForRoot;