1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! This module contains the worker agent implementation.
//!
//! This is a low-level implementation that uses an actor model.
//!
//! # Example
//!
//! ```
//! # mod example {
//! use serde::{Deserialize, Serialize};
//! use yew::prelude::*;
//! use yew_agent::worker::{use_worker_bridge, UseWorkerBridgeHandle};
//!
//! // This would usually live in the same file as your worker
//! #[derive(Serialize, Deserialize)]
//! pub enum WorkerResponseType {
//! IncrementCounter,
//! }
//! # mod my_worker_mod {
//! # use yew_agent::worker::{HandlerId, WorkerScope};
//! # use super::WorkerResponseType;
//! # pub struct MyWorker {}
//! #
//! # impl yew_agent::worker::Worker for MyWorker {
//! # type Input = ();
//! # type Output = WorkerResponseType;
//! # type Message = ();
//! #
//! # fn create(scope: &WorkerScope<Self>) -> Self {
//! # MyWorker {}
//! # }
//! #
//! # fn update(&mut self, scope: &WorkerScope<Self>, _msg: Self::Message) {
//! # // do nothing
//! # }
//! #
//! # fn received(&mut self, scope: &WorkerScope<Self>, _msg: Self::Input, id: HandlerId) {
//! # scope.respond(id, WorkerResponseType::IncrementCounter);
//! # }
//! # }
//! # }
//! use my_worker_mod::MyWorker; // note that <MyWorker as yew_agent::Worker>::Output == WorkerResponseType
//! #[component(UseWorkerBridge)]
//! fn bridge() -> Html {
//! let counter = use_state(|| 0);
//!
//! // a scoped block to clone the state in
//! {
//! let counter = counter.clone();
//! // response will be of type MyWorker::Output, i.e. WorkerResponseType
//! let bridge: UseWorkerBridgeHandle<MyWorker> = use_worker_bridge(move |response| match response {
//! WorkerResponseType::IncrementCounter => {
//! counter.set(*counter + 1);
//! }
//! });
//! }
//!
//! html! {
//! <div>
//! {*counter}
//! </div>
//! }
//! }
//! # }
//! ```
use RefCell;
use Rc;
pub use WorkerBridge;
pub use HandlerId;
pub use ;
pub use WorkerProviderState;
pub use ;
pub use WorkerRegistrar;
pub use ;
pub use WorkerSpawner;
pub use Worker;
/// Alias for `Rc<RefCell<T>>`
type Shared<T> = ;
/// Alias for `Rc<dyn Fn(IN)>`
type Callback<IN> = ;