Skip to content

Commit 6676b70

Browse files
First changes
1 parent 4cb61ac commit 6676b70

34 files changed

+1997
-0
lines changed

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "ruex"
3+
version = "0.1.0"
4+
authors = ["Victor Dudochkin <dudochkin.victor@gmail.com>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
yew = "0.17"
9+
log = "0.4"
10+
serde = { version = "1.0", features = ["derive"] }
11+
wasm-logger = "0.2"

src/core/controller.rs

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//! A Singleton IController implementation.
2+
//!
3+
//! In RuEx, the Controller class follows the
4+
//! 'Command and Controller' strategy, and assumes these
5+
//! responsibilities:
6+
//!
7+
//! * Remembering which ICommands
8+
//! are intended to handle which INotifications.
9+
//! * Registering itself as an IObserver with
10+
//! the View for each INotification
11+
//! that it has an ICommand mapping for.
12+
//! * Creating a new instance of the proper ICommand
13+
//! to handle a given INotification when notified by the View.
14+
//! * Calling the ICommand's execute
15+
//! method, passing in the INotification.
16+
//!
17+
//! Your application must register ICommands with the
18+
//! Controller.
19+
//!
20+
//! The simplest way is to subclass Facade,
21+
//! and use its initializeController method to add your
22+
//! registrations.
23+
//!
24+
25+
#![allow(unused_variables)]
26+
#![allow(dead_code)]
27+
28+
// use crate::core::*;
29+
use crate::interfaces::*;
30+
// use crate::patterns::observer::*;
31+
32+
// // Singleton instance
33+
// protected static var instance : IController;
34+
35+
// // Message Constants
36+
// protected const SINGLETON_MSG : String = "Controller Singleton already constructed!";
37+
38+
pub struct Controller<B, C, V> {
39+
/// Local reference to View
40+
view: Box<dyn IView<B, C, V>>,
41+
42+
/// Mapping of Notification names to Command Class references
43+
command_map: Vec<String>,
44+
}
45+
46+
impl<B, C, V> Controller<B, C, V> {
47+
/// Constructor.
48+
///
49+
///
50+
/// This IController implementation is a Singleton,
51+
/// so you should not call the constructor
52+
/// directly, but instead call the static Singleton
53+
/// Factory method Controller.getInstance()
54+
///
55+
/// @throws Error Error if Singleton instance has already been constructed
56+
pub fn new() {
57+
// if (instance != null) throw Error(SINGLETON_MSG);
58+
// instance = this;
59+
// commandMap = new Array();
60+
// initializeController();
61+
}
62+
63+
/// Initialize the Singleton Controller instance.
64+
///
65+
/// Called automatically by the constructor.
66+
///
67+
/// Note that if you are using a subclass of View
68+
/// in your application, you should also subclass Controller
69+
/// and override the initializeController method in the
70+
/// following way:
71+
///
72+
/// //TODO: Example here
73+
///
74+
fn initialize_controller() {
75+
// view = View.getInstance();
76+
}
77+
78+
/// Controller Singleton Factory method.
79+
///
80+
/// Returns the Singleton instance of Controller
81+
/// pub static fn
82+
pub fn get_instance() -> Box<dyn IController<B>> {
83+
// if ( instance == null ) instance = new Controller( );
84+
// return instance;
85+
unimplemented!()
86+
}
87+
}
88+
89+
impl<B, C, V> IController<B> for Controller<B, C, V> {
90+
/// If an ICommand has previously been registered
91+
/// to handle a the given INotification, then it is executed.
92+
///
93+
/// * `note` - an INotification
94+
fn execute_command(&self, note: Box<dyn INotification<B>>) {
95+
// var commandFactory : Box<dyn FnOnce()> = commandMap[ note.getName() ];
96+
// if ( commandFactory == null ) return;
97+
98+
// var commandInstance : ICommand = new commandFactory();
99+
// commandInstance.execute( note );
100+
}
101+
102+
/// Register a particular ICommand class as the handler
103+
/// for a particular INotification.
104+
///
105+
/// If an ICommand has already been registered to
106+
/// handle INotifications with this name, it is no longer
107+
/// used, the new ICommand is used instead.
108+
///
109+
/// The Observer for the new ICommand is only created if this the
110+
/// first time an ICommand has been regisered for this Notification name.
111+
///
112+
/// * `notification_name` - the name of the INotification
113+
/// * `command_factory` - the Class of the ICommand
114+
fn register_command(&self, notification_name: String, command_factory: Box<dyn FnOnce()>) {
115+
// if ( commandMap[ notificationName ] == null ) {
116+
// view.registerObserver( notificationName, new Observer( executeCommand, this ) );
117+
// }
118+
// commandMap[ notificationName ] = commandFactory;
119+
}
120+
121+
/// Check if a Command is registered for a given Notification
122+
///
123+
/// * `notification_name` -
124+
/// Returns whether a Command is currently registered for the given notificationName.
125+
fn has_command(&self, notification_name: String) -> bool {
126+
// return commandMap[ notificationName ] != null;
127+
unimplemented!()
128+
}
129+
130+
/// Remove a previously registered ICommand to INotification mapping.
131+
///
132+
/// * `notification_name` - the name of the INotification to remove the ICommand mapping for
133+
fn remove_command(&self, notification_name: String) {
134+
// // if the Command is registered...
135+
// if ( hasCommand( notificationName ) )
136+
// {
137+
// // remove the observer
138+
// view.removeObserver( notificationName, this );
139+
140+
// // remove the command
141+
// commandMap[ notificationName ] = null;
142+
// }
143+
}
144+
}

src/core/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod controller;
2+
pub use controller::*;
3+
4+
mod model;
5+
pub use model::*;
6+
7+
mod view;
8+
pub use model::*;

src/core/model.rs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//! A Singleton IModel implementation.
2+
//!
3+
//! In RuEx, the Model class provides
4+
//! access to model objects (Proxies) by named lookup.
5+
//!
6+
//! The Model assumes these responsibilities:
7+
//!
8+
//! * Maintain a cache of IProxy instances.
9+
//! * Provide methods for registering, retrieving, and removing
10+
//! IProxy instances.
11+
//!
12+
//! Your application must register IProxy instances
13+
//! with the Model. Typically, you use an
14+
//! ICommand to create and register IProxy
15+
//! instances once the Facade has initialized the Core
16+
//! actors.
17+
18+
#![allow(dead_code)]
19+
#![allow(unused_variables)]
20+
21+
use crate::interfaces::*;
22+
23+
// // Singleton instance
24+
// protected static var instance : IModel;
25+
26+
// // Message Constants
27+
// protected const SINGLETON_MSG : String = "Model Singleton already constructed!";
28+
29+
pub struct Model<D> {
30+
/// Mapping of proxyNames to IProxy instances
31+
proxy_map: Vec<D>, // FIXME: adjust
32+
}
33+
34+
impl<D> Model<D> {
35+
/// Constructor.
36+
///
37+
///
38+
/// This IModel implementation is a Singleton,
39+
/// so you should not call the constructor
40+
/// directly, but instead call the static Singleton
41+
/// Factory method Model.getInstance()
42+
///
43+
/// @throws Error Error if Singleton instance has already been constructed
44+
pub fn new() {
45+
// if (instance != null) throw Error(SINGLETON_MSG);
46+
// instance = this;
47+
// proxyMap = new Array();
48+
// initializeModel();
49+
}
50+
51+
/// Initialize the Singleton Model instance.
52+
///
53+
/// Called automatically by the constructor, this
54+
/// is your opportunity to initialize the Singleton
55+
/// instance in your subclass without overriding the
56+
/// constructor.
57+
///
58+
fn initialize_model() {}
59+
60+
/// Model Singleton Factory method.
61+
///
62+
/// Returns the Singleton instance
63+
/// static fn
64+
fn get_instance() -> Box<dyn IModel<D>> {
65+
// if (instance == null) instance = new Model( );
66+
// return instance;
67+
unimplemented!()
68+
}
69+
}
70+
71+
impl<D> IModel<D> for Model<D> {
72+
/// Register an IProxy with the Model.
73+
///
74+
/// * `proxy` - an IProxy to be held by the Model.
75+
fn register_proxy(&self, proxy: Box<dyn IProxy<D>>) {
76+
// proxyMap[ proxy.getProxyName() ] = proxy;
77+
// proxy.onRegister();
78+
}
79+
80+
/// Retrieve an IProxy from the Model.
81+
///
82+
/// * `proxy_name` -
83+
/// Returns the IProxy instance previously registered with the given proxyName.
84+
fn retrieve_proxy(&self, proxy_name: String) -> Box<dyn IProxy<D>> {
85+
// return proxyMap[ proxyName ];
86+
unimplemented!()
87+
}
88+
89+
/// Check if a Proxy is registered
90+
///
91+
/// * `proxy_name` -
92+
/// Returns whether a Proxy is currently registered with the given proxyName.
93+
fn has_proxy(&self, proxy_name: String) -> bool {
94+
// return proxyMap[ proxy_name ] != null;
95+
unimplemented!()
96+
}
97+
98+
/// Remove an IProxy from the Model.
99+
///
100+
/// * `proxy_name` - name of the IProxy instance to be removed.
101+
/// Returns the IProxy that was removed from the Model
102+
fn remove_proxy(&self, proxy_name: String) -> Box<dyn IProxy<D>> {
103+
// var proxy:IProxy = proxyMap [ proxyName ] as IProxy;
104+
// if ( proxy )
105+
// {
106+
// proxyMap[ proxyName ] = null;
107+
// proxy.onRemove();
108+
// }
109+
// return proxy;
110+
unimplemented!()
111+
}
112+
}

0 commit comments

Comments
 (0)