chore: polish

This commit is contained in:
Jonathan Kelley 2021-11-16 13:09:41 -05:00
parent 25a8411485
commit 8bf57dc21d
5 changed files with 63 additions and 25 deletions

View file

@ -43,7 +43,7 @@ impl ToTokens for CallBody {
quote! {#inner}
} else {
let childs = &self.roots;
quote! { __cx.fragment_from_iter([ #(#childs),* ]) }
quote! { __cx.fragment_root([ #(#childs),* ]) }
};
match &self.custom_context {

View file

@ -643,6 +643,29 @@ impl<'a> NodeFactory<'a> {
}
}
pub fn fragment_root<'b, 'c>(
self,
node_iter: impl IntoIterator<Item = impl IntoVNode<'a> + 'c> + 'b,
) -> VNode<'a> {
let bump = self.bump;
let mut nodes = bumpalo::collections::Vec::new_in(bump);
for node in node_iter {
nodes.push(node.into_vnode(self));
}
if nodes.is_empty() {
nodes.push(VNode::Anchor(bump.alloc(VAnchor {
dom_id: empty_cell(),
})));
}
VNode::Fragment(VFragment {
children: nodes.into_bump_slice(),
key: None,
})
}
pub fn fragment_from_iter<'b, 'c>(
self,
node_iter: impl IntoIterator<Item = impl IntoVNode<'a> + 'c> + 'b,
@ -665,20 +688,17 @@ impl<'a> NodeFactory<'a> {
// todo: add a backtrace
if cfg!(debug_assertions) && children.len() > 1 && children.last().unwrap().key().is_none()
{
// todo: rsx! calls get turned into fragments which means they always trip this error
//
//
// use backtrace::Backtrace;
// let bt = Backtrace::new();
use backtrace::Backtrace;
let bt = Backtrace::new();
log::error!(
r#"
Warning: Each child in an array or iterator should have a unique "key" prop.
Not providing a key will lead to poor performance with lists.
See docs.rs/dioxus for more information.
-------------
{:?}
"#,
// bt
bt
);
}

View file

@ -347,11 +347,11 @@ impl Scope {
/// cx.render(lazy_tree)
/// }
///```
pub fn render<'src>(&'src self, lazy_nodes: Option<LazyNodes<'src, '_>>) -> Option<NodeLink> {
pub fn render<'src>(&'src self, rsx: Option<LazyNodes<'src, '_>>) -> Option<NodeLink> {
let frame = self.wip_frame();
let bump = &frame.bump;
let factory = NodeFactory { bump };
let node = lazy_nodes.map(|f| f.call(factory))?;
let node = rsx.map(|f| f.call(factory))?;
let node = bump.alloc(node);
let node_ptr = node as *mut _;

View file

@ -54,11 +54,6 @@ pub fn launch_with_props<P: Properties + 'static + Send + Sync>(
run(root, props, builder)
}
#[derive(Serialize)]
enum RpcEvent<'a> {
Initialize { edits: Vec<DomEdit<'a>> },
}
#[derive(Serialize)]
struct Response<'a> {
pre_rendered: Option<String>,
@ -74,7 +69,7 @@ pub fn run<T: 'static + Send + Sync>(
let mut cfg = DesktopConfig::new();
user_builder(&mut cfg);
let DesktopConfig {
window,
window: window_cfg,
manual_edits,
pre_rendered,
..
@ -100,7 +95,7 @@ pub fn run<T: 'static + Send + Sync>(
match window_event {
Event::NewEvents(StartCause::Init) => {
let window = create_window(event_loop);
let window = create_window(event_loop, &window_cfg);
let window_id = window.id();
let sender =
launch_vdom_with_tokio(root, props_shared.take().unwrap(), edit_queue.clone());
@ -234,13 +229,9 @@ fn build_menu() -> MenuBar {
menu_bar_menu
}
fn create_window(event_loop: &EventLoopWindowTarget<()>) -> Window {
WindowBuilder::new()
.with_maximized(true)
.with_menu(build_menu())
.with_title("Dioxus App")
.build(event_loop)
.unwrap()
fn create_window(event_loop: &EventLoopWindowTarget<()>, cfg: &WindowBuilder) -> Window {
let builder = cfg.clone().with_menu(build_menu());
builder.build(event_loop).unwrap()
}
fn create_webview(
@ -264,7 +255,7 @@ fn create_webview(
}
_ => {}
}
// always driven through eval
None
})
// Any content that that uses the `wry://` scheme will be shuttled through this handler as a "special case"

View file

@ -682,8 +682,35 @@ builder_constructors! {
/// Build a
/// [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
/// element.
///
/// The [`script`] HTML element is used to embed executable code or data; this is typically used to embed or refer to
/// JavaScript code. The [`script`] element can also be used with other languages, such as WebGL's GLSL shader
/// programming language and JSON.
script {
/// Normal script elements pass minimal information to the window.onerror for scripts which do not pass the
/// standard CORS checks. To allow error logging for sites which use a separate domain for static media, use
/// this attribute. See CORS settings attributes for a more descriptive explanation of its valid arguments.
crossorigin: CrossOrigin,
/// This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the
/// document has been parsed, but before firing DOMContentLoaded.
///
/// Scripts with the defer attribute will prevent the DOMContentLoaded event from firing until the script has
/// loaded and finished evaluating.
///
/// ----
/// ### Warning:
///
/// This attribute must not be used if the src attribute is absent (i.e. for inline scripts), in this
/// case it would have no effect.
///
/// ----
///
/// The defer attribute has no effect on module scripts — they defer by default.
/// Scripts with the defer attribute will execute in the order in which they appear in the document.
///
/// This attribute allows the elimination of parser-blocking JavaScript where the browser would have to load and
/// evaluate scripts before continuing to parse. async has a similar effect in this case.
defer: Bool,
integrity: Integrity,
nomodule: Bool,