Sharing state between pilets
Pilets are isolated by design. Communication happens through explicit, observable mechanisms — four channels, never direct imports or window globals.
1. Events: fire-and-forget
Good for: real-time notifications, analytics hooks, loose coupling. Not for: state a late-loading pilet needs at startup.
2. Shared data store: named key-value
First pilet to write a key owns it. Others can read but not overwrite.
3. Shared libraries via importmap
Any pilet can share a package as a side-bundle:
Other pilets that declare the same name get the same instance:
For how this resolves (externals vs side-bundles, and where each dependency belongs), see Dependency sharing.
4. Extension slots: sharing UI
Decision guide
Warning
Never use window globals to share state. Untestable, untyped, and a debugging nightmare.