Skip to content

Commit fffaf45

Browse files
authored
feat: add JSONPath subscription (#883)
* feat: jsonpath subscribe * fix: add comments and optimize the algorithm * chore: changeset * refactor: simplify the code
1 parent 2800a4c commit fffaf45

File tree

17 files changed

+767
-110
lines changed

17 files changed

+767
-110
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"loro-crdt": patch
3+
"loro-crdt-map": patch
4+
---
5+
6+
feat: add JSONPath subscription #883

crates/loro-internal/examples/event.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::sync::Arc;
22

33
use loro_internal::{
4+
cursor::PosType,
45
event::Diff,
56
handler::{Handler, ValueOrHandler},
6-
cursor::PosType, ListHandler, LoroDoc, MapHandler, TextHandler, ToJson, TreeHandler,
7+
ListHandler, LoroDoc, MapHandler, TextHandler, ToJson, TreeHandler,
78
};
89

910
fn main() {

crates/loro-internal/src/container/richtext/richtext_state.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,11 +1302,7 @@ impl RichtextState {
13021302
.unwrap_or(false)
13031303
}
13041304

1305-
pub(crate) fn range_has_style_key(
1306-
&mut self,
1307-
range: Range<usize>,
1308-
key: &StyleKey,
1309-
) -> bool {
1305+
pub(crate) fn range_has_style_key(&mut self, range: Range<usize>, key: &StyleKey) -> bool {
13101306
self.check_cache();
13111307
let result = match self.style_ranges.as_ref() {
13121308
Some(s) => s.range_contains_key(range, key),

crates/loro-internal/src/cursor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ pub enum PosType {
9494
Event,
9595
/// The index is based on the entity index.
9696
Entity,
97-
}
97+
}

crates/loro-internal/src/jsonpath/ast.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use crate::jsonpath::errors::JSONPathError;
22
use crate::jsonpath::JSONPathParser;
33
use std::fmt::{self, Write};
44

5-
#[derive(Debug)]
5+
#[derive(Debug, Clone)]
66
pub struct Query {
77
pub segments: Segment,
88
}
99

10-
#[derive(Debug)]
10+
#[derive(Debug, Clone)]
1111
pub enum Segment {
1212
Root {},
1313
Child {
@@ -20,7 +20,7 @@ pub enum Segment {
2020
},
2121
}
2222

23-
#[derive(Debug)]
23+
#[derive(Debug, Clone)]
2424
pub enum Selector {
2525
Name {
2626
name: String,
@@ -39,7 +39,7 @@ pub enum Selector {
3939
},
4040
}
4141

42-
#[derive(Debug)]
42+
#[derive(Debug, Clone)]
4343
pub enum FilterExpression {
4444
True_ {},
4545
False_ {},
@@ -81,13 +81,13 @@ pub enum FilterExpression {
8181
},
8282
}
8383

84-
#[derive(Debug)]
84+
#[derive(Debug, Clone)]
8585
pub enum LogicalOperator {
8686
And,
8787
Or,
8888
}
8989

90-
#[derive(Debug)]
90+
#[derive(Debug, Clone)]
9191
pub enum ComparisonOperator {
9292
Eq,
9393
Ne,

crates/loro-internal/src/jsonpath/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
pub mod ast;
22
pub mod errors;
33
pub mod jsonpath_impl;
4+
pub mod subscription;
5+
6+
pub use subscription::SubscribeJsonPathCallback;
47
pub mod parser;
58

69
pub use ast::Query;

0 commit comments

Comments
 (0)