Skip to content

Commit

Permalink
[core] Refactor core crate.
Browse files Browse the repository at this point in the history
* Move remaining functionality to embed module.
* Runtime::handle -> context_handle
* Free functions are thin wrappers around RuntimeContext.
* moxie::embed -> moxie::runtime
* Remove built-in executor.
  * It was only used for testing, replace with futures LocalPool.
  • Loading branch information
anp committed Jun 30, 2020
1 parent bf91754 commit 8441c5d
Show file tree
Hide file tree
Showing 12 changed files with 590 additions and 847 deletions.
17 changes: 8 additions & 9 deletions benches/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@ extern crate criterion;

use criterion::{Criterion, ParameterizedBenchmark};
use moxie::{
embed::{Revision, Runtime},
once,
runtime::{Revision, RunLoop},
};
use std::rc::Rc;

criterion::criterion_group!(runtime, once_from_store, run_empty, run_repeated);
criterion::criterion_main!(runtime);

fn once_from_store(c: &mut Criterion) {
let mut rt = Runtime::new();
let run = || once(|| Rc::new(vec![0; 1_000_000]));
rt.run_once(run);
c.bench_function("1mb vec cached", |b| b.iter(|| rt.run_once(run)));
let mut rt = RunLoop::new(|| once(|| Rc::new(vec![0; 1_000_000])));
rt.run_once();
c.bench_function("1mb vec cached", |b| b.iter(|| rt.run_once()));
}

fn run_empty(c: &mut Criterion) {
let mut rt = Runtime::new();
c.bench_function("run_empty", |b| b.iter(|| rt.run_once(Revision::current)));
let mut rt = RunLoop::new(Revision::current);
c.bench_function("run_empty", |b| b.iter(|| rt.run_once()));
}

fn run_n_times_empty(b: &mut criterion::Bencher, n: &usize) {
let mut rt = Runtime::new();
let mut rt = RunLoop::new(Revision::current);
b.iter(|| {
for _ in 0..*n {
rt.run_once(Revision::current);
rt.run_once();
}
});
}
Expand Down
12 changes: 6 additions & 6 deletions dom/src/embed.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Embedding APIs offering finer-grained control over execution of the runtime.
use crate::{interfaces::node::Child, memo_node::MemoNode};
use moxie::embed::RootedRuntime;
use moxie::runtime::RunLoop;

/// Wrapper around `moxie::embed::Runtime` which provides an `Env` for building
/// trees of DOM nodes.
/// Wrapper around `moxie::runtime::RunLoop` which provides an environment for
/// building trees of DOM nodes.
#[must_use]
pub struct WebRuntime {
inner: RootedRuntime<Box<dyn FnMut()>>,
inner: RunLoop<Box<dyn FnMut()>>,
}

impl WebRuntime {
Expand All @@ -23,7 +23,7 @@ impl WebRuntime {
) -> Self {
let parent = parent.into();
WebRuntime {
inner: RootedRuntime::new(Box::new(move || {
inner: RunLoop::new(Box::new(move || {
illicit::Layer::new().with(MemoNode::new(parent.clone())).enter(|| {
let new_root = topo::call(|| root());

Expand All @@ -36,7 +36,7 @@ impl WebRuntime {
}

/// Run the root function in a fresh `moxie::Revision`. See
/// `moxie::embed::Runtime::run_once` for details.
/// `moxie::runtime::RunLoop::run_once` for details.
pub fn run_once(&mut self) {
self.inner.run_once();
}
Expand Down
2 changes: 1 addition & 1 deletion dom/src/interfaces/event_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where
#[topo::nested]
fn on(self, callback: impl FnMut(Ev) + 'static) -> Self {
memo_with(
moxie::embed::Revision::current(),
moxie::runtime::Revision::current(),
|_| EventHandle::new(self.raw_node_that_has_sharp_edges_please_be_careful(), callback),
|_| {},
);
Expand Down
308 changes: 0 additions & 308 deletions src/embed.rs

This file was deleted.

Loading

0 comments on commit 8441c5d

Please sign in to comment.