Skip to content

The Great Unlearning Doc #482

@nickchomey

Description

@nickchomey

Someone proposed the creation of a "The Big Unlearning" guide in discord. I and others have also floated such a thing various times. I'm not the one to write it, but figured that we can start to dump/brainstorm ideas here for inclusion in such a doc.

Here's some things that I had to wrap my head around/learn

  • SSE is HTTP so is compatible with all (is that true?) HTTP stuff.
    • e.g. You can add gzip, brotli, zstd compression as you would for any http response - be it in your application (d* bad apple example does this) or in a proxy server (caddy, nginx, cloudflare etc). I documented a lot of that in this issue.
  • D* does not just open one SSE connection that everything gets piped through from the server - like you might do with WebSockets. Each request is a new http request that happens to have SSE headers and can therefore return nothing (eg POST data), 1 message and close (request-reply pattern) or infinite responses (long-lived SSE connection). You could also, in theory, maintain multiple long-lived connections for different endpoints. If using http2+ it shouldn't really be an issue since, in theory, you could have infinite requests sharing the same multiplexed connection.
  • this video and article really ought to be featured more prominently
  • Dont be afraid of sending an entire document for morph/merging rather than more granular elements (in fact, it might even be better/more performant
  • Its HOWL - you dont need any particular backend, let alone NATS/event-driven stuff. But its plays particularly well with such an approach (and NATS is just glorious compared to its alternatives)
  • idiomoprh is the appropriate default for merge-fragments. Use it as much as you can, unless you're truly just appending/prepending a fragment somewhere - then it might be appropriate to change the mergeMode.
  • You also dont need to specify the data: selector #foo if the fragment contains an ID (as it should) - idiomorph will just find it and deal with it.
  • This all makes D* is particularly compatible with brownfield apps, as you dont need to modify the html templates as you would with something liek htmx (eg adding hx-swap, hx-target etc...). Just send the fragment with the ID and/or data: selector and it will work.
  • Should probably elaborate on this compared to hx-boost

And some "collected wisdom" from discord:

10 commandments (and some of my own additions/elaborations)

  1. SSE is just HTTP response with ability to send 0- ♾️ chunks
  2. SSE it cost the same as any fetch.
  3. Yes its a framework, it is also a library.
  4. D*'s superpower/contribution to hypermedia is making signals easy to use declaratively
  5. But try not to use signals until you need them(theyre at the top of hypermedia maslow hierarchy of needs
  • theyre most useful when the dom and its elements are stable and you just want to change the content (name, time, date, price etc...). Fragments are the Bricks of your house, they alone hold together and can last a while on their own but signals are the mortar than can flex and hold together your house when rain and wind comes. If you are building a simpler fire pit, bricks alone are fine... building a cathedral, you have well place mortar thoughtfully placed too much mortar and the whole thing collapses
  • immediate vs retained mode (i believe immediate is essentially hypermedia/MPAs whereas signals are retained mode. Use each when appropriate?
  1. Don't put state in the wrong place (keep it on server - or at the very least in service worker proxy, not in a SPA)
  2. Don't over complicate it
  3. Hypermedia is faster than you think
  4. CSS and View Transitions hide any server work
  5. Just start coding with it, it's easier than you think
  6. :NotACult: but 🖕 JS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions