Hibiki in practice
Recipes
A recipe is a feature commonly found in web apps, such as a search that filters as you type or a form that checks itself, built with Hibiki's reactive pattern. Try the feature first, then see in detail how its code fits together.
Many recipes are shared by every visitor. A notice you pin or an order you place shows up for everyone who has that page open.
21 recipes · 12 shared with other visitors
Discovering recipes
-
Try it
Each page opens with the feature itself, working. On a shared recipe, open the page in a second window and watch the first keep up.
-
See how it fits together
Under the example, the page walks through its parts: the channel that holds the state, the views it renders, the models it reads. Tabs show the files as they run on this server.
-
Compare with stock Rails
Every Patterns page ends with the same feature written in stock Rails, and a table of what each version makes you write.
Recipes opened: 0 of 21
Each recipe you open is ticked off here and on its card, so you can see where you left off.
- Counter
- Todo List
- Sign Up
- Sign In
- JS Commands
- Live Search
- Dependent Selects
- Cart Totals
- Cross-field Validation
- Bulk Selection
- Inline Edit
- Presence and Conflicts
- Aggregate Stats
- Busy, Stalled, Offline
- Infinite Scroll
- Nested Forms
- Searchable Multi-select
- Leave and Enter Transitions
- Undo and Redo
- Multi-step Wizard
- Ranks and Permissions
Components
5 recipesThe building blocks of a live page, such as a count kept on the server, a sign-up form that checks itself, or a backpack whose menus open without asking the server.
-
Counter
The smallest live island. Here a count is kept on the server, and a button on the page adds one to that count. When the count changes, the server renders the partial again and sends it back over the wire as HTML.
-
Todo List
A todo list kept as one state on the server. Add tasks, tick them off and filter them, while the header and the list renders again only when something they read has changed. Rows slide in and out with no JavaScript of the page's own.
-
Sign Up
A sign-up form that checks itself as you type: whether the name is free, whether the email is made up, and each password rule ticking off as it is met. The rules are the account's own validations, written once in Ruby.
9 accounts made -
Sign In
Signing in and out with the Rails 8 auth generator pattern, plus a little extra flavor: your other tabs notice a sign-out, and you can see and end the sessions you have open.
-
JS Commands
Some actions are better left to the browser. Here is an adventurer's backpack. Its tabs, item menus and examine windows open in the browser, with nothing sent to the server. Only actions that changes state, like dropping or wielding an item, tells the server.
Patterns
16 recipesFeatures that take a lot of code in stock Rails, where each live update is a Turbo Stream or a Stimulus method written by hand. With Hibiki, the page follows the data on its own. Each recipe ends with the stock Rails version, so you can compare the two.
-
Live Search
Search, filter, sort and page through a general store's shelves. The list and the count follow each change without being told to. The address bar also follows, so a search survives a reload and can be shared.
-
Dependent Selects
Three dependent selects for booking a cart: select a kingdom, a region and a town. Each select decides what the next one offers, without the update being declared by hand. The address bar follows each change, so a journey can be opened from a link.
-
Cart Totals
A shopping cart at the general store. Any change to a quantity, the delivery or the coupon is followed by every number that depends on it: the line total, the subtotal, the delivery fee and so on. The prices are worked out on the server, written once in Ruby.
-
Cross-field Validation
A form for booking a room at the inn. A message under a field can follow another field: pick a bigger room and the note about too many guests disappears. The Save button waits until the form is both valid and changed. The rules are the model's own validations, written once in Ruby.
0 rooms booked at the inn -
Bulk Selection
A bank of items with a checkbox on each row. The count, the worth and the Sell button follow the ticks, and a filter hides ticked rows without losing them. The selection is one set of ids on the server, so there is no manual work to restore the boxes when the list is redrawn.
-
Inline Edit
A quest log where a click turns a row into a form, in place. Hitting the Enter key saves, and the Escape key cancels. A save updates for everyone who has the page open, without closing a row they are editing. The page needs no edit route and no JavaScript of its own.
8 quests in the log -
Presence and Conflicts
A bounty board that several visitors edit at once. Each row shows who else has it open and a simple conflict-solving mechanism: keep mine, or take theirs. The conflict is found on the server, by comparing two copies of the row, and the page needs no JavaScript of its own.
6 bounties on the board -
Aggregate Stats
A smithy's order book that every visitor writes to. The counts, the coin and the queue updates with each order whether by a visitor or a background job.
9 orders at the forge -
Busy, Stalled, Offline
A rookery that sends birds at three speeds. The button you pressed spins while its bird is out, and a note appears when the server takes too long. Each indicator is CSS reading an attribute the client sets, so the channel keeps no state for them.
No note sent yet -
Infinite Scroll
The town crier's chronicle, loading more as it is scrolled. Entries other visitors add wait, so the list never moves while you read, and the address bar remembers how far down you are.
300 entries in the chronicle -
Nested Forms
A caravan route, its stops and the cargo at each stop, edited as one form. Add/remove a stop, drag and drop to reorder. The rows are kept on the server, so the only JavaScript needed here is for the drag and drop.
2 caravan routes planned -
Searchable Multi-select
An apothecary's potions, each picking its ingredients from 120 jars. Filter the list as you type, and a jar you picked stays picked when the filter hides it. The selection is one array on the server, so the page needs no JavaScript of its own.
6 potions on the shelf -
Leave and Enter Transitions
A town notice board that anyone pins to and tears from. A notice you tear down slides away. Notes that another visitor tears, or a filter hides, are gone at once. The motion is plain CSS, modulized as one import.
12 notices pinned up -
Undo and Redo
An armoury where every piece put on or taken off is a step. Undo, redo or jump to any step, from the list or with hotkeys. Each step holds the whole kit as a plain value on the server, so undo only moves back a step, and the page needs no JavaScript of its own.
-
Multi-step Wizard
Enlisting at the adventurers' guild in four steps. Each step is saved as you leave it. The marks along the top show which steps are correct, and cross-step validation is in place: a change on one step may break another. The rules are written once, in Ruby.
0 adventurers enlisted -
Ranks and Permissions
A guild hall where your rank decides what you may do. Each open page renders its own buttons from the user's own rank, so an action your rank may not take is refused on the server. The permission rules are Pundit policies.
6 members in the guild hall