|
|
|
@ -50,7 +50,7 @@ bitflags! {
|
|
|
|
|
/// Emmit delete events.
|
|
|
|
|
const DELETE = 1<<2;
|
|
|
|
|
|
|
|
|
|
/// Propagate events from children of `Map` datas
|
|
|
|
|
/// Propagate events from children of `Map` or `List` datas
|
|
|
|
|
const CHILD = 1<<3;
|
|
|
|
|
|
|
|
|
|
/// Poke events are opaque events that are fired manually.
|
|
|
|
@ -68,28 +68,45 @@ impl Default for HookMask
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id_type!(pub HookID: "The ID of a hook, passed with the event when the hook is fired");
|
|
|
|
|
|
|
|
|
|
/// Fire events when something happens to this value.
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct Hooks
|
|
|
|
|
{
|
|
|
|
|
filter: HookMask,
|
|
|
|
|
id: HookID,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for Hooks
|
|
|
|
|
{
|
|
|
|
|
#[inline]
|
|
|
|
|
fn default() -> Self
|
|
|
|
|
{
|
|
|
|
|
Self {
|
|
|
|
|
id: HookID::id_new(), // generate an id now, in case hooks are added later
|
|
|
|
|
filter: Default::default(), //default is to emit nothing ever
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// An event emitted from a matched `Hook`.
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
|
|
|
|
pub enum HookEvent
|
|
|
|
|
pub enum HookEventKind
|
|
|
|
|
{
|
|
|
|
|
/// An opaque event type
|
|
|
|
|
/// An opaque event type that can only be fired manually.
|
|
|
|
|
Poke,
|
|
|
|
|
|
|
|
|
|
Read,
|
|
|
|
|
Write,
|
|
|
|
|
Delete,
|
|
|
|
|
/// An event propagated from a child of this element.
|
|
|
|
|
///
|
|
|
|
|
/// This only can happen with `Map` or `List` data kinds.
|
|
|
|
|
Child(Box<HookEvent>),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for HookEvent
|
|
|
|
|
impl Default for HookEventKind
|
|
|
|
|
{
|
|
|
|
|
#[inline]
|
|
|
|
|
fn default() -> Self
|
|
|
|
@ -98,3 +115,11 @@ impl Default for HookEvent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// An event emitted from a element value's `Hooks` object.
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
|
|
|
|
pub struct HookEvent
|
|
|
|
|
{
|
|
|
|
|
kind: HookEventKind,
|
|
|
|
|
/// Corresponds to the `id` field of the `Hooks` object this event was emitted from.
|
|
|
|
|
id: HookID,
|
|
|
|
|
}
|
|
|
|
|