Move towards a new reconciler model, undo a lot of the weird stretch integrations I had done, separate out Layout and Appearance concepts, introduce ComponentKey and constructor lifecycle for components
This commit is contained in:
parent
6fd3f79099
commit
91266cc841
31 changed files with 820 additions and 941 deletions
51
lifecycle/src/reconciler/key.rs
Normal file
51
lifecycle/src/reconciler/key.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
//! Implements an auto-incrementing ID for Component instances.
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
||||
use alchemy_styles::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
/// Global stretch instance id allocator.
|
||||
pub(crate) static ref INSTANCE_ALLOCATOR: Mutex<Allocator> = Mutex::new(Allocator::new());
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct Id {
|
||||
id: u32
|
||||
}
|
||||
|
||||
pub(crate) struct Allocator {
|
||||
new_id: u32
|
||||
}
|
||||
|
||||
impl Allocator {
|
||||
pub fn new() -> Self {
|
||||
Allocator { new_id: 1 }
|
||||
}
|
||||
|
||||
pub fn allocate(&mut self) -> Id {
|
||||
let id = self.new_id;
|
||||
self.new_id += 1;
|
||||
Id { id: id }
|
||||
}
|
||||
}
|
||||
|
||||
/// Used as a key for Component storage. Component instances receive these
|
||||
/// in their constructor methods, and should retain them as a tool to update their
|
||||
/// state.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ComponentKey {
|
||||
pub(crate) instance: Id,
|
||||
pub(crate) local: Id,
|
||||
}
|
||||
|
||||
impl ComponentKey {
|
||||
/// A placeholder value, used purely for ensuring the diffing algorithm remains
|
||||
/// readable by reducing some unwrapping hell.
|
||||
pub fn placeholder() -> ComponentKey {
|
||||
ComponentKey {
|
||||
instance: Id { id: 0 },
|
||||
local: Id { id: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue