Slight tweak to how gets created on demand. We use an now, for mutability/immutability needs in the reconciliation process. Not sure offhand how much the double lock of will affect things, but that's a problem for later.
This commit is contained in:
parent
4bf89f5d91
commit
c7ef19a943
8 changed files with 53 additions and 43 deletions
|
|
@ -3,7 +3,7 @@
|
|||
//! uses these to build and alter UI; they're typically returned from `render()`
|
||||
//! methods.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
mod virtual_node;
|
||||
|
|
@ -40,7 +40,7 @@ pub enum RSX {
|
|||
impl RSX {
|
||||
/// Shorthand method for creating a new `RSX::VirtualNode` instance. Rarely should you call
|
||||
/// this yourself; the `rsx! {}` macro handles this for you.
|
||||
pub fn node<F: Fn() -> Box<Component> + Send + Sync + 'static>(tag: &'static str, create_fn: F, props: Props) -> RSX {
|
||||
pub fn node<F: Fn() -> Arc<RwLock<Component>> + Send + Sync + 'static>(tag: &'static str, create_fn: F, props: Props) -> RSX {
|
||||
RSX::VirtualNode(VirtualNode {
|
||||
tag: tag,
|
||||
create_component_fn: Arc::new(create_fn),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
//! Implements a Props struct that mostly acts as expected. For arbitrary primitive values,
|
||||
//! it shadows a `serde_json::Value`.
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::traits::{Component};
|
||||
use crate::rsx::{RSX, StylesList};
|
||||
|
||||
/// A value stored inside the `attributes` field on a `Props` instance.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! Implements the `RSX::VirtualNode` struct, which is a bit of a recursive
|
||||
//! structure.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::fmt::{Display, Debug};
|
||||
|
||||
use alchemy_styles::node::Node;
|
||||
|
|
@ -19,11 +19,11 @@ pub struct VirtualNode {
|
|||
|
||||
/// `Component` instances are created on-demand, if the reconciler deems it be so. This
|
||||
/// is a closure that should return an instance of the correct type.
|
||||
pub create_component_fn: Arc<Fn() -> Box<Component> + Send + Sync + 'static>,
|
||||
pub create_component_fn: Arc<Fn() -> Arc<RwLock<Component>> + Send + Sync + 'static>,
|
||||
|
||||
/// A cached component instance, which is transferred between trees. Since `Component`
|
||||
/// instances are lazily created, this is an `Option`, and defaults to `None`.
|
||||
pub instance: Option<Arc<Component>>,
|
||||
pub instance: Option<Arc<RwLock<Component>>>,
|
||||
|
||||
/// A cached `Node` for computing `Layout` with `Stretch`. Some components may not have
|
||||
/// a need for layout (e.g, if they don't have a backing node), and thus this is optional.
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ pub trait Component: Send + Sync {
|
|||
|
||||
/// If you implement a Native-backed component, you'll need to implement this. Given a
|
||||
/// `component`, you need to instruct the system how to append it to the tree at your point.
|
||||
fn append_child_component(&self, _component: &Arc<Component>) {}
|
||||
fn append_child_component(&self, _component: &Component) {}
|
||||
|
||||
/// If you implement a Native-backed component, you'll need to implement this. Given a
|
||||
/// `component`, you need to instruct the system how to replace it in the tree at your point.
|
||||
|
|
|
|||
Reference in a new issue