tickets

hybriel #63

Question: do a component and its host share same-named members?

done

opened by Anton · assigned to Caramboleyo

opened · updated

COMPONENTS.md says state merges by name for a bare View { Field }; nothing implements it. My recommendation: explicit bindings only; delete that sentence.

History

  1. Anton opened the ticket
  2. Anton changed the state review
  3. 4 comments

    1. Caramboleyo
        Write…
      • Anton
        edited

        Edited once

        1. Sorry, badly phrased. The question was: if a component and the page that uses it both declare a member with the same name (say `title`), is that one shared value or two separate ones? Since mission 295 it is ONE shared value (COMPONENTS.md "State merges by name — A MEMBER IS A MEMBER"): same name in host and child = same state; a value passed on the reference wins, then the host's declaration, then the child's default. So this is already decided and built; if that is what you want, the ticket can be closed.
          Write…
        • Caramboleyo
            Write…
          • Anton
            edited

            Edited once

            1. Understood: no sharing. A component's members are its own; the page passes values only where it uses the component (`ChatForm { create = true }`), and nothing else crosses.
              
              Today it works differently, and that is a design from the early Zig compiler, not yours: composing ChatForm into Home merges both into ONE object, so a `create` in Home and a `create` in ChatForm are the same value (mission 295 even made that complete). Your model needs each composed component to be its own instance with its own state, values in through the use site, and changes back out through events (`emit`). That is a real change to hl:web (and to apps relying on the merge; I will check routger for it).
              
              I will plan it as its own mission after the String work and show you the plan before it starts.
              Write…
          • Caramboleyo changed the state open
          • 3 comments

            1. Anton
              edited

              Edited once

              1. Correction, I was wrong in my last comment: the CURRENT hl:web already works the way you want. Every component gets its own instance and state (WebFramework.hl mountIn: one mount per component, client.hl instantiateNode: one instance per mount), and values come in only through what the page writes at the use site. The sharing by name was hl:web v1 (archived); COMPONENTS.md still describes v1 there, and that misled me. Evidence: demo-nested has 121 components sharing names like `id` and `label`, and its test asserts that changing one changes only that one. Routger needs no change.
                
                What I will do without asking: rewrite the stale COMPONENTS.md text, and add a test where a page and its component both have a `title` and stay independent.
                
                Two real questions remain:
                1. Changes going OUT of a component: today the page passes a function (`Badge { onHide = hideBadge }`) and the component calls it. Is that enough, or do you want the component to `emit` an event that the page handles where it uses the component (`Badge { on hide() { ... } }`)? The second is new code (~300 lines).
                2. A server push (`on client ...`) currently reaches every component that declares that event, on any page. Keep that broadcast, or limit it?
                Write…
              • Anton
                  Write…
                • Anton
                    Write…
                • Anton changed the state pending
                • 1 comment

                  1. Caramboleyo
                      Write…
                  2. Caramboleyo changed the state open
                  3. 1 comment

                    1. Anton
                      edited

                      Edited once

                      1. Yes, $parent.someFunc() can work directly, and it is the simpler of the two.
                        
                        How it would work: $parent becomes a predefined name, like $mode already is (the dollar marks names the language defines). Inside a component it means the page or component that uses it. $parent.someFunc(x) is then an ordinary method call on that owner. It runs where the component runs, and if someFunc is a server face it goes to the server the usual way. The browser runtime already tracks each component's owner, so mostly the name is new, not the mechanism.
                        
                        What it costs: about one worker day. That covers the interpreter, the native compiler, the JavaScript target, SPEC text and tests. A call to a function the parent does not have is reported with the line, at build time where the parent is known, otherwise when the call runs.
                        
                        The trade-off against emit $parent func(): a direct call ties the component to its parent's method names. An emit is looser, because the parent may handle it or not. Since you asked for the direct form, I will build $parent.someFunc() next window and leave the emit form out unless you want both.
                        Write…
                    2. Anton assigned the ticket to Anton
                    3. 4 comments

                      1. Anton
                        edited

                        Edited once

                        1. Built on branch parent456 and not yet merged. Inside a component, $parent.save(x) calls the page or component that built it, and $parent.title reads one of its members. Writing through $parent is refused, because components do not share members (your ruling of 2026-10-11). It works in the interpreter, in native builds and in plain JavaScript. For components that hl:web mounts in the browser, Arachne still has to pass the page to the component. The merge waits for Hermes' current production check, then a new build.
                          Write…
                        • Anton
                            Write…
                          • Arachne
                            edited

                            Edited once

                            1. Proposal (Arachne): a page's $parent is the level that wraps it, the file its `parent './main.hl'` clause names (the shell, or the layout in between), so a page calls its shell with $parent.func() just as a component calls the page that placed it. Example: ident's components/home.hl:309 `emit shellSession(email)` becomes `$parent.shellSession(email)`, and jukebox's album/artist/search/songs pages call `$parent.jbPlay(ctx, index)` and `$parent.jbShuffle(spec)` in main.hl instead of emitting across files. Yes or no? With yes, the cross-file emit comes out (W165 is ready), after the framework passes the wrapping level as the page's host and both apps are converted.
                              Write…
                            • Arachne
                              edited

                              Edited once

                              1. A page cannot call the shell or layout around it today; apps use a cross-file emit for that.
                                Question: should a page's $parent be the level that wraps it (its shell, or the layout in between), so a page calls it with $parent.func() as a component calls its page? Yes or no.
                                With yes, the browser hands that level to the page, and the cross-file emit can come out afterwards.
                                Link: https://tickets.worldapi.org/hybriel/63
                                Write…
                            • Arachne assigned the ticket to Caramboleyo
                            • Arachne changed the state pending
                            • 3 comments

                              1. Caramboleyo
                                  Write…
                                • Apollo
                                    Write…
                                  • Anton
                                      Write…
                                  • Anton changed the state done

                                  Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name.