|
1 | | -use std::{collections::HashMap, fmt::Display, path::PathBuf, sync::Arc}; |
| 1 | +use std::sync::Arc; |
2 | 2 |
|
3 | 3 | use dashmap::DashMap; |
| 4 | +use rolldown_common::{WatcherEvent, WatcherEventData}; |
4 | 5 |
|
5 | 6 | pub type SharedWatcherEmitter = Arc<WatcherEmitter>; |
6 | 7 |
|
7 | | -#[allow(dead_code)] |
8 | | -#[derive(Default, Clone)] |
9 | | -pub struct WatcherEventData(Option<Arc<HashMap<String, String>>>); |
10 | | - |
11 | 8 | pub type Listener = Box<dyn Fn(WatcherEventData) + Send + Sync>; |
12 | 9 |
|
13 | 10 | pub struct WatcherEmitter { |
@@ -41,67 +38,3 @@ impl WatcherEmitter { |
41 | 38 | self.listeners.entry(event).or_default().push(Box::new(listener)); |
42 | 39 | } |
43 | 40 | } |
44 | | - |
45 | | -#[derive(PartialEq, Eq, Hash)] |
46 | | -pub enum WatcherEvent { |
47 | | - Close, |
48 | | - Event, |
49 | | - ReStart, |
50 | | - Change, |
51 | | -} |
52 | | - |
53 | | -pub enum BundleEventKind { |
54 | | - Start, |
55 | | - BundleStart, |
56 | | - BundleEnd, |
57 | | - End, |
58 | | -} |
59 | | - |
60 | | -impl Display for BundleEventKind { |
61 | | - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
62 | | - match self { |
63 | | - BundleEventKind::Start => write!(f, "START"), |
64 | | - BundleEventKind::BundleStart => write!(f, "BUNDLE_START"), |
65 | | - BundleEventKind::BundleEnd => write!(f, "BUNDLE_END"), |
66 | | - BundleEventKind::End => write!(f, "END"), |
67 | | - } |
68 | | - } |
69 | | -} |
70 | | - |
71 | | -impl From<BundleEventKind> for WatcherEventData { |
72 | | - fn from(kind: BundleEventKind) -> Self { |
73 | | - let mut map = HashMap::default(); |
74 | | - map.insert("code".to_string(), kind.to_string()); |
75 | | - Self(Some(Arc::new(map))) |
76 | | - } |
77 | | -} |
78 | | - |
79 | | -pub enum WatcherChangeKind { |
80 | | - Create, |
81 | | - Update, |
82 | | - Delete, |
83 | | -} |
84 | | - |
85 | | -impl Display for WatcherChangeKind { |
86 | | - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
87 | | - match self { |
88 | | - WatcherChangeKind::Create => write!(f, "create"), |
89 | | - WatcherChangeKind::Update => write!(f, "update"), |
90 | | - WatcherChangeKind::Delete => write!(f, "delete"), |
91 | | - } |
92 | | - } |
93 | | -} |
94 | | - |
95 | | -pub struct WatcherChange { |
96 | | - pub path: PathBuf, |
97 | | - pub kind: WatcherChangeKind, |
98 | | -} |
99 | | - |
100 | | -impl From<WatcherChange> for WatcherEventData { |
101 | | - fn from(event: WatcherChange) -> Self { |
102 | | - let mut map = HashMap::default(); |
103 | | - map.insert("id".to_string(), event.path.to_string_lossy().to_string()); |
104 | | - map.insert("kind".to_string(), event.kind.to_string()); |
105 | | - Self(Some(Arc::new(map))) |
106 | | - } |
107 | | -} |
0 commit comments