# packages/core/src/lib/transitions/binding.ts
This is the source snapshot used to build these API details. [View this revision on GitHub](https://github.com/benlesh/pibbl/blob/272a94aaf62e0bd6ad8726a4c607a76a9ec44ca1/packages/core/src/lib/transitions/binding.ts#L13).

[Back to reference](/reference/hooks/use-visibility-transition/)

<pre class="api-source"><code><span id="L1"><a href="#L1" aria-label="Line 1">1</a> import type { PibblVisibilityTransition } from '../hooks/use-visibility-transition.js';</span>
<span id="L2"><a href="#L2" aria-label="Line 2">2</a> import { GLOBAL_STATE } from '../global-state.js';</span>
<span id="L3"><a href="#L3" aria-label="Line 3">3</a> import { requireHookContext } from '../hooks/hook-slot.js';</span>
<span id="L4"><a href="#L4" aria-label="Line 4">4</a> import type { PibblComponentRefs, PibblEventRoot, PibblInstance } from '../types.js';</span>
<span id="L5"><a href="#L5" aria-label="Line 5">5</a> import type { PibblFilter } from '../style/filter-types.js';</span>
<span id="L6"><a href="#L6" aria-label="Line 6">6</a> </span>
<span id="L7"><a href="#L7" aria-label="Line 7">7</a> declare const bindingBrand: unique symbol;</span>
<span id="L8"><a href="#L8" aria-label="Line 8">8</a> /**</span>
<span id="L9"><a href="#L9" aria-label="Line 9">9</a>  * An opaque connection between one transition controller and its painted subject.</span>
<span id="L10"><a href="#L10" aria-label="Line 10">10</a>  *</span>
<span id="L11"><a href="#L11" aria-label="Line 11">11</a>  * @see {@link PibblVisibilityTransition}</span>
<span id="L12"><a href="#L12" aria-label="Line 12">12</a>  */</span>
<span id="L13"><a href="#L13" aria-label="Line 13">13</a> export interface PibblTransitionBinding { readonly [bindingBrand]: true }</span>
<span id="L14"><a href="#L14" aria-label="Line 14">14</a> interface BindingRecord {</span>
<span id="L15"><a href="#L15" aria-label="Line 15">15</a>   readonly resolve: () =&gt; readonly PibblFilter[];</span>
<span id="L16"><a href="#L16" aria-label="Line 16">16</a>   readonly root: PibblEventRoot;</span>
<span id="L17"><a href="#L17" aria-label="Line 17">17</a>   readonly owner: PibblComponentRefs&lt;any&gt;;</span>
<span id="L18"><a href="#L18" aria-label="Line 18">18</a>   receiver?: PibblComponentRefs&lt;any&gt;;</span>
<span id="L19"><a href="#L19" aria-label="Line 19">19</a>   receiverInstance?: PibblInstance;</span>
<span id="L20"><a href="#L20" aria-label="Line 20">20</a> }</span>
<span id="L21"><a href="#L21" aria-label="Line 21">21</a> const bindings = new WeakMap&lt;PibblTransitionBinding, BindingRecord&gt;();</span>
<span id="L22"><a href="#L22" aria-label="Line 22">22</a> export function createTransitionBinding(resolve: () =&gt; readonly PibblFilter[]): PibblTransitionBinding {</span>
<span id="L23"><a href="#L23" aria-label="Line 23">23</a>   const binding = Object.freeze({}) as PibblTransitionBinding;</span>
<span id="L24"><a href="#L24" aria-label="Line 24">24</a>   const { componentRefs, pibblInstance } = requireHookContext();</span>
<span id="L25"><a href="#L25" aria-label="Line 25">25</a>   bindings.set(binding, { resolve, owner: componentRefs, root: pibblInstance.eventRoot });</span>
<span id="L26"><a href="#L26" aria-label="Line 26">26</a>   return binding;</span>
<span id="L27"><a href="#L27" aria-label="Line 27">27</a> }</span>
<span id="L28"><a href="#L28" aria-label="Line 28">28</a> export function resolveTransitionBinding(binding: PibblTransitionBinding): readonly PibblFilter[] {</span>
<span id="L29"><a href="#L29" aria-label="Line 29">29</a>   const record = bindings.get(binding);</span>
<span id="L30"><a href="#L30" aria-label="Line 30">30</a>   if (!record) throw new TypeError('style.transition requires a binding from useVisibilityTransition in the same Pibbl runtime.');</span>
<span id="L31"><a href="#L31" aria-label="Line 31">31</a>   const receiver = GLOBAL_STATE.componentRefs;</span>
<span id="L32"><a href="#L32" aria-label="Line 32">32</a>   if (GLOBAL_STATE.currentPibblInstance?.eventRoot !== record.root) throw new Error('A transition binding must stay within its owning Pibbl root.');</span>
<span id="L33"><a href="#L33" aria-label="Line 33">33</a>   if (record.owner.teardowns.closed) throw new Error('Cannot use a disposed transition binding.');</span>
<span id="L34"><a href="#L34" aria-label="Line 34">34</a>   if (!receiver) throw new Error('Transition bindings require a mounted receiver.');</span>
<span id="L35"><a href="#L35" aria-label="Line 35">35</a>   const instance = GLOBAL_STATE.currentPibblInstance!;</span>
<span id="L36"><a href="#L36" aria-label="Line 36">36</a>   // Keyed replacements are visited before the old receiver is torn down. Only</span>
<span id="L37"><a href="#L37" aria-label="Line 37">37</a>   // retire an unseen receiver in this same render instance; cached Layers own</span>
<span id="L38"><a href="#L38" aria-label="Line 38">38</a>   // independent generations and must not silently lose their binding.</span>
<span id="L39"><a href="#L39" aria-label="Line 39">39</a>   if (record.receiver &amp;&amp; record.receiver !== receiver &amp;&amp; record.receiverInstance === instance &amp;&amp; record.receiver.renderGeneration !== instance.renderGeneration) {</span>
<span id="L40"><a href="#L40" aria-label="Line 40">40</a>     record.receiver = undefined;</span>
<span id="L41"><a href="#L41" aria-label="Line 41">41</a>   }</span>
<span id="L42"><a href="#L42" aria-label="Line 42">42</a>   if (record.receiver &amp;&amp; record.receiver !== receiver) throw new Error('A transition binding supports one mounted receiver. Wrap shared content in a Group.');</span>
<span id="L43"><a href="#L43" aria-label="Line 43">43</a>   if (!record.receiver) {</span>
<span id="L44"><a href="#L44" aria-label="Line 44">44</a>     record.receiver = receiver;</span>
<span id="L45"><a href="#L45" aria-label="Line 45">45</a>     record.receiverInstance = instance;</span>
<span id="L46"><a href="#L46" aria-label="Line 46">46</a>     receiver.teardowns.add(() =&gt; { if (record.receiver === receiver) record.receiver = undefined; });</span>
<span id="L47"><a href="#L47" aria-label="Line 47">47</a>   }</span>
<span id="L48"><a href="#L48" aria-label="Line 48">48</a>   return record.resolve();</span>
<span id="L49"><a href="#L49" aria-label="Line 49">49</a> }</span>
<span id="L50"><a href="#L50" aria-label="Line 50">50</a> </span></code></pre>

## Documentation version

Documentation built with @pibbl/core 0.0.2, revision 272a94a. ALPHA — NOT FOR PRODUCTION USE.
