Skip to main content

fusor/
lib.rs

1//! Reactive Rust for HTML script blocks, compiled by Cargo without a Rust DSL.
2//!
3//! ```
4//! use fusor::{signal, derived, effect, batch};
5//! let count = signal(0);
6//! let doubled = derived({ let count = count.clone(); move || count.get() * 2 });
7//! let subscription = effect(move || println!("{}", doubled.get()));
8//! batch(|| { count.set(2); count.set(3); });
9//! // Prints 0, then 6. Dropping the subscription stops it.
10//! drop(subscription);
11//! ```
12
13#[doc(hidden)]
14pub mod authoring;
15mod cleanup;
16pub mod coherence;
17mod owner;
18mod reactive;
19pub use cleanup::{Cleanup, CleanupEffect, effect_with_cleanup};
20pub use owner::{ContextError, ContextKey, Owner, OwnerHandle, Registration};
21#[doc(hidden)]
22pub use reactive::versions;
23
24/// Versioned contract shared by the HTML compiler and the DOM runtime.
25/// This is an implementation interface, not application authoring syntax.
26#[doc(hidden)]
27pub mod template;
28pub use reactive::{
29    Derived, Effect, Memo, Signal, batch, derived, effect, memo, memo_with_eq, signal, untrack,
30};
31
32#[cfg(feature = "dom")]
33pub mod dom;
34
35#[cfg(feature = "dom")]
36pub use dom::FromInputs;
37#[cfg(feature = "dom")]
38pub use fusor_macros::FromInputs;
39
40#[cfg(feature = "javascript")]
41pub mod js;
42#[cfg(feature = "javascript")]
43pub use fusor_macros::JsInputs;
44#[cfg(feature = "javascript")]
45pub use js::JsInputs;
46
47/// The small set of types needed by a browser application.
48pub mod prelude {
49    #[cfg(feature = "dom")]
50    pub use crate::FromInputs;
51    #[cfg(feature = "javascript")]
52    pub use crate::JsInputs;
53    #[cfg(feature = "dom")]
54    pub use crate::dom::{Component, Content, Scope, TemplateComponent, document, element};
55    pub use crate::{Cleanup, CleanupEffect, effect_with_cleanup};
56    pub use crate::{ContextError, ContextKey, Owner, OwnerHandle};
57    pub use crate::{
58        Derived, Effect, Memo, Signal, batch, derived, effect, memo, memo_with_eq, signal, untrack,
59    };
60}