Skip to main content

Crate afia_component

Crate afia_component 

Source
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 an EmulatedImports that 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_event function that expects that a pointer to a Callback was used as the context when calling [crate::DomElement::add_event_listener]’s context.

Structs§

ComponentImports
A handle that can be used to call component imports such as ComponentImports::create_element and ComponentImports::create_text.
ComponentOutputArgs
Holds the arguments passed to an __afia__$output$123 function.

Traits§

FromComponentOutputArgs
Represents a type that can be created from ComponentOutputArgs.