On this page

Observe registration and runtime lifecycles๏ƒ

Prerequisite: configuration. Hooks attach observation to a book or registration so call sites can keep using ordinary meld and lifecycle verbs.

Pick the boundary you need๏ƒ

Boundary

Registration surface

Saved demonstration

Spell creation

SpellBinder.with_pre_hook, with_activation_hook, with_post_hook

Record construction events

Meld

configuration.add_hook(book.id, name, callback)

Observe pre/post resolution

Conduit

The same book-keyed hook registration

Observe creation and cleanup

Links and contracts

The same book-keyed hook registration

Observe linking, pull, and sever

The book ID matters when a configuration serves several books. Register the callbacks before the lifecycle operation you intend to observe. The runnable examples collect events in memory so you can inspect what actually fired.

Keep the result separate from the observation๏ƒ

A hook records a moment in a lifecycle. The meld still supplies the resolved object. Use the meld-hook lesson's repeated resolutions and event counts as a small working pattern; use the conduit lesson when cleanup observation matters.

For the dynamic arc, read linking before the link-hook lesson. The latter observes the same owner/borrower operations; it adds no alternative sharing procedure.

The workflow in code๏ƒ

These are the core steps from the saved example. Use its complete linked script for all class definitions and setup.

 1def main() -> None:
 2    events = []
 3
 4    book = md.Spellbook()
 5    config = book.get_configuration()
 6    config.add_hook(book.id, "on_meld_pre_resolve",
 7                    lambda *a, **k: events.append("pre"))
 8    config.add_hook(book.id, "on_meld_post_resolve",
 9                    lambda *a, **k: events.append("post"))
10
11    book.bind(spell=Watched, existence="many")
12    conduit = book.conjure()
13
14    conduit.meld(spell=Watched)
15    conduit.meld(spell=Watched)
16    print("meld pipeline observed:", events)
17    assert events.count("pre") >= 2 and events.count("post") >= 2
18    print("every meld fired pre and post - the pipeline is watchable")

Runnable examples๏ƒ

All intermediate examples ยท Level contents ยท Full contents

Canonical page source