# RFC: Hooks.jl

**URL:** <https://discourse.julialang.org/t/rfc-hooks-jl/22158>\
**Category:** General Usage\
**Created:** [March 21, 2019, 6:11pm UTC](https://discourse.julialang.org/t/rfc-hooks-jl/22158 "2019-03-21T18:11:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [March 21, 2019, 6:11pm UTC](https://discourse.julialang.org/t/rfc-hooks-jl/22158/1 "2019-03-21T18:11:16Z")

</div>

Sometimes one package wants to do something when an event happens in another package, but they don’t necessarily want to introduce a dependency. I threw together [Hooks.jl](https://github.com/ssfrr/Hooks.jl) to make this easy.

For example, say Atom.jl wants to be able to notify other packages when it’s loaded, so it might have:

```julia
# Atom.jl
function __init__ ()
    # some initialization code
    notify(hook"atom-initialized")
end

```

Then some other package can take some action

```julia
function __init__ ()
    handle(hook"atom-initialized") do
        # this is from Revise.jl
        setup_atom(getfield(Main, :Atom)::Module)
    end
end

```

Now this initialization will happen regardless of which order Atom and the OtherPkg are loaded in.

Good idea? Terrible idea?

@tim.holy @pfitzseb

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 21, 2019, 7:19pm UTC](https://discourse.julialang.org/t/rfc-hooks-jl/22158/2 "2019-03-21T19:19:55Z")

</div>

It does seem like it could be useful to have a lightweight package for communication between packages. Interesting, I’ll keep it in mind.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [March 21, 2019, 7:24pm UTC](https://discourse.julialang.org/t/rfc-hooks-jl/22158/3 "2019-03-21T19:24:10Z")

</div>

Packages are no longer automatically loaded into Main anymore. I imagine there’s still some sort of way of getting at the module, but I don’t know what it is. What you have now won’t necessarily work, though.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 21, 2019, 7:31pm UTC](https://discourse.julialang.org/t/rfc-hooks-jl/22158/4 "2019-03-21T19:31:11Z")

</div>

`Base.loaded_modules` is your friend. You can iterate and match on UUID.

EDIT: or easier

```julia
julia> Main.Markdown
ERROR: UndefVarError: Markdown not defined

julia> Base.root_module(Main, :Markdown)
Markdown

```
