This Maya MFE demonstrates how to instantiate the same MFE multiple times using different key values. Each instance manages isolated state and view logic, showcasing Maya's ability to scope stores per key, allowing independent behavior across dynamic instances.
- ✅ Multi-Instance MFE Rendering using separate
keyvalues (alpha,beta) - ✅ Scoped Store State per instance
- ✅ Slot-based Composition to render MFEs side-by-side
- ✅ Interactive Inputs with isolated updates via
maya-inputand storeselfdata - ✅ Independent Event Dispatch through
operationId-basedmaya-button
/mfe/multikey/
│
├── js/
│ └── index.js # MFE logic, store, lifecycle
│
├── view/
│ ├── main.html # Hosts the slots for child MFEs
│ └── detail.html # The per-instance card layout
<maya-slot name="target1"></maya-slot>
<maya-slot name="target2"></maya-slot>This view defines two named slots. Each slot will receive a dynamically loaded instance of the same MFE with a different
key.
Maya.Store.multikey = { /* ... */ }- onLoad: Loads default data for either
alphaorbetainstance. - updateName: Updates the instance’s name from the self-bound input.
Maya.Load('multikey/detail?key=alpha&target=target1');
Maya.Load('multikey/detail?key=beta&target=target2');The
onRenderhook dynamically loadsdetail.htmlinto both slots, using unique keys to isolate each instance.
Displays each instance's values and allows editing the name via input.
| Component | Purpose |
|---|---|
<maya-input> |
Binds to self[key][name], syncing user input to store self-state |
<albert-uibutton> |
Triggers store events like updateName using operationId |
<maya-slot> |
Creates anchor points for rendering child MFEs (from main.html) |
| Concept | Description |
|---|---|
key |
A unique identifier per instance, used to scope store.data[key] |
maya-input |
Syncs user input to store.self[key][name], enabling scoped binding |
operationId |
Dispatches events like updateName, which fetches self.name via key |
| Slots | Enable nesting MFEs into well-defined locations dynamically |
When this MFE is rendered:
- Two separate cards appear.
- You can edit the name in either one.
- Clicking Update triggers a scoped
SetDatausing the specifickey, proving MFE isolation.
This MFE is a practical pattern in Maya when:
- You need to repeat a form/card layout many times
- Each needs its own state
- You want one MFE, multiple behaviors
<maya-slot>– Dynamic layout anchors<maya-input>– One-way data binding to storeself<albert-uibutton>– Event dispatcher viaoperationIdMaya.Store.SetData– Triggers view updates scoped by keyMaya.Load()– Loads MFEs dynamically into slots without full reload
- MFE Name:
multikey - Custom Element:
<albert-multikey> - Store Name:
multikey
All aligned to Maya's lowercase, hyphenless naming convention.
- Use version.json to track deployment changes
- Declare
multikeyin yourmaya-mayaHTML with:<albert-multikey slot="main"></albert-multikey>
- No extra dependencies required