1use gpui::{App, Context, Entity};
5use purview::{ActionError, OnUi, Outcome, on_ui};
6
7pub fn on_entity<V, O, F>(
20 entity: &Entity<V>,
21 f: F,
22) -> OnUi<impl Fn(&mut App) -> Result<O, ActionError> + Send + Sync + 'static>
23where
24 V: 'static,
25 O: Into<Outcome> + Send + 'static,
26 F: Fn(&mut V, &mut Context<V>) -> Result<O, ActionError> + Send + Sync + 'static,
27{
28 let entity = entity.clone();
29 on_ui(move |cx: &mut App| entity.update(cx, |v, c| f(v, c)))
30}
31
32pub fn on_entity_with<V, P, O, F>(
36 entity: &Entity<V>,
37 f: F,
38) -> OnUi<impl Fn(P, &mut App) -> Result<O, ActionError> + Send + Sync + 'static>
39where
40 V: 'static,
41 P: for<'de> serde::Deserialize<'de> + Send + 'static,
42 O: Into<Outcome> + Send + 'static,
43 F: Fn(P, &mut V, &mut Context<V>) -> Result<O, ActionError> + Send + Sync + 'static,
44{
45 let entity = entity.clone();
46 on_ui(move |p: P, cx: &mut App| entity.update(cx, |v, c| f(p, v, c)))
47}