Svelte Betta Auction — Svelte

One price on every screen of Mas Gilang's betta auction, with Svelte stores, context and actions. 15 levels, right in the browser.

What the levels ask

  1. Sunday morning in the yard under Mr. Gilang’s house in Kedondong Lane. Lelang Cupang Sukamaju, the village’s betta auction, opens: jars of cupang line the stalls, the price shows on the TV, and buyers bid from their phones. Last month the TV said 85rb, the WA group said 90rb, and three people thought they had won the same Halfmoon. From now on every screen reads one source: the store harga in lelang.js. Fill the price line in Harga.svelte (used by the TV and every phone) so each screen shows the store’s value and follows it when the neighbourhood head and Mrs. Sari bid.
  2. The phones’ +5rb button now uses a shorter way. In a component the $ prefix does not only read a store: assigning to $name writes to that store too. Fill the button’s onclick so the neighbourhood head’s, then Mrs. Sari’s, then Mr. Piksel’s bid each raises the price by 5rb, and every screen follows.
  3. Bagas opens his first stall, and the tablet on it shows the price of the lot on the block. Its top line, the opening price, is read once with get(harga) and must not change. Fill the price line under it so Bagas’s tablet follows the neighbourhood head’s and Mrs. Sari’s bids like the TV.
  4. The rule of a cupang auction: every bid must rise by at least one KB (kelipatan bid, the bid step), here 5rb. The TV shows the least next bid, and the phones’ button bids exactly that. Fill minimal in lelang.js so it is always harga plus kb, whatever the price is now.
  5. Mrs. Sari wins two fish today and wants them delivered. Her phone shows the total: all her winnings plus delivery. The winnings are in the store menang, the delivery fee in the store ongkir, and both can change. Fill total so it is worked out again when Mrs. Sari wins again and when her delivery fee goes up.
  6. Each lot gets 30 seconds. The clock is the store sisa, made with readable: its second argument runs when the first subscriber comes, and what it returns runs when the last one leaves. Mr. Gilang does not want the clock ticking and draining batteries while not one screen is on. Fill the function’s last line so the clock stops when every screen is off and runs again when Mrs. Sari opens the group.
  7. Last Sunday the power went out for five seconds when the Red Halfmoon had 27 seconds left. The TV died, everyone pocketed their phones to help start the genset, and the lazy clock went to sleep too. When Mrs. Sari opened the group the clock still said 27: the lot closed five seconds late, and Mr. Tono’s late bid won. Today the Halfmoon is auctioned again, and the lot closes exactly at tutup. Fill tik so the clock always counts the time left until tutup, whether anyone watches or not.
  8. The auction’s WA group still has an old bot that sometimes sets a price at random, and last Sunday it dropped the Plakat to 40rb. Mr. Gilang wraps the price store in buatLelang: the price can only rise through tawar, at least one KB over the price now. Fill the first part of the object it returns so the screens can still read the price, but nobody can set it backwards.
  9. Mr. Gilang tries the Svelte 5 way for this lot: not a store but a rune in the module lelang.svelte.js, which Svelte compiles like a component. Every screen imports lelang and reads lelang.harga directly, with no $. Fill the value of lelang so the bids from the phones reach every screen.
  10. Mr. Arka opens a stall beside Bagas’s, and each stall now auctions its own lot on its tablet, while the TV still shows Mr. Gilang’s main lot (harga). The tablet on each stall (Layar.svelte) takes its lot with getContext('lot'). Fill the line in Lapak.svelte so a bid at Bagas’s stall changes neither Mr. Arka’s stall nor the TV.
  11. The Galaxy Koi can be bought outright with BIN (buy it now) for 150rb, but the button must be held for 600 ms so nobody buys by accident. The holding is the action tahan in aksi.js, put on with use:tahan. Last Sunday the neighbourhood head pressed BIN by accident and closed his app, and a second later the Koi was sold to him. Fill the object the action returns so the hold’s timer stops when its button is thrown away.
  12. In the last minute of the Yellow Giant’s auction, Mr. Gilang shortens the BIN hold from 800 ms to 300 ms, and Mrs. Sari’s phone gets the new number as a prop. The action tahan now keeps its options in o. Fill the first method of the object it returns so Mrs. Sari’s 400 ms hold is not enough before the change, and is enough after it.

And more, 15 levels in all.