1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
use_prelude!();
#[derive(Debug)]
/// Provides information about the changes that have occurred in relation to an event delivered when
/// observing the collections in a `DittoStore`. It contains information about the collections that
/// are known about as well as the collections that were previously known about in the previous
/// event, along with information about what collections have been inserted, deleted, updated, or
/// moved since the last event.
pub struct CollectionsEvent {
pub is_initial: bool,
pub collections: Vec<Collection>,
pub old_collections: Vec<Collection>,
pub insertions: Box<[usize]>,
pub deletions: Box<[usize]>,
pub updates: Box<[usize]>,
pub moves: Vec<LiveQueryMove>,
}
impl CollectionsEvent {
/// Create a new CollectionsEvent in initial state.
pub fn initial(collections: Vec<Collection>) -> Self {
CollectionsEvent {
is_initial: true,
collections,
old_collections: vec![],
insertions: vec![].into(),
deletions: vec![].into(),
updates: vec![].into(),
moves: vec![],
}
}
/// Update a CollectionsEvent with provided data.
pub fn update(
collections: Vec<Collection>,
old_collections: Vec<Collection>,
insertions: Box<[usize]>,
deletions: Box<[usize]>,
updates: Box<[usize]>,
moves: Vec<LiveQueryMove>,
) -> Self {
CollectionsEvent {
is_initial: false,
collections,
old_collections,
insertions,
deletions,
updates,
moves,
}
}
}