first commit
This commit is contained in:
16
public/assets/alpinejs/src/directives/x-ref.js
Normal file
16
public/assets/alpinejs/src/directives/x-ref.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { closestRoot } from '../lifecycle'
|
||||
import { directive } from '../directives'
|
||||
|
||||
function handler () {}
|
||||
|
||||
handler.inline = (el, { expression }, { cleanup }) => {
|
||||
let root = closestRoot(el)
|
||||
|
||||
if (! root._x_refs) root._x_refs = {}
|
||||
|
||||
root._x_refs[expression] = el
|
||||
|
||||
cleanup(() => delete root._x_refs[expression])
|
||||
}
|
||||
|
||||
directive('ref', handler)
|
||||
Reference in New Issue
Block a user