Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Fill out examples #16

Merged
merged 17 commits into from
Feb 12, 2019
Merged

Fill out examples #16

merged 17 commits into from
Feb 12, 2019

Conversation

fitzgen
Copy link
Owner

@fitzgen fitzgen commented Feb 12, 2019

@alexcrichton want to take a look at the TodoMVC implementation?

If you're interested in some lolsob, also check out 5837d53...

Copy link
Collaborator

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was quite a pleasure to read over! All the pieces really are seriously coming together here...

I do think we gotta put some elbow grease into creating nodes before this super-awesome, but I'll settle for just awesome for now

@@ -41,12 +41,14 @@ features = [
]

[profile.release]
# Tell `rustc` to optimize for small code size.
incremental = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional = true
version = "0.4.6"

[dependencies.serde]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might recommend collapsing these using inline tables where possible (as it's a bit more idiomatic I think)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated my cargo update but it still is canonicalizing everything like this :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't think they're using something which preserves formatting (not sure if that exists in a production-ready capacity even...)


[dependencies.log]
optional = true
version = "0.4.6"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to expose some features of this to compile out debug! and/or info! statements perhaps?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crate itself doesn't do any logging, just dodrio but it does need to depend on log to get the Level when initializing the console_log logger. So I think it is OK to tie them together in the logging feature since they are only ever used together.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh for sure, but debug!'s code is emitted by default, which means there's a runtime check and the code for formatting is all compiled in. For the tiniest binaries we probably want to compile out the log messages?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been seeing some debug!s get compiled away when there is no logger -- should double check that for dodrio for sure though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right that's a good point. I think LTO is good enough to see that if no one sets the max log level the max log level is a constant that forbids logging so everything is optimized away as if it were already compiled out

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>dodrio • TodoMVC</title>
<link rel="stylesheet" href="node_modules/todomvc-common/base.css">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there perhaps an NPM CDN thing we could use to skip the npm install step for this?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call: https://unpkg.com/


/// Invoke `f` with the root `Todos` component, save the (likely just modified)
/// todos to local storage, and schedule a new `dodrio` render.
fn with_todos<F>(root: &mut dyn RootRender, vdom: VdomWeak, f: F)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using RAII may make this a bit more ergonomic to call by skipping some indentation maybe?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not more ergonomic to write initially though

/// Start the router.
pub fn start(vdom: VdomWeak) {
// Callback fired whenever the URL's hash fragment changes. Keeps the root
// TODOs collection's visibility in sync with the `#` fragment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now this is tricky

It's a comment that starts with "TODO"

not a TODO comment

// Call it once to handle the initial `#` fragment.
on_hash_change();

// Now listen for hash changes forever.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a small comment could be added about how this technically isn't linking memory within the context of this one application?

}

/// Get this TODO's title.
pub fn title(&self) -> &str {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I smell a derive macro for stuff like this

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just make it all pub... a real application would probably not use pub so I didn't here either. This is kind of an in-between scenario.

let title = self.edits.as_ref().unwrap_or(&self.title);
let elem_id = bumpalo::format!(in bump, "todo-{}", id);

let mut input_attrs = bumpalo::vec![
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just gotta say. This, ergonomically, is pretty awesome

}
let input_attrs = input_attrs.into_bump_slice();

Node::element(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh we should definitely clean this up a bit at some point :)

(the helper methods you were mentioning would be perfect)

(well, that plus maybe a builder to add attributes)

@alexcrichton
Copy link
Collaborator

Also I demand validation-via-travis.

And I request publication-via-travis.

@fitzgen fitzgen merged commit ca435e8 into master Feb 12, 2019
@fitzgen fitzgen deleted the fill-out-examples branch February 12, 2019 21:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants