hello
This commit is contained in:
parent
cdb7a9b8e3
commit
8b0fdef461
3 changed files with 43 additions and 43 deletions
|
@ -69,6 +69,43 @@ pub enum DepNode {
|
|||
ModelValue(Symbol),
|
||||
}
|
||||
|
||||
impl DepNode {
|
||||
fn gen_update_code(
|
||||
&self,
|
||||
model_bimap: &BiHashMap<Id, String>,
|
||||
updates: &mut TokenStream,
|
||||
update_func: &mut TokenStream,
|
||||
) {
|
||||
match self {
|
||||
DepNode::ModelValue(sym) => {
|
||||
let sym_name = format_ident!("{}", model_bimap.get_by_left(&sym).unwrap());
|
||||
let inner_lock = format_ident!("inner_lock_{}", Symbol::gensym().as_str());
|
||||
updates.extend(quote! {
|
||||
let #inner_lock = self.#sym_name.clone();
|
||||
});
|
||||
update_func.extend(quote! {
|
||||
{
|
||||
let mut locked = #inner_lock.lock();
|
||||
*locked = new_value.clone();
|
||||
}
|
||||
});
|
||||
}
|
||||
DepNode::RsxSpan(id) => {
|
||||
let id_str = id.as_str();
|
||||
update_func.extend(quote! {
|
||||
{
|
||||
use enterprise::stdweb::web::{INonElementParentNode, INode};
|
||||
if let Some(target) = enterprise::stdweb::web::document().get_element_by_id(#id_str) {
|
||||
target.set_text_content(&new_value.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type DependencyGraph = DiGraphMap<DepNode, ()>;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
|
@ -164,39 +201,11 @@ impl Visitor {
|
|||
let mut update_func = TokenStream::new();
|
||||
while let Some(nx) = dfs.next(&self.deps) {
|
||||
if nx != starting {
|
||||
match nx {
|
||||
DepNode::ModelValue(sym) => {
|
||||
let sym_name = format_ident!(
|
||||
"{}",
|
||||
self.model_bimap.get_by_left(&sym).unwrap()
|
||||
nx.gen_update_code(
|
||||
&self.model_bimap,
|
||||
&mut updates,
|
||||
&mut update_func,
|
||||
);
|
||||
let inner_lock = format_ident!(
|
||||
"inner_lock_{}",
|
||||
Symbol::gensym().as_str()
|
||||
);
|
||||
updates.extend(quote! {
|
||||
let #inner_lock = self.#sym_name.clone();
|
||||
});
|
||||
update_func.extend(quote! {
|
||||
{
|
||||
let mut locked = #inner_lock.lock();
|
||||
*locked = new_value.clone();
|
||||
}
|
||||
});
|
||||
}
|
||||
DepNode::RsxSpan(id) => {
|
||||
let id_str = id.as_str();
|
||||
update_func.extend(quote! {
|
||||
{
|
||||
use enterprise::stdweb::web::{INonElementParentNode, INode};
|
||||
if let Some(target) = enterprise::stdweb::web::document().get_element_by_id(#id_str) {
|
||||
target.set_text_content(&new_value.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
updates.extend(quote! {
|
||||
|
|
|
@ -1,21 +1,12 @@
|
|||
#[macro_use]
|
||||
extern crate enterprise;
|
||||
|
||||
// #[macro_use]
|
||||
extern crate stdweb;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use enterprise::{Backend, Component, Web};
|
||||
|
||||
// use stdweb::{
|
||||
// unstable::TryFrom,
|
||||
// web::{
|
||||
// document, html_element::InputElement, Element, IElement, IEventTarget, INode,
|
||||
// INonElementParentNode,
|
||||
// },
|
||||
// };
|
||||
|
||||
example!();
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="enterprise.js"></script>
|
||||
<script src="helloworld.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue