wip: docs

Worked a bit on adding more examples. Trying out a new "antipattern" example to show how *not* to use Dioxus.
This commit is contained in:
Jonathan Kelley committed 2021-06-23 22:32:54 -04:00
1 parent 9d7ee79826
commit f5683a2346
9 files changed
+197 -174

No files matched your search

+6 -3
View File
@@ -2,18 +2,21 @@ fn main() {}
pub mod dioxus {
pub mod prelude {
pub unsafe trait Properties {
pub trait Properties {
type Builder;
const CAN_BE_MEMOIZED: bool;
fn builder() -> Self::Builder;
unsafe fn memoize(&self, other: &Self) -> bool;
}
}
}
#[derive(dioxus_core_macro::Props)]
/// This implementation should require a "PartialEq" because it memoizes (no external references)
#[derive(PartialEq, dioxus_core_macro::Props)]
struct SomeProps {
a: String,
}
/// This implementation does not require a "PartialEq" because it does not memoize
#[derive(dioxus_core_macro::Props)]
struct SomePropsTwo<'a> {
a: &'a str,
+13 -3
View File
@@ -44,11 +44,21 @@ pub enum VirtualEvent {
MouseEvent(Rc<dyn on::MouseEvent>),
PointerEvent(Rc<dyn on::PointerEvent>),
// image event has conflicting method types
// ImageEvent(event_data::ImageEvent),
OtherEvent,
}
pub mod on {
//! This module defines the synthetic events that all Dioxus apps enable. No matter the platform, every dioxus renderer
//! will implement the same events and same behavior (bubbling, cancelation, etc).
//!
//! Synthetic events are immutable and wrapped in Arc. It is the intention for Dioxus renderers to re-use the underyling
//! Arc allocation through "get_mut"
//!
//!
//!
#![allow(unused)]
use std::{fmt::Debug, ops::Deref, rc::Rc};
@@ -178,8 +188,8 @@ pub mod on {
pub trait MouseEvent: Debug {
fn alt_key(&self) -> bool;
fn button(&self) -> i32;
fn buttons(&self) -> i32;
fn button(&self) -> i16;
fn buttons(&self) -> u16;
fn client_x(&self) -> i32;
fn client_y(&self) -> i32;
fn ctrl_key(&self) -> bool;
@@ -189,7 +199,7 @@ pub mod on {
fn screen_x(&self) -> i32;
fn screen_y(&self) -> i32;
fn shift_key(&self) -> bool;
fn get_modifier_state(&self, key_code: usize) -> bool;
fn get_modifier_state(&self, key_code: &str) -> bool;
}
pub trait PointerEvent: Debug {
+3 -3
View File
@@ -504,9 +504,9 @@ where
let child = item.into_vnode(&self.ctx);
self.children.push(child);
}
if self.children.len() > len_before + 1 {
if self.children.last().unwrap().key().is_none() {
if cfg!(debug_assertions) {
if cfg!(debug_assertions) {
if self.children.len() > len_before + 1 {
if self.children.last().unwrap().key().is_none() {
log::error!(
r#"
Warning: Each child in an array or iterator should have a unique "key" prop.
+30
View File
@@ -0,0 +1,30 @@
//! POC: Planning the layout of a single element type
//!
//!
//! The ultimate goal with a dedicated namespace is three-fold:
//! - compile-time correct templates preventing misuse of elemnents
//! - deep integration of DSL with IDE
//!
//!
//!
struct NodeCtx {}
struct div<'a>(&NodeCtx);
impl<'a> div<'a> {
fn new(cx: &NodeCtx) -> Self {
div(cx)
}
}
fn main() {}
fn factory(
// this is your mom
cx: &NodeCtx,
) {
div::new(cx);
rsx! {
div {}
}
}
+19 -16
View File
@@ -480,43 +480,46 @@ fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent {
pub struct CustomMouseEvent(web_sys::MouseEvent);
impl dioxus_core::events::on::MouseEvent for CustomMouseEvent {
fn alt_key(&self) -> bool {
todo!()
self.0.alt_key()
}
fn button(&self) -> i32 {
todo!()
fn button(&self) -> i16 {
self.0.button()
}
fn buttons(&self) -> i32 {
todo!()
fn buttons(&self) -> u16 {
self.0.buttons()
}
fn client_x(&self) -> i32 {
todo!()
self.0.client_x()
}
fn client_y(&self) -> i32 {
todo!()
self.0.client_y()
}
fn ctrl_key(&self) -> bool {
todo!()
self.0.ctrl_key()
}
fn meta_key(&self) -> bool {
todo!()
self.0.meta_key()
}
fn page_x(&self) -> i32 {
todo!()
self.0.page_x()
}
fn page_y(&self) -> i32 {
todo!()
self.0.page_y()
}
fn screen_x(&self) -> i32 {
todo!()
self.0.screen_x()
}
fn screen_y(&self) -> i32 {
todo!()
self.0.screen_y()
}
fn shift_key(&self) -> bool {
todo!()
self.0.shift_key()
}
fn get_modifier_state(&self, key_code: usize) -> bool {
todo!()
// yikes
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
fn get_modifier_state(&self, key_code: &str) -> bool {
self.0.get_modifier_state(key_code)
}
}
VirtualEvent::MouseEvent(Rc::new(CustomMouseEvent(evt)))