Git Product home page Git Product logo

quasar's Introduction

Quasar

An experimental rust-to-{wasm,asmjs} frontend framework.


Supermassive black holes exist at the center of most observed galaxies, but there is much about them that remains a mystery. It is believed that rapidly adding sufficient matter to a supermassive black hole's accretion disk results in becoming a quasar that emits enormous amounts of electromagnetic energy as matter via astrophysical jets perpendicular to the black hole's spin. These jets can emit matter at nearly lightspeed and stretch hundreds of thousands of light years across a galaxy.

WASM is at the center of an upcoming shift in web development, but there is still much about that shift that remains a mystery. Some believe Rust, as an early mover, and with zero-cost abstractions is well-positioned to invest in bytecode that spins up on the event loop. It may be possible for Rust to power the fastest applications on the web, becoming highly visible across the frontend ecosystem for years to come.

Oh, and black hole's form from the collapse of a core of iron.. you know, the only element that rusts.


Everything is experimental, half-baked, full of caveats, regularly broken, and subject to change. But some basic principles are beginning to emerge. With Quasar...

  • your component and state types propogate into event handlers (no need to guess the type or structure of state).
  • mutating state updates views that rely on that state (unless you update your state via interior mutability)
  • bring your own templating engine and reuse it for server rendering (though quasar will provide a default OOB engine - TBD)

How it works

Currently, Quasar combines some basic JQuery-like semantics with state and component management while ensuring that state modifications trigger rerendering of components that depend on that data.

  • Template engines are swappable. There are examples using bart, mustache and maud. But replacing the template engine is just a matter of implementing the Renderable trait.
  • Components are the combination of data with a template or other rendering process - really anything that implements Renderable. Quasar takes ownership of your components when binding them to the DOM and makes the data available to your event handlers via data() and data_mut() methods. In general, methods that mutate the component will result in re-rendering it at the end of the event handler. Note, component data is local to the component and not shareable outside your component.
  • Views are the result of one-way binding of a component to the DOM. You can also attach event listeners to views. Note, that currently rendering a view uses the destructive innerHtml = ... approach, which kills DOM state like input focus, so eventually some sort of DOM diffing/patching or virtual DOM solution will become pretty important.
  • App Data is shared state that is also available to event handlers. It is partitioned by a key (and by TypeId), and any attempt to read a shared data partition (calling data(key)) automatically registers your view as an observer of that data partion. Any attempt to write to an app data partition (calling data_mut(key)) will automatically add all observer views for that data partition to the re-render queue process at the end of the event handler.

A basic example might include an HTML file like this:

<html>
  <body>
    <div id="counter"></div>
  </body>
</html>

You can bind and update data with a snippet like this:

#[derive(Default, BartDisplay)]
#[template_string = "<p>Count: {{count}}</p><button>+1</button>"]
struct CounterData { count: u32 }

impl Component for CounterData {
    fn onload(view: &View<Self>) {
        view.on_each(EventType::Click, "button", |mut evt| {
              evt.binding.data_mut().count += 1;
        });
    }
}

fn main() {
    let mut app = quasar::init();
    app.bind("#counter", CounterData::default());
    app.spin();
}

And every such framework needs a To Do app; Quasar has two: Mustache To Do, and Maud To Do.

Goals

Quasar is still exploring some ideas and working to better understand what works and what's missing in webplatform. Here are some overarching questions that are guiding this experimentation right now:

  • Can Quasar achieve a level of abstractions that feel comparable to modern Javascript frameworks? (Probably with the help of macros eventually after some dust settles.)
  • What might it look like to have "isomorphic" rust, where the same rendering code can run both client and server side?
  • How can I leverage the type system to achieve more flexible and/or more robust frontend development? (e.g. trait-based templating, leveraging immutable vs mutable access as a gate for identifying views that observer or mutate specific data.)

Admittedly Quasar is absent any perf goals at this time.

Building

You'll need emscripten setup and activated (see brson's post), and then to add a couple compilation targets:

rustup target add asmjs-unknown-emscripten
rustup target add wasm32-unknown-emscripten

Now you can build quasar with:

cargo build --target=asmjs-unknown-emscripten

# or using cargo-web
cargo install cargo-web
cargo-web build

And you can run the various examples by running cargo-web start from their directory:

cd www
cargo-web start

quasar's People

Contributors

anowell avatar lambda-fairy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quasar's Issues

Any solution/proposal to work with a rest backend?

Hi, I have a small demo due next Friday and I was wondering if I could try quasar? Only catch is that I need to get data from a server (and submit to it) which will probably be done with rocket.rs.

Any pointers would be appreciated, and if I can help I'd be happy to.

Areas needing attention

There are lots of areas that need plenty of thought, discussion, and possibly contributors. These need broken out into separate issues (please do open an issue to discuss one of these deeper). This issue serves as a high-level summary:

  • Routing - what's it look like to implement SPA routing on top of quasar? Is this built-in, or does quasar just provide a flexible set of primitives so that other crates can implement routing?
  • Lifecycle management- When should component data, app state, or even DOM elements get dropped/destroyed? Currently all of these live for the entire duration of the app, and the underlying webplatform makes things worse by growing an array of node elements indefinitely (e.g. every event appends an element to it).
  • DOM/JS interop - Quasar needs some deeper thought into how it interop the DOM and JS. This includes increasing the quasar's surface area to expose more DOM/JS functionality. It also includes thinking deeper about rendering. The current use of morphdom.js is probably temporary, and DOM patching in general needs more thought given to updating state of form elements. More generally, quasar might be better served by an alternative to rust-webplatform. Longer term, a future WASM DOM is probably a better story.
  • HTTP - Can we get HTTP client libraries like reqwest to target emscripten (e.g. perhaps the Fetch API)
  • Isomorphic - What's it look like to integrate Quasar with Rocket, Iron, etc? What patterns will lead to effective sharing of rendering code between the client and server?
  • JS Alternatives - Identify or create crates which could serve as alternatives to common JS libraries. (e.g. syntect could be a highlight.js alternative once it can target emscripten)
  • Demos - Quasar is probably a ways from real usage, so demos are currently guiding it's design and implementation. more substantial demos, isomorphic demos, perf demos, demos for specific crates in the browser, demos with different templating. A Quasar Demo gallery could be sweet.
  • Other projects that benefit Rust's emscripten ecosystem in general? cargo-web is nice but still super early. domafic is another frontend framework for those more interested in Elm/Redux architecture? Perhaps we need something like an "Are We Frontend Yet?" to keep track of the moving pieces in this ecosystem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.