Skip to content

Latest commit

 

History

History
111 lines (80 loc) · 2.76 KB

File metadata and controls

111 lines (80 loc) · 2.76 KB

← Back to Usage Guide Index

🚀 Quick Start

This example shows the fastest way to get M7BootStrap running in your project. We’ll initialize the bootstrapper, load a package, and mount its content.


1. Requirements


2. Project Structure

your-project/
  vendor/
    m7Bootstrap/
      BootStrap.js
    m7Fetch/
      src/
        index.js
  index.js

3. Example Package

For demonstration, we’ll use a symbolic package reference and a repo definition:

const resources = [
  { resource: "scene:chess", repo: ["/repo"] }
];

4. Minimal Code Example

import Net from "./vendor/m7Fetch/src/index.js";
import BootStrap from "./vendor/m7Bootstrap/BootStrap.js";

// Initialize networking layer and bootstrapper
const net = new Net();
const bootstrap = new BootStrap(net);

// Define package load options
const opts = {
  package: { hooks: true } // run package-defined "run" hooks (default: true)
};

// Handlers
const onLoad = [
  "#runner.mount", // symbolic reference to a bootstrapper method
  (sys, ctx) => console.log("Loaded packages:", ctx)
];

const onError = [
  "logFailure",
  (sys, ctx) => console.warn("Failed to load:", ctx)
];

// Load the package(s)
const success = await bootstrap.load(resources,{ load:onLoad, error:onError}, opts);

if (!success) {
  console.error("Bootstrap failed");
}

5. What Happens Here

  1. Dependency resolution — M7BootStrap builds a dependency graph from resources.
  2. Parallel fetch — Packages, assets, and modules are retrieved as quickly as possible.
  3. Mounting — HTML assets are mounted automatically; modules are stored in bootstrap’s registry.
  4. Hooks — If enabled, any run hooks in packages are executed.
  5. Handlers — onLoad or onError handlers are run with full context.

6. Unmounting Example

await bootstrap.unload(
  ["scene:chess"],        // package ids
  ["#runner.unmount"],      // onDone handlers
  ["logFailure"],         // onError handlers
  { ignoreMissing: true } // options
);

This removes the package’s mounted assets and clears modules from the bootstrapper. If you copied modules elsewhere, you’ll need to remove them manually.


Next Steps