Files
cell/help/reload.md
2025-12-17 00:48:02 -06:00

2.1 KiB
Raw Blame History

Hot Reloading

Hot reloading is of primary concern here. Cell does its best to hot reload modules when possible.

The key function can be used to create a stable key for a module, which can be used to hot reload modules and aid in data migration.

During hot reload ...

All var declarations are rebound, so old var -> new value Def declarations are not rebound, but properties of objects may be adjusted. Returned objects and functions are wrapped in a trampoline and adjusted. The original export shape is stable (same set of keys); you will get a warning if the shape changes, and you must reload the program to get the correct new shape.

Hot-reload binding rules var bindings are rebound on hot reload New evaluation replaces the old value. Use var for: tunables / config behavior references caches youre happy to discard anything you expect to change when code changes def bindings are never rebound The binding identity persists across reloads. Use def for: long-lived state prototypes / identity anchors capability keys registries you want to keep alive def objects may have their methods patched

Hot reload is best-effort. You get the full benefit when modules export a stable API object and keep long-lived identity in def (protos/state), while keeping tunables in var and reading them at use-time; caching primitives or function references opts out of live updates.

A module is “hot-reload friendly” if its export is a function or an object (not a primitive). On reload, the runtime: Re-evaluates the module. Rebinds all vars: old var binding becomes the new value from the new evaluation. pasted Keeps all def bindings (identity does not change), but: patches function-valued fields on def objects in place to match new code (and any other fields you explicitly define as reloadable). pasted Patches the module export handle (runtime-owned, stone-to-userland) so existing importers keep the same identity, but calls/fields can reflect new code. pasted Checks export shape: if the export is an object, its set of text keys must match the previous version; otherwise warn and require full program reload.