ソースを参照

Expose a hook for added attributes

Caleb Porzio 1 年間 前
コミット
98a0fff15a
2 ファイル変更9 行追加2 行削除
  1. 2 1
      packages/alpinejs/src/alpine.js
  2. 7 1
      packages/alpinejs/src/binds.js

+ 2 - 1
packages/alpinejs/src/alpine.js

@@ -1,7 +1,7 @@
 import { setReactivityEngine, disableEffectScheduling, reactive, effect, release, raw } from './reactivity'
 import { mapAttributes, directive, setPrefix as prefix, prefix as prefixed } from './directives'
 import { start, addRootSelector, addInitSelector, closestRoot, findClosest, initTree, destroyTree, interceptInit } from './lifecycle'
-import { onElRemoved, onAttributeRemoved, mutateDom, deferMutations, flushAndStopDeferringMutations, startObservingMutations, stopObservingMutations } from './mutation'
+import { onElRemoved, onAttributeRemoved, onAttributesAdded, mutateDom, deferMutations, flushAndStopDeferringMutations, startObservingMutations, stopObservingMutations } from './mutation'
 import { mergeProxies, closestDataStack, addScopeToNode, scope as $data } from './scope'
 import { setEvaluator, evaluate, evaluateLater, dontAutoEvaluateFunctions } from './evaluator'
 import { transition } from './directives/x-transition'
@@ -33,6 +33,7 @@ let Alpine = {
     stopObservingMutations,
     setReactivityEngine,
     onAttributeRemoved,
+    onAttributesAdded,
     closestDataStack,
     skipDuringClone,
     onlyDuringClone,

+ 7 - 1
packages/alpinejs/src/binds.js

@@ -6,10 +6,12 @@ export function bind(name, bindings) {
     let getBindings = typeof bindings !== 'function' ? () => bindings : bindings
 
     if (name instanceof Element) {
-        applyBindingsObject(name, getBindings())
+        return applyBindingsObject(name, getBindings())
     } else {
         binds[name] = getBindings
     }
+
+    return () => {} // Null cleanup...
 }
 
 export function injectBindingProviders(obj) {
@@ -58,4 +60,8 @@ export function applyBindingsObject(el, obj, original) {
 
         handle()
     })
+
+    return () => {
+        while (cleanupRunners.length) cleanupRunners.pop()()
+    }
 }