import { createContext } from "effection";
export const CollectedIslands = createContext("revolution.IslandCollection");
export function* useIsland(location, ...args) {
    let collection = yield* CollectedIslands.expect();
    let mod = collection.modules[location];
    if (!mod) {
        let error = new Error(`no known island: '${location}'`);
        error.name = "MissingIslandError";
        throw error;
    }
    let id = String(collection.nextId++);
    collection.seen.add(location);
    collection.invocations[id] = { id, location, args };
    let { placeholder } = mod;
    let slot = {
        type: "root",
        children: [
            {
                type: "comment",
                value: `island@${id}`,
            },
        ],
    };
    if (placeholder) {
        if (typeof placeholder === "string") {
            slot.children.push({
                type: "text",
                value: placeholder,
            });
        }
        else if (typeof placeholder === "function") {
            let content = placeholder(...args);
            if (content.type === "root") {
                slot.children.push(...content.children);
            }
            else {
                slot.children.push(content);
            }
        }
    }
    slot.children.push({
        type: "comment",
        value: `/island@${id}`,
    });
    return slot;
}
//# sourceMappingURL=island.js.map