notes
All repositories: gitoria
7.4 KB
// The View's READERS — realm-neutral: the same code reads values on the server and (compiled to JS) in the// browser; the browser's bundle carries this file and nothing server-only (viewserver.hl). It reads a TREE, the// syntax of a View member reflected into plain hybrids by the server (see// server.hl `tree()`), against an INSTANCE whose members supply the values.//// Tree node shapes:// { k = 'el' tag key path = [ keys… ] site attrs = [ { name text } | { name member } ] children = [ … ] }// `site` is `file:line:col` of the literal — the id its class is minted under// `tag` is what the DOM gets (a custom key kebab-cased), `key` the source key// { k = 'text' text }// { k = 'member' name } an ordered entry naming a member of the class — a SITE// { k = 'field' name path } `p.title`: a path off a member or a `for` row variable// { k = 'for' row list body } `for (row of list) { … }`, body rendered per entry// { k = 'if' cond then other } `if (cond) { … } else { … }`// { k = 'on' event } a DOM event the owning literal handles (its inline `on`)// { k = 'component' cls key path bindings ons } `Child { count = count on done(v) { … } }`:// a composed component — its own mount renders here// { k = 'other' tag } a construct this round does not render yet (if / for / on)//// `ctx` rides through every call: `ctx.slot` is the HTML a shell's `slot` member// stands for (null when rendering a page alone), `ctx.kids` the child mounts of// the instance being rendered, keyed by the component node's path joined with// '/'. A component node renders ITS mount: its own instance, its own kids.// the language has no escapes: a newline and a tab are written as themselvesstatic newline = ""static tab = " "// a component node's key in a mount's `kids`: its path, '/'-joined (a list has no// join in the language; the walk is written out)kidKey(&path) {let out = ''for (p of path) { out = out + '/' + p }return out}// THE KEY OF ONE ROW — the record's id, then @id (hl:mpackdb documents), and by// the row's index where the row is not a record or carries neither key (a list of strings// is one: demo-blog's paragraphs). ONE rule, called by everything that has to tell// one row from the next: the server's HTML walk below, the mount key of a row's// children (WebFramework `mountKids`), and the browser's keyed region (client.hl).// Two rows with the SAME id are two rows to the language and one key to this rule;// the browser's region gives the second one a key of its own, the server does not.rowKey(&entry, i) {if (entry != null) {t = hlTypeName(&entry)if (t == 'Hybrid' || t == 'Instance') {if (entry.id != null) { return '' + entry.id }if (entry.@id != null) { return '' + entry.@id }}}return '' + i}// THE KEYS OF A LIST, in order: rowKey of each row, and where one id stands twice the second and later// rows get ':' + their index (#119). The browser's region (client listKeys) keys a list the same way, so a// child of the second row of one id is its own mount on the server too, not the first row's.listKeys(&entries) {let out = []let seen = {}let ri = 0for (entry of entries) {let k = rowKey(&entry, ri)if (seen[k] != null) { k = k + ':' + ri }seen[k] = trueout.push(k)ri = ri + 1}return out}// A LITERAL'S VALUE, TYPED — COMPONENTS.md §12, "typed, not stringified". `hlSyntax`// hands a literal back as its source text and its KIND, and a reference binding carries// the value rather than the text: `Level2 { n = 1 }` gives the child a Number, so `n * 97`// is arithmetic and not "operator '*' does not apply to String and Number" (measured// 2026-09-14, demo-nested wall 3). An attribute and a text child keep the text, because// HTML is text; only what crosses into a member of another class is typed.literalValue(kind, text) {if (kind == 'number') { return toNumber(text) }if (kind == 'boolean') { return text == 'true' }if (kind == 'null_literal') { return null }return text}// THE VALUE A REFERENCE BINDING CARRIES when it is a literal or a folded static — the// one place the two are read, so the server's mount and the browser's do it alike. A// static is folded to its VALUE and carried as one ('folded'), never printed and parsed// back; a literal carries its source text and its kind, which is all the syntax has.refValue(b) {if (b.kind == 'folded') { return b.value }if (b.kind != null) { return literalValue(b.kind, b.text) }return b.text}// THE VALUE a read names: a `for` row variable in scope wins over a member of the// same name (nesting is scope); a field path walks into it.value(&node, &page, &rows) {if (node.k == 'text') { return refValue(node) }if (node.k == 'expr') { return evalExpr(&node.x, &page, &rows) }// READ IN PLACE: `v = rows[node.name]` copied the whole row value (a block with all its spans) and each// `v = v[f]` step copied the rest again, per read, per mount; a path of up to three steps is one indexed readlet name = node.namelet inRow = rows[name] != nullif (node.k == 'field') {let path = node.pathlet n = path.lengthif (n == 1) {if (inRow) { return rows[name] == null ? null : rows[name][path[0]] }return page[name] == null ? null : page[name][path[0]]}if (n == 2) {if (inRow) { return rows[name][path[0]] == null ? null : rows[name][path[0]][path[1]] }return page[name][path[0]] == null ? null : page[name][path[0]][path[1]]}}let v = nullif (inRow) { v = rows[name] } else { v = page[name] }if (node.k == 'field') {for (f of node.path) {if (v == null) { return null }v = v[f]}}return v}// A VIEW EXPRESSION (`p { "x" + n }`, `a - b`, `n > 3 ? 'big' : 'small'`) is evaluated by// the LANGUAGE'S OWN OPERATORS: this walk only picks the operator the author wrote and// applies it, so what `+` gives null and a string, what `==` says of two types, what `&&`// returns — all of it is the runtime's answer, on the server (the interpreter or a// binary) and in the browser (the client target), and hl:web has no rule of its own.// The leaves are reads (`value`) and literals. `&&`, `||` and `?:` evaluate what they// pick only, as the language does.evalExpr(&x, &page, &rows) {if (x.k == 'bin') {let l = evalExpr(&x.l, &page, &rows)let op = x.opif (op == 'logical_and') { return l && evalExpr(&x.r, &page, &rows) }if (op == 'logical_or') { return l || evalExpr(&x.r, &page, &rows) }let r = evalExpr(&x.r, &page, &rows)if (op == 'add') { return l + r }if (op == 'subtract') { return l - r }if (op == 'multiply') { return l * r }if (op == 'divide') { return l / r }if (op == 'modulo') { return l % r }if (op == 'equal') { return l == r }if (op == 'not_equal') { return l != r }if (op == 'less_than') { return l < r }if (op == 'greater_than') { return l > r }if (op == 'less_equal') { return l <= r }if (op == 'greater_equal') { return l >= r }if (op == 'bit_and') { return l & r }if (op == 'bit_or') { return l | r }if (op == 'bit_xor') { return l ^ r }if (op == 'shift_left') { return l << r }return l >> r}if (x.k == 'un') {let o = evalExpr(&x.x, &page, &rows)if (x.op == 'logical_not') { return !o }if (x.op == 'negate') { return -o }return ~o}if (x.k == 'cond') { return evalExpr(&x.c, &page, &rows) ? evalExpr(&x.a, &page, &rows) : evalExpr(&x.b, &page, &rows) }return value(&x, &page, &rows)}
Branches
Latest commits
- 3537cf7eMerge branch 'vendor-day59' into mainAtlas
- c13d188b|||PR Vendor Hybriel day59Atlas
- 24c95433Merge branch 'notes17-ghost-note' into mainAtlas
- ae1075b2Preserve rejected drafts during note ID adoptionAtlas
- 383cce23|||PR Prevent saved local edits from restoring deleted notesAtlas
- 99ca1cf6Merge branch 'vendor-day56' into mainAtlas
- 649cef37|||PR Vendor Hybriel day56Atlas
- aadd0abcMerge branch 'hl-standard-2' into mainAtlas
- 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
- 617ee8c0Merge branch 'hl-standard' into mainAtlas
- 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
- 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre
- 5d7cc700Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre
- d7366702Check session cookie flags after login and assert anonymous GET stays cookielessmre
- 16bc8fd8Re-vendor Hybriel day38b with the mpackdb store-open race fixmre
- d860dc2dnotes#12: the markup names its own rules instead of hand-written class strings: the selected row is `aria-current="page"` (the list-first theme rule styles it, no class), the delete question is `Style.pAsk` and follows its own `open` attribute (bound to `asking`), the error line is `Style.pMessage` (body once in lib/looks.hl, rule in notes.hl, main.hl and loginfailed.hl). The CSS declarations are the same, only selectors changed (.ask -> p.ask, .ask.open -> p.ask[open], .message -> p.message); the pages look the same (AE 0 at 4 sizes). main.hl's selectorClass in/out stays (login.js reads it).mre
- 2e7f8664notes#13: the list and back links pass the note key from the loop (emit pick(e, r.key)) instead of writing data-note into the View and reading it back with getAttribute; the two window.history.replaceState calls and the identcode e.target.value read stay (hl:web has no replace-navigation, a bound hidden input is not adopted on a script's change event), see NO13 reportmre
- 4dc98282notes#15: a deleted note made in this tab leaves the list at once (the delete now removes this tab's edit under every key the row has: local id, server id); gate: browser.mjs notes#15 section, red on the old codemre
- e4e7402fnotes#11: plain declarations instead of let for variables never reassigned (components/notes.hl 3, lib/jsoncheck.hl 5, lib/util.hl 2, tools/migrate-short-ids.hl 8)mre