Skip to content

Commit

Permalink
Merge pull request #89 from ivanceras/develop
Browse files Browse the repository at this point in the history
- rename Cmd -> Dispatch
- rename Task -> Cmd
  • Loading branch information
ivanceras authored Apr 3, 2024
2 parents 5dbf299 + 4919401 commit 52b586c
Show file tree
Hide file tree
Showing 52 changed files with 777 additions and 584 deletions.
22 changes: 19 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,32 @@
}
```
- [X] Maybe disable the template usage for now
- [ ] Make `Cmd` to be used internally as it needs reference to the `Program<APP>`
- [ ] Use `Task` for returning from `Application` init and `update`.
- [X] Make `Cmd` to be used internally as it needs reference to the `Program<APP>`
- [X] Use `Task` for returning from `Application` init and `update`.
- The `Recurring Task` is actually just a Sub in elm
- Issue with recurring task, how to store the closures which has different multiple types for the in arguments
- Store the closures with `Closure<dyn Fn(IN)->MSG>`
- Then task becomes `Task<IN,MSG>`
- The `SingleTask` is a Cmd in sauron
- Rename `Cmd` to `Command` alternative: `Action`, `Operation`, `Instruction`, `Effects`, `Dispatch`
- This is effects in elm
- [X] Rename `Cmd` to `Dispatch`
- [X] Rename `SingleTask` to `Action`
- [X] Rename `RecurringTask` to `Sub`
- [X] enum Command{Cmd,Sub} into one unified type.
- [X] Cmd is a vec of Command
- Sauron just consilidate them into one enum struct for simplicity
- [ ] Remove `Modifier` and `measurements`
- [ ] Have a measurement in the Application trait
- [ ] Remove StatefulComponent as it is now the same as Application and serve the same purpose
- add methods for Application:
- attribute_changed
- remove_attribute
- append_child
- remove_child
- connected_callback
- disconnected_callback
- adopted_callback

## Features
- [X] Storage service (May not be needed since the user can directly use web-sys)
Expand Down Expand Up @@ -401,7 +417,7 @@
- [X] This should work very simply `classes_flag([("todo", true), ("editor", is_editing)])`

## Limitations
- In rust, no two closures, even if identical, have the same type. Therefore closure can not be check for equality.
- ~~In rust, no two closures, even if identical, have the same type. Therefore closure can not be check for equality.~~ Solved by using the original type_id of the function callback
- In sauron node are matched and reused aggressively, except when the keys are different then the node is discarded.
- If we don't reuse nodes with event listeners aggressively, then we would have a performance penalty, since every recreation of the node with event listener will have to discard and create a new one for it, even if it is matching itself.
- Adding `key` attribute provides a good trade off.
15 changes: 10 additions & 5 deletions crates/core/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
pub use component::Component;
pub use effects::Effects;
pub use modifier::Modifier;
pub use task::Task;
pub use cmd::Cmd;

mod component;
mod effects;
mod modifier;
mod task;
mod cmd;

use cfg_if::cfg_if;

cfg_if! {if #[cfg(feature = "with-dom")] {
pub use application::{Application, Measurements, SkipDiff, skip_if, skip_diff, SkipPath};
#[cfg(feature = "custom_element")]
pub use component::{register_web_component, WebComponent, WebComponentWrapper};
pub use component::{component, stateful_component, StatefulComponent, StatefulModel, StatelessModel};
pub use component::{stateful_component, StatefulComponent, StatefulModel, StatelessModel};
pub use component::component;
pub use dom_patch::{DomPatch, PatchVariant};
pub use dom_attr::{DomAttr, DomAttrValue, GroupedDomAttrValues};
pub use http::Http;
Expand All @@ -29,13 +30,15 @@ cfg_if! {if #[cfg(feature = "with-dom")] {
pub use raf::{request_animation_frame, AnimationFrameHandle};
pub use ric::{request_idle_callback, IdleCallbackHandle, IdleDeadline};
pub use timeout::{delay, request_timeout_callback, TimeoutCallbackHandle};
pub use cmd::Cmd;
pub use dispatch::Dispatch;
use crate::dom::events::MountEvent;
pub use window::Window;
pub use dom_node::DomNode;
pub use document::Document;
pub use time::Time;

mod application;
pub mod cmd;
pub mod dispatch;
mod dom_node;
mod dom_patch;
mod dom_attr;
Expand All @@ -46,6 +49,8 @@ cfg_if! {if #[cfg(feature = "with-dom")] {
mod raf;
mod ric;
mod window;
mod document;
mod time;
mod timeout;


Expand Down
10 changes: 5 additions & 5 deletions crates/core/src/dom/application.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::dom::Cmd;
use crate::vdom::Node;
pub use skip_diff::{skip_if, SkipDiff, SkipPath};
use crate::dom::Cmd;

///
pub mod skip_diff;
Expand All @@ -13,15 +13,15 @@ pub trait Application: Sized + 'static {
type MSG;
/// The application can implement this method where it can modify its initial state.
/// This method is called right after the program is mounted into the DOM.
fn init(&mut self) -> Cmd<Self> {
fn init(&mut self) -> Cmd<Self::MSG> {
Cmd::none()
}

/// Update the component with a message.
/// The update function returns a Cmd, which can be executed by the runtime.
/// The update function returns a Dispatch, which can be executed by the runtime.
///
/// Called each time an action is triggered from the view
fn update(&mut self, _msg: Self::MSG) -> Cmd<Self>;
fn update(&mut self, _msg: Self::MSG) -> Cmd<Self::MSG>;

/// Returns a node on how the component is presented.
fn view(&self) -> Node<Self::MSG>;
Expand All @@ -40,7 +40,7 @@ pub trait Application: Sized + 'static {
/// This is for diagnostic and performance measurement purposes.
///
/// Warning: DO NOT use for anything else other than the intended purpose
fn measurements(&self, measurements: Measurements) -> Cmd<Self> {
fn measurements(&self, measurements: Measurements) -> Cmd<Self::MSG> {
log::debug!("Measurements: {:#?}", measurements);
Cmd::none().no_render()
}
Expand Down
Loading

0 comments on commit 52b586c

Please sign in to comment.