Expand description
§afia-component
A high-level Rust wrapper for
libafia_component.
§Overview
This crate provides a higher-level safe API on top of the afia-component-sys
crate.
For instance, creating a new DOM element using the afia-component crate looks like:
use afia_component::ComponentImports;
let imports = ComponentImports::new_dynamically_linked();
let div = imports.create_element("div").unwrap();Whereas creating a new DOM element using afia-component-sys requires direct usage of
pointers and unsafe code:
use afia_component_sys::create_element;
let tag = "div";
let div = unsafe { create_element(std::ptr::null(), tag.as_ptr(), tag.len()) };Most developers should choose afia-component since it is easier and safer to use
than the raw afia-component-sys bindings.
A developer might choose to instead use afia-component-sys if they are unsatisfied
with the API that afia-component exposes and would prefer to write their own Rust
wrapper.
§To Test
First, download a libafia_component from https://afiaproject.com .
Then run the tests.
cargo test -p afia-component§Optional Features
emulate-imports- Instead of importing functionality from the Afia host, expose anEmulatedImportsthat can be used to emulate the Afia host.test-utils- Exposes types that are useful for testing.macros- Expose macros such as#[create_instance]and#[output(..)].
Modules§
- callback
- Types and functions used for handling events and adding event listeners to dom nodes.
- context
- Some functions in the site component wasm ABI pass context to the Afia host.
- data_
element_ value - Types related to getting and setting an input element’s value.
- dom
- Types related to the DOM.
- input
- Types related to component inputs.
- local_
storage - Types related to getting and setting values in local storage.
- node_
property - Types related to getting and setting a property on a DOM node.
- stripe
- Types related to the Stripe JS SDK.
Macros§
- define_
text_ input - Define a text input for the component.
- handle_
events_ using_ callbacks - Generates an
__afia__$handle_eventfunction that expects that a pointer to aCallbackwas used as the context when calling [crate::DomElement::add_event_listener]’s context.
Structs§
- Component
Imports - A handle that can be used to call component imports such as
ComponentImports::create_elementandComponentImports::create_text. - Component
Output Args - Holds the arguments passed to an
__afia__$output$123function.
Traits§
- From
Component Output Args - Represents a type that can be created from
ComponentOutputArgs.