Skip to content

Commit aba659e

Browse files
committed
wip
1 parent ebe2da6 commit aba659e

24 files changed

Lines changed: 690 additions & 174 deletions

File tree

anathema-core/src/attributes.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ impl<'bp> AttributeRegistry<'bp> {
2525
pub(crate) fn insert(&mut self, id: ElementId, attributes: Attributes<'bp>) {
2626
self.attributes.insert(id, attributes);
2727
}
28+
29+
pub(crate) fn get(&self, id: ElementId) -> Option<&Attributes<'bp>> {
30+
self.attributes.get(id)
31+
}
2832
}
2933

3034
// The access key for attributes.
@@ -300,4 +304,18 @@ mod test {
300304
assert_eq!("strings", iter.next().unwrap());
301305
assert_eq!("numbers", iter.next().unwrap());
302306
}
307+
308+
#[test]
309+
fn mixed_type_iteration() {
310+
let attributes = attributes();
311+
let mixed = attributes.get("mixed").unwrap();
312+
313+
if let TemplateValue::List(list) = mixed {
314+
assert_eq!(list[0].as_bool().unwrap(), true);
315+
assert_eq!(list[1].as_int().unwrap(), 1);
316+
assert_eq!(list[2].as_str().unwrap(), "string");
317+
} else {
318+
panic!("Expected List");
319+
}
320+
}
303321
}

anathema-core/src/frontend/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//! front ends...

anathema-core/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
// #![deny(missing_docs)]
1+
//! TODO: write docs
2+
#![deny(missing_docs)]
23
#[allow(unused_extern_crates)]
34
extern crate anathema_state as anathema;
45

56
// Has docs
67
pub mod attributes;
78
pub mod frontend;
89
pub mod layout;
9-
10-
// Dosn't like has docs so is a bit mid
1110
pub mod runtime;
1211
pub mod templates;
1312

anathema-core/src/runtime/components/component.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
/// User defined components
2+
///
3+
/// ```
4+
/// use anathema_core::runtime::Component;
5+
/// use anathema_state::Value;
6+
///
7+
/// struct MyComponent;
8+
///
9+
/// impl Component for MyComponent {
10+
/// type State = Value<String>;
11+
/// type Message = u32;
12+
/// }
13+
/// ```
114
pub trait Component: 'static {
15+
/// The state associated with the component
216
type State;
17+
/// The type of message that can be sent to the component
318
type Message;
419
}
520

6-
pub trait AnyComponent: 'static {
21+
pub(crate) trait AnyComponent: 'static {
722
}
823

924
impl std::fmt::Debug for dyn AnyComponent {

anathema-core/src/runtime/components/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
//! Runtime user defined component registry
12
use anathema::Value;
23
use anathema_state::State;
34
use anathema_store::key;
45
use anathema_store::slab::{GenSlab, SecondaryMap};
56

6-
pub use self::component::{AnyComponent, Component};
7+
pub use self::component::Component;
8+
use crate::runtime::components::component::AnyComponent;
79
use crate::templates::ComponentBlueprintId;
810

911
key!(ComponentId, Debug, Copy, Clone);
@@ -29,7 +31,8 @@ enum Lookup {
2931
Component(ComponentId),
3032
}
3133

32-
pub struct Components {
34+
/// Runtime component storage
35+
pub(crate) struct Components {
3336
instances: GenSlab<ComponentId, Entry>,
3437
blueprints: SecondaryMap<ComponentBlueprintId, Lookup>,
3538
}
@@ -78,8 +81,6 @@ impl Components {
7881
}
7982
}
8083

81-
pub(crate) fn by_component_id(&self) {}
82-
8384
pub(crate) fn get_state(&self, component_id: ComponentId) -> Option<&Value<Box<dyn State>>> {
8485
let inst = self.instances.get(component_id)?;
8586
Some(&inst.state)

0 commit comments

Comments
 (0)