Merge MutableAppContext into AppContext

There may have been a good reason for the difference at some point, or I was
still learning Rust. But now it's just &mut AppContext vs &AppContext.
This commit is contained in:
Nathan Sobo 2023-04-06 15:49:03 -06:00
parent dd00966cc6
commit de9bf6dfbd
112 changed files with 882 additions and 1041 deletions

View file

@ -19,9 +19,8 @@ use smol::stream::StreamExt;
use crate::{
executor, geometry::vector::Vector2F, keymap_matcher::Keystroke, platform, Action,
AnyViewHandle, AppContext, Appearance, Entity, Event, FontCache, Handle, InputHandler,
KeyDownEvent, ModelContext, ModelHandle, MutableAppContext, Platform, ReadModelWith,
ReadViewWith, RenderContext, Task, UpdateModel, UpdateView, View, ViewContext, ViewHandle,
WeakHandle,
KeyDownEvent, ModelContext, ModelHandle, Platform, ReadModelWith, ReadViewWith, RenderContext,
Task, UpdateModel, UpdateView, View, ViewContext, ViewHandle, WeakHandle,
};
use collections::BTreeMap;
@ -30,7 +29,7 @@ use super::{
};
pub struct TestAppContext {
cx: Rc<RefCell<MutableAppContext>>,
cx: Rc<RefCell<AppContext>>,
foreground_platform: Rc<platform::test::ForegroundPlatform>,
condition_duration: Option<Duration>,
pub function_name: String,
@ -48,7 +47,7 @@ impl TestAppContext {
first_entity_id: usize,
function_name: String,
) -> Self {
let mut cx = MutableAppContext::new(
let mut cx = AppContext::new(
foreground,
background,
platform,
@ -149,15 +148,15 @@ impl TestAppContext {
self.cx.borrow().window_ids().collect()
}
pub fn root_view<T: View>(&self, window_id: usize) -> Option<ViewHandle<T>> {
pub fn root_view(&self, window_id: usize) -> Option<AnyViewHandle> {
self.cx.borrow().root_view(window_id)
}
pub fn read<T, F: FnOnce(&AppContext) -> T>(&self, callback: F) -> T {
callback(self.cx.borrow().as_ref())
callback(&*self.cx.borrow())
}
pub fn update<T, F: FnOnce(&mut MutableAppContext) -> T>(&mut self, callback: F) -> T {
pub fn update<T, F: FnOnce(&mut AppContext) -> T>(&mut self, callback: F) -> T {
let mut state = self.cx.borrow_mut();
// Don't increment pending flushes in order for effects to be flushed before the callback
// completes, which is helpful in tests.
@ -194,7 +193,7 @@ impl TestAppContext {
}
pub fn font_cache(&self) -> Arc<FontCache> {
self.cx.borrow().cx.font_cache.clone()
self.cx.borrow().font_cache.clone()
}
pub fn foreground_platform(&self) -> Rc<platform::test::ForegroundPlatform> {
@ -202,7 +201,7 @@ impl TestAppContext {
}
pub fn platform(&self) -> Arc<dyn platform::Platform> {
self.cx.borrow().cx.platform.clone()
self.cx.borrow().platform.clone()
}
pub fn foreground(&self) -> Rc<executor::Foreground> {
@ -396,7 +395,7 @@ impl ReadModelWith for TestAppContext {
read: &mut dyn FnMut(&E, &AppContext) -> T,
) -> T {
let cx = self.cx.borrow();
let cx = cx.as_ref();
let cx = &*cx;
read(handle.read(cx), cx)
}
}
@ -424,7 +423,7 @@ impl ReadViewWith for TestAppContext {
V: View,
{
let cx = self.cx.borrow();
let cx = cx.as_ref();
let cx = &*cx;
read(handle.read(cx), cx)
}
}
@ -513,7 +512,7 @@ impl<T: Entity> ModelHandle<T> {
loop {
{
let cx = cx.borrow();
let cx = cx.as_ref();
let cx = &*cx;
if predicate(
handle
.upgrade(cx)
@ -600,7 +599,7 @@ impl<T: View> ViewHandle<T> {
loop {
{
let cx = cx.borrow();
let cx = cx.as_ref();
let cx = &*cx;
if predicate(
handle
.upgrade(cx)