Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New AppBuilderAPI #290

Merged
merged 7 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
- Fixed jumping cursor in inputs (#158)
- Added method `orders.after_next_render(Option<RenderTimestampDelta>)` (#207)
- Fixed a bug with back/forward routing to the landing page (#296)
- [BREAKING] Deprecated `Init` struct, replacing it with `BeforeMount` and `AfterMount` structs to
better denote state before and after mounting the `App` occurs.
- [BREAKING] Added a new function `builder` which replaces `build` as part of deprecating `Init`.
- [BREAKING] Added a new function `build` which replaces `finish` as part of deprecating `Init`.
- Added `IntoInit`, `IntoAfterMount`, and `IntoBeforeMount` traits. It is possible to use these
in place of a closure or function to produce the corresponding `Init`, `AfterMount`, and
`BeforeMount` structs.
- Messages sent from `IntoAfterMount` will now be run after the routing message.

## v0.4.2
- Added an `Init` struct, which can help with initial routing (Breaking)
Expand Down
9 changes: 5 additions & 4 deletions examples/animation_frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ struct Model {
car: Car,
}

// Init
// AfterMount

fn init(_: Url, orders: &mut impl Orders<Msg>) -> Init<Model> {
fn after_mount(_: Url, orders: &mut impl Orders<Msg>) -> AfterMount<Model> {
orders
.send_msg(Msg::SetViewportWidth)
.after_next_render(Msg::Rendered);
Init::new(Model::default())
AfterMount::default()
}

// Update
Expand Down Expand Up @@ -162,7 +162,8 @@ fn view_wheel(wheel_x: f64, car: &Car) -> Node<Msg> {

#[wasm_bindgen(start)]
pub fn render() {
seed::App::build(init, update, view)
seed::App::builder(update, view)
.after_mount(after_mount)
.window_events(|_| vec![simple_ev(Ev::Resize, Msg::SetViewportWidth)])
.build_and_start();
}
10 changes: 6 additions & 4 deletions examples/canvas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ struct Model {
fill_color: Color,
}

// Init
// AfterMount

fn init(_: Url, orders: &mut impl Orders<Msg>) -> Init<Model> {
fn after_mount(_: Url, orders: &mut impl Orders<Msg>) -> AfterMount<Model> {
orders.after_next_render(|_| Msg::Rendered);
Init::new(Model {
AfterMount::new(Model {
fill_color: COLOR_A,
})
}
Expand Down Expand Up @@ -87,5 +87,7 @@ fn view(_model: &Model) -> impl View<Msg> {

#[wasm_bindgen(start)]
pub fn render() {
seed::App::build(init, update, view).build_and_start();
seed::App::builder(update, view)
.after_mount(after_mount)
.build_and_start();
}
2 changes: 1 addition & 1 deletion examples/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ fn view(model: &Model) -> impl View<Msg> {

#[wasm_bindgen(start)]
pub fn render() {
seed::App::build(|_, _| Init::new(Model::default()), update, view).build_and_start();
seed::App::builder(update, view).build_and_start();
}
4 changes: 2 additions & 2 deletions examples/drop/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## Drop example

How to crate a drop-zone.
How to create a drop-zone.

---

```bash
cargo make start
```

Open [127.0.0.1:8000](http://127.0.0.1:8000) in your browser.
Open [127.0.0.1:8000](http://127.0.0.1:8000) in your browser.
16 changes: 6 additions & 10 deletions examples/drop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ struct Model {
drop_zone_content: Vec<Node<Msg>>,
}

// Init

fn init(_: Url, _: &mut impl Orders<Msg>) -> Init<Model> {
Init::new(Model {
drop_zone_active: false,
drop_zone_content: vec![div!["Drop files here"]],
})
}

// Update

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -117,5 +108,10 @@ fn view(model: &Model) -> impl View<Msg> {

#[wasm_bindgen(start)]
pub fn start() {
seed::App::build(init, update, view).build_and_start();
seed::App::builder(update, view)
.after_mount(AfterMount::new(Model {
drop_zone_active: false,
drop_zone_content: vec![div!["Drop files here"]],
}))
.build_and_start();
}
8 changes: 1 addition & 7 deletions examples/mathjax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,7 @@ fn view(model: &Model) -> impl View<Msg> {
]
}

// Init

fn init(_: Url, _: &mut impl Orders<Msg>) -> Init<Model> {
Init::new(Model::default())
}

#[wasm_bindgen(start)]
pub fn render() {
seed::App::build(init, update, view).build_and_start();
seed::App::builder(update, view).build_and_start();
}
2 changes: 1 addition & 1 deletion examples/orders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ fn view(model: &Model) -> impl View<Msg> {

#[wasm_bindgen(start)]
pub fn start() {
seed::App::build(|_, _| Init::new(Model::default()), update, view).build_and_start();
seed::App::builder(update, view).build_and_start();
}
2 changes: 1 addition & 1 deletion examples/server_integration/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ fn view_example_introduction(title: &str, description: &str) -> Vec<Node<Msg>> {

#[wasm_bindgen(start)]
pub fn start() {
seed::App::build(|_, _| Init::new(Model::default()), update, view).build_and_start();
seed::App::builder(update, view).build_and_start();
}
8 changes: 5 additions & 3 deletions examples/server_interaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ fn view(model: &Model) -> Vec<Node<Msg>> {

// Init

fn init(_: Url, orders: &mut impl Orders<Msg>) -> Init<Model> {
fn after_mount(_: Url, orders: &mut impl Orders<Msg>) -> AfterMount<Model> {
orders.perform_cmd(fetch_repository_info());
Init::new(Model::default())
AfterMount::default()
}

#[wasm_bindgen(start)]
pub fn render() {
seed::App::build(init, update, view).build_and_start();
seed::App::builder(update, view)
.after_mount(after_mount)
.build_and_start();
}
4 changes: 1 addition & 3 deletions examples/server_interaction_detailed/reports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ fn view(model: &Model) -> Vec<El<Msg>> {

#[wasm_bindgen]
pub fn render() {
let state = seed::App::build(Model::default(), update, view)
.finish()
.run();
let state = seed::App::builder(update, view).build_and_start();

state.update(Msg::GetData)
}
2 changes: 1 addition & 1 deletion examples/todomvc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn routes(url: seed::Url) -> Option<Msg> {

#[wasm_bindgen(start)]
pub fn render() {
seed::App::build(|_, _| Init::new(Model::default()), update, view)
seed::App::builder(update, view)
.routes(routes)
.build_and_start();
}
8 changes: 1 addition & 7 deletions examples/update_from_js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ struct Model {
time_from_js: Option<String>,
}

// Init

fn init(_: Url, _: &mut impl Orders<Msg>) -> Init<Model> {
Init::new(Model::default())
}

// Update

#[derive(Clone)]
Expand Down Expand Up @@ -76,7 +70,7 @@ fn view(model: &Model) -> Node<Msg> {
#[wasm_bindgen]
// `wasm-bindgen` cannot transfer struct with public closures to JS (yet) so we have to send slice.
pub fn start() -> Box<[JsValue]> {
let app = seed::App::build(init, update, view).build_and_start();
let app = seed::App::builder(update, view).build_and_start();

create_closures_for_js(&app)
}
Expand Down
10 changes: 6 additions & 4 deletions examples/user_media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use web_sys::{HtmlMediaElement, MediaStream, MediaStreamConstraints};

struct Model {}

// Init
// AfterMount

fn init(_: Url, orders: &mut impl Orders<Msg>) -> Init<Model> {
fn after_mount(_: Url, orders: &mut impl Orders<Msg>) -> AfterMount<Model> {
orders.perform_cmd(user_media());
Init::new(Model {})
AfterMount::new(Model {})
}

fn user_media() -> impl Future<Item = Msg, Error = Msg> {
Expand Down Expand Up @@ -74,5 +74,7 @@ fn view(_: &Model) -> impl View<Msg> {

#[wasm_bindgen(start)]
pub fn start() {
seed::App::build(init, update, view).build_and_start();
seed::App::builder(update, view)
.after_mount(after_mount)
.build_and_start();
}
8 changes: 5 additions & 3 deletions examples/websocket/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ struct Model {

// Init

fn init(_: Url, orders: &mut impl Orders<Msg>) -> Init<Model> {
fn after_mount(_: Url, orders: &mut impl Orders<Msg>) -> AfterMount<Model> {
let ws = WebSocket::new(WS_URL).unwrap();

register_ws_handler(WebSocket::set_onopen, Msg::Connected, &ws, orders);
register_ws_handler(WebSocket::set_onclose, Msg::Closed, &ws, orders);
register_ws_handler(WebSocket::set_onmessage, Msg::ServerMessage, &ws, orders);
register_ws_handler(WebSocket::set_onerror, Msg::Error, &ws, orders);

Init::new(Model {
AfterMount::new(Model {
ws,
connected: false,
msg_rx_cnt: 0,
Expand Down Expand Up @@ -154,5 +154,7 @@ fn view(model: &Model) -> impl View<Msg> {

#[wasm_bindgen(start)]
pub fn start() {
App::build(init, update, view).build_and_start();
App::builder(update, view)
.after_mount(after_mount)
.build_and_start();
}
2 changes: 1 addition & 1 deletion examples/window_events/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn window_events(model: &Model) -> Vec<Listener<Msg>> {

#[wasm_bindgen(start)]
pub fn render() {
seed::App::build(|_, _| Init::new(Model::default()), update, view)
seed::App::builder(update, view)
.window_events(window_events)
.build_and_start();
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub mod prelude {
request_animation_frame, ClosureNew, RequestAnimationFrameHandle,
RequestAnimationFrameTime,
},
vdom::{Init, MountType, RenderTimestampDelta, UrlHandling},
vdom::{AfterMount, BeforeMount, Init, MountType, RenderTimestampDelta, UrlHandling},
};
pub use indexmap::IndexMap; // for attrs and style to work.
pub use wasm_bindgen::prelude::*;
Expand Down
5 changes: 5 additions & 0 deletions src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ impl<Ms, Mdl, ElC: View<Ms>, GMs> OrdersContainer<Ms, Mdl, ElC, GMs> {
app,
}
}

pub(crate) fn merge(&mut self, mut other: Self) {
self.should_render = other.should_render;
self.effects.append(&mut other.effects);
}
}

impl<Ms: 'static, Mdl, ElC: View<Ms> + 'static, GMs> Orders<Ms, GMs>
Expand Down
Loading