Skip to content

Experimental zero cost(no_std, no_alloc) declarative fine grained reactivity system

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

storycraft/reactive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tbd

Experimental zero cost declarative fine grained reactivity system

Safety requirement

Due to lack of drop guarantee in Rust, it can be unsound if the effect is leaked. This is same limitation as scoped task.

It's unsafe to manually poll boxed future containing effects and leaking it. You can't have undefined behaviour by using well defined executors(like tokio or async_std) and future combinators

How it works

structure

  • DependencyTracker: 1 pointer sized main reactive primitive wrapping Intrusive linked list. Which contains start pointer to Binding
  • Binding: Node of DependencyTracker. Unlinked on drop. Each node contains pointer to Effect's queue node
  • Effect: Contains constant number of bindings(Each one for depending DependencyTracker) and a node which can be linked to a queue
  • Queue: Lazily evaluated effect queue. Evaluate queued effects and provides an asynchronous interface.
  1. DependencyTrackers are created and pinned
  2. Effects are created, pinned, initialized and evaluate the effect closure once
  3. During evaluation, each Bindings are attached to a corresponding DependencyTracker
  4. When a value changes, corresponding DependencyTracker is notified.
  5. Notified DependencyTracker traverses linked Binding nodes, link the Effect node to the Queue and clear the list
  6. Waker in the Queue notify upper Executor when nodes are added
  7. On next poll, the Queue pops first linked node, run effect closure. Repeat until there is no nodes left in the queue

See crates/example-app for more complex example

Note

Number of required bindings are calculated in compile time(using macro).

License

The project is dual-licensed under Apache-2.0 and MIT.

About

Experimental zero cost(no_std, no_alloc) declarative fine grained reactivity system

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages