Skip to content

feat: 0.7 release (codename futura)#106

Merged
schell merged 82 commits into
mainfrom
feat/futura
Jun 19, 2025
Merged

feat: 0.7 release (codename futura)#106
schell merged 82 commits into
mainfrom
feat/futura

Conversation

@schell

@schell schell commented Jun 7, 2025

Copy link
Copy Markdown
Owner

0.7 release

Codenamed futura, the 0.7 release of mogwai is a very big change.

Big conceptual changes

Interlocking traits, crowned by View

Views are now structs whose fields are types that implement one or more of an interlocking set of traits - ViewText, ViewParent, ViewChild, ViewProperties, ViewEventTarget, and ViewEventListener.

These structs are parameterized with a type variable V:View that determines the precise type of these fields, given the V passed in at runtime. It does this with associated types - V::Element, V::Text, V::Node, and V::EventListener. This strategy allows view structs to be written in a platform agnostic way, with platform selection happening at runtime. It also allows "specialization" at runtime using a try_cast_ref function that casts a V::Element to a specific type.

mogwai 0.7 will ship with at least two implementations of View: Web and Ssr. Web's View impl resolves to web_sys types and Ssr's View impl resolves to an internal string representation.

Streams are dead

Streams can be cool, but supporting them takes up a bunch of memory due to lots of clones and lots of uses of wasm_bindgen_futures::spawn_local. 0.7 drops streams in favor of futures. 0.7 is closer to the metal. Don't worry though, the crate still addresses the pain points of UI web dev in a very similar manner, just one that feels less "Reacty".

Instead of streams, 0.7 gets closer to the metal by relying on futures and mutability. For example, instead of building up a stream of event messages and matching in a loop, 0.7 relies on stepping through event futures one at a time. The code ends up looking very similar, but there's less cloning and it encourages more idiomatic Rust code and scoping the UI steps to a single future instead of an ongoing stream allows views to be borrowed mutably for short periods, which all contributes to a reduction in memory usage.

RSX updates

The rsx! macro is completely revamped and focuses on constructing views and capturing the fields necessary for updating the UI. Reactivity is (for the most part) not done in the rsx! macro (but there is a bit of that using Proxy, more on that later).

Proxy replaces Model, no magic to see here

Proxy is a new type that replaces Model, though it is much simpler and updates are made mutably. The rsx! macro has special support for using proxies to provide a very thin layer of reactivity, but without any React style magic. View structs must update the value within a Proxy explicitly, but then Proxy will update parts of the view automatically, according to the sites of its use within an rsx! macro.

Why are you doing this?

For the most part I love working close to the metal (so to speak) when building web interfaces. Close to the metal in this case means using the browser APIs directly. But of course there are some real pain points with using web_sys directly, especially for creating DOM nodes. So 0.7 makes mogwai as thin a layer over the bare metal while still addressing these specific issues:

  • reduce boilerplate for creating views using the rsx! macro
  • update multiple parts of views (or multiple views) using one model update via Proxy
  • async event handling
  • server side rendering and cross-platform support via the View trait

TODO

  • port crates
  • port examples
  • port cargo-gen template
  • port cookbook
  • port introduction docs

After merging

  • crates.io releases
  • cargo-generate template points to crates.io

schell added 28 commits June 9, 2025 14:51
@schell schell merged commit 289bd85 into main Jun 19, 2025
1 check failed
@schell schell deleted the feat/futura branch June 19, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant