Skip to content

Commit

Permalink
Make create_ext_action use FnOnce (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinusGix authored Dec 6, 2023
1 parent 2f3e93b commit 9dba156
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ext_event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::VecDeque, sync::Arc};
use std::{cell::Cell, collections::VecDeque, sync::Arc};

use floem_reactive::{create_effect, untrack, with_scope, ReadSignal, Scope, Trigger, WriteSignal};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -36,7 +36,7 @@ impl ExtEventHandler {

pub fn create_ext_action<T: Send + 'static>(
cx: Scope,
action: impl Fn(T) + 'static,
action: impl FnOnce(T) + 'static,
) -> impl FnOnce(T) {
let view = get_current_view();
let cx = cx.create_child();
Expand All @@ -45,13 +45,15 @@ pub fn create_ext_action<T: Send + 'static>(

{
let data = data.clone();
let action = Cell::new(Some(action));
with_scope(cx, move || {
create_effect(move |_| {
trigger.track();
if let Some(event) = data.lock().take() {
untrack(|| {
let current_view = get_current_view();
set_current_view(view);
let action = action.take().unwrap();
action(event);
set_current_view(current_view);
});
Expand Down

0 comments on commit 9dba156

Please sign in to comment.