Add start_app method

This commit is contained in:
Denis Kolodin 2019-02-02 01:26:04 +03:00
parent cfe5d84b8c
commit fc7f7a97ea
20 changed files with 80 additions and 195 deletions

View File

@ -6,6 +6,8 @@
### New features
- Added `start_app` method. It's a shortcut to initialize a component and mount it to the body.
### Bug fixes
## 0.5 - Released 2019-02-01

View File

@ -1,9 +1,5 @@
extern crate stdweb;
#[macro_use]
extern crate yew;
use stdweb::web::Date;
use yew::prelude::*;
use yew::{html, Component, ComponentLink, Renderable, ShouldRender};
use yew::services::ConsoleService;
pub struct Model {

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate counter;
use yew::prelude::*;
use counter::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<counter::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate crm;
use yew::prelude::*;
use crm::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<crm::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate custom_components;
use yew::prelude::*;
use custom_components::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<custom_components::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate dashboard;
use yew::prelude::*;
use dashboard::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<dashboard::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate fragments;
use yew::prelude::*;
use fragments::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<fragments::Model>();
}

View File

@ -1,9 +1,4 @@
extern crate yew;
extern crate game_of_life;
#[macro_use] extern crate log;
extern crate web_logger;
use log::trace;
use yew::prelude::*;
use game_of_life::{Model, Msg};
@ -11,7 +6,7 @@ fn main() {
web_logger::init();
trace!("Initializing yew...");
yew::initialize();
App::<Model>::new().mount_to_body()
App::<game_of_life::Model>::new().mount_to_body()
.send_message(Msg::Random);
yew::run_loop();
}

View File

@ -1,14 +1,3 @@
#![recursion_limit="512"]
extern crate stdweb;
extern crate yew;
extern crate inner_html;
use yew::prelude::*;
use inner_html::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<inner_html::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate js_callback;
use yew::prelude::*;
use js_callback::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<js_callback::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate large_table;
use yew::prelude::*;
use large_table::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<large_table::Model>();
}

View File

@ -1,5 +1,3 @@
fn main() {
yew::initialize();
yew::App::<minimal::Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<minimal::Model>();
}

View File

@ -1,10 +1,5 @@
#[macro_use]
extern crate stdweb;
extern crate yew;
extern crate mount_point;
use yew::prelude::*;
use stdweb::web::{IElement, INode, IParentNode, document};
use yew::App;
use stdweb::web::{js, IElement, INode, IParentNode, document};
use mount_point::Model;
fn main() {

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate npm_and_rest;
use yew::prelude::*;
use npm_and_rest::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<npm_and_rest::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate routing;
use yew::prelude::*;
use routing::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
}
yew::start_app::<routing::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate textarea;
use yew::prelude::*;
use textarea::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<textarea::Model>();
}

View File

@ -1,11 +1,3 @@
extern crate yew;
extern crate timer;
use yew::prelude::*;
use timer::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<timer::Model>();
}

View File

@ -1,12 +1,4 @@
extern crate yew;
extern crate todomvc;
use yew::prelude::*;
use todomvc::Model;
fn main() {
yew::initialize();
App::<Model>::new().mount_to_body();
yew::run_loop();
yew::start_app::<todomvc::Model>();
}

View File

@ -1,7 +1,3 @@
extern crate stdweb;
extern crate yew;
extern crate two_apps;
use stdweb::web::{IParentNode, document};
use yew::prelude::*;
use yew::html::Scope;

View File

@ -104,56 +104,16 @@ pub fn run_loop() {
stdweb::event_loop();
}
/// The Yew Prelude
///
/// The purpose of this module is to alleviate imports of many common types:
///
/// ```
/// # #![allow(unused_imports)]
/// use yew::prelude::*;
/// ```
pub mod prelude {
pub use html::{
Component,
ComponentLink,
Href,
Html,
Renderable,
ShouldRender,
};
pub use app::App;
pub use callback::Callback;
pub use agent::{
Bridge,
Bridged,
Threaded,
};
pub use events::*;
/// Prelude module for creating worker.
pub mod worker {
pub use agent::{
Agent,
AgentLink,
Bridge,
Bridged,
Context,
Global,
HandlerId,
Job,
Private,
Public,
Transferable,
};
}
/// Starts an app mounted to a body of the document.
pub fn start_app<COMP>()
where
COMP: Component + Renderable<COMP>,
{
initialize();
App::<COMP>::new().mount_to_body();
run_loop();
}
pub use self::prelude::*;
/// The module that contains all events available in the framework.
pub mod events {
pub use html::{
@ -203,3 +163,53 @@ pub mod events {
SubmitEvent
};
}
/// The Yew Prelude
///
/// The purpose of this module is to alleviate imports of many common types:
///
/// ```
/// # #![allow(unused_imports)]
/// use yew::prelude::*;
/// ```
pub mod prelude {
pub use html::{
Component,
ComponentLink,
Href,
Html,
Renderable,
ShouldRender,
};
pub use app::App;
pub use callback::Callback;
pub use agent::{
Bridge,
Bridged,
Threaded,
};
pub use events::*;
/// Prelude module for creating worker.
pub mod worker {
pub use agent::{
Agent,
AgentLink,
Bridge,
Bridged,
Context,
Global,
HandlerId,
Job,
Private,
Public,
Transferable,
};
}
}
pub use self::prelude::*;