Skip to content

Commit

Permalink
Address clippy lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Aug 4, 2024
1 parent ebb5c91 commit 8f83ee1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions playground/src/app/text_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
// https://github.com/broxamson/hcl-leptos-app/blob/6f2da694fb97e60f4d2fd7cc7038bfb483566ba3/src/pages/global_components/text_editor.rs
// https://github.com/siku2/rust-monaco/issues/50

#[cfg(target_arch = "wasm32")]
use std::{cell::RefCell, rc::Rc};

use leptos::{
component, create_node_ref, create_rw_signal, create_signal, html::Div, view, IntoView,
NodeRef, ReadSignal, RwSignal, SignalGetUntracked, WriteSignal,
component, create_node_ref, create_signal, html::Div, view, IntoView, NodeRef, ReadSignal,
WriteSignal,
};

#[cfg(target_arch = "wasm32")]
use monaco::api::{CodeEditor, TextModel};

#[cfg(target_arch = "wasm32")]
use leptos::{SignalGet, SignalSet, SignalUpdate};
use leptos::{create_rw_signal, RwSignal, SignalGet, SignalGetUntracked, SignalSet, SignalUpdate};
#[cfg(target_arch = "wasm32")]
use monaco::{
api::CodeEditorOptions,
Expand Down Expand Up @@ -111,12 +114,14 @@ pub fn TextEditor(
}

/// Shared reference to the underlying [`CodeEditor`].
#[cfg(target_arch = "wasm32")]
pub type CodeEditorCell = Rc<RefCell<Option<CodeEditor>>>;
#[cfg(target_arch = "wasm32")]
pub type ClosureCell = Rc<RefCell<Option<(Closure<dyn Fn()>, IDisposable)>>>;

#[derive(Copy, Clone, Debug)]
pub struct EditorState {
#[cfg(target_arch = "wasm32")]
pub code_editor: RwSignal<CodeEditorCell>,
#[cfg(target_arch = "wasm32")]
pub update_fn_closure: RwSignal<ClosureCell>,
Expand All @@ -131,12 +136,14 @@ impl Default for EditorState {
impl EditorState {
pub fn new() -> Self {
Self {
#[cfg(target_arch = "wasm32")]
code_editor: create_rw_signal(CodeEditorCell::default()),
#[cfg(target_arch = "wasm32")]
update_fn_closure: create_rw_signal(ClosureCell::default()),
}
}

#[cfg(target_arch = "wasm32")]
pub fn get_value(&self) -> String {
self.code_editor
.get_untracked()
Expand All @@ -148,6 +155,7 @@ impl EditorState {
.unwrap_or_default()
}

#[cfg(target_arch = "wasm32")]
pub fn set_value(&self, value: &str) {
if let Some(text_model) = self
.code_editor
Expand Down

0 comments on commit 8f83ee1

Please sign in to comment.