On this page

Config meld hooks๏ƒ

๐ŸŸก Intermediate ยท Lesson 32

SpellbookConfiguration hooks, family 1: the MELD PIPELINE. add_hook(spellbook_id, name, fn) registers callbacks keyed to a BOOK - the configuration can serve many books, so hooks say whose melds they watch. Two hook points: on_meld_pre_resolve - before resolution on_meld_post_resolve - after the instance is handed back Hooks observe; they do not replace resolution.

Before you run๏ƒ

Use the Intermediate guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.

Run the saved script๏ƒ

python UX_and_AIX_experiences/02_intermediate/32_config_meld_hooks.py
py -3.14t UX_and_AIX_experiences/02_intermediate/32_config_meld_hooks.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

add_hook, on_meld_pre_resolve, on_meld_post_resolve

Code๏ƒ

 1"""
 2TIER: intermediate (32)
 3GOAL: SpellbookConfiguration hooks, family 1: the MELD PIPELINE.
 4      add_hook(spellbook_id, name, fn) registers callbacks keyed to a
 5      BOOK - the configuration can serve many books, so hooks say whose
 6      melds they watch. Two hook points:
 7        on_meld_pre_resolve  - before resolution
 8        on_meld_post_resolve - after the instance is handed back
 9      Hooks observe; they do not replace resolution.
10SURFACE EXERCISED: add_hook, on_meld_pre_resolve, on_meld_post_resolve
11"""
12import melder as md
13
14
15class Watched:
16    pass
17
18
19def main() -> None:
20    events = []
21
22    book = md.Spellbook()
23    config = book.get_configuration()
24    config.add_hook(book.id, "on_meld_pre_resolve",
25                    lambda *a, **k: events.append("pre"))
26    config.add_hook(book.id, "on_meld_post_resolve",
27                    lambda *a, **k: events.append("post"))
28
29    book.bind(spell=Watched, existence="many")
30    conduit = book.conjure()
31
32    conduit.meld(spell=Watched)
33    conduit.meld(spell=Watched)
34    print("meld pipeline observed:", events)
35    assert events.count("pre") >= 2 and events.count("post") >= 2
36    print("every meld fired pre and post - the pipeline is watchable")
37
38
39if __name__ == "__main__":
40    main()

Check the outcome๏ƒ

The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.

More intermediate examples ยท Level guide