β Shops Admin Walkthrough β β
This example shows how to model a multi-shop admin panel in .me using:
- indexed collections (
shops[1],shops[2]) - broadcast formulas (
[i]) - range selectors (
[1..2]) - logical filters (
[menu.breakfast_deal > 6])
Full Script (tests/ShopsExample.ts) β β
ts
import ME from "this.me";
const me = new ME() as any;
console.log("\\n.me example2: shops + [] selectors");
// 1) Build two shops as an indexed collection
me.shops[1].name("Downtown");
me.shops[1].menu.latte.price(4.5);
me.shops[1].menu.espresso.price(3.0);
me.shops[2].name("Riverside");
me.shops[2].menu.latte.price(5.0);
me.shops[2].menu.espresso.price(3.5);
// 2) Broadcast combo logic to every shop (iterator [i])
me.shops["[i]"].menu["="]("breakfast_deal", "latte.price + espresso.price - 1.5");
// 3) Read by range selector
const rangeDeals = me("shops[1..2].menu.breakfast_deal");
console.log("shops[1..2].menu.breakfast_deal ->", rangeDeals);
// 4) Filter shops by computed value
const filteredNames = me("shops[menu.breakfast_deal > 6].name");
console.log("shops[menu.breakfast_deal > 6].name ->", filteredNames);
// 5) Direct leaf checks
console.log("shops[1].menu.breakfast_deal ->", me("shops[1].menu.breakfast_deal")); // 6
console.log("shops[2].menu.breakfast_deal ->", me("shops[2].menu.breakfast_deal")); // 7π Step-by-Step Semantics β β
1) Build the collection β β
ts
me.shops[1].menu.latte.price(4.5);
me.shops[2].menu.latte.price(5.0);You are creating a semantic indexed tree:
txt
shops
ββ 1
β ββ menu
β ββ latte.price = 4.5
β ββ espresso.price = 3.0
ββ 2
ββ menu
ββ latte.price = 5.0
ββ espresso.price = 3.52) Broadcast formula over all members ([i]) β β
ts
me.shops["[i]"].menu["="]("breakfast_deal", "latte.price + espresso.price - 1.5");The kernel compiles one derivation rule and applies it to each existing child under shops.
Result:
shops[1].menu.breakfast_deal = 6shops[2].menu.breakfast_deal = 7
3) Read range slice ([1..2]) β β
ts
me("shops[1..2].menu.breakfast_deal");Range selector returns a keyed projection:
json
{ "1": 6, "2": 7 }4) Filter with logic β β
ts
me("shops[menu.breakfast_deal > 6].name");Only matching children survive the predicate:
json
{ "2": "Riverside" }π£ Optional Audit (Explain) β β
You can inspect why one computed value exists:
ts
console.log(me.explain("shops.2.menu.breakfast_deal"));This returns:
- expression used
- input dependencies
- last compute metadata
- masked origin if a dependency is stealth
Runtime Output (real) β β
txt
suign@Suis-MacBook-Air npm % node tests/ShopsExample.ts
.me example2: shops + [] selectors
shops[1..2].menu.breakfast_deal -> { '1': 6, '2': 7 }
shops[menu.breakfast_deal > 6].name -> { '2': 'Riverside' }
shops[1].menu.breakfast_deal -> 6
shops[2].menu.breakfast_deal -> 7Run β β
bash
node tests/ShopsExample.tsIf the output matches, your collection selectors, broadcast derivation, and logic filter are all working correctly.