|
@@ -9,16 +9,6 @@ magic('model', (el, { cleanup }) => {
|
|
|
|
|
|
let func = generateModelAccessor(el, cleanup)
|
|
let func = generateModelAccessor(el, cleanup)
|
|
|
|
|
|
- Object.defineProperty(func, 'closest', { get() {
|
|
|
|
- let func = generateModelAccessor(el.parentElement, cleanup)
|
|
|
|
-
|
|
|
|
- func._x_modelAccessor = true
|
|
|
|
-
|
|
|
|
- return accessor(func)
|
|
|
|
- }, })
|
|
|
|
-
|
|
|
|
- func._x_modelAccessor = true
|
|
|
|
-
|
|
|
|
return accessor(func)
|
|
return accessor(func)
|
|
})
|
|
})
|
|
|
|
|
|
@@ -28,6 +18,8 @@ function generateModelAccessor(el, cleanup) {
|
|
if (i._x_model) return true
|
|
if (i._x_model) return true
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+ closestModelEl && destroyModelListeners(closestModelEl)
|
|
|
|
+
|
|
// Instead of simply returning the get/set object, we'll create a wrapping function
|
|
// Instead of simply returning the get/set object, we'll create a wrapping function
|
|
// so that we have the option to add additional APIs without breaking anything...
|
|
// so that we have the option to add additional APIs without breaking anything...
|
|
let accessor = function (fallbackStateInitialValue) {
|
|
let accessor = function (fallbackStateInitialValue) {
|
|
@@ -63,19 +55,11 @@ function generateModelAccessor(el, cleanup) {
|
|
return accessor
|
|
return accessor
|
|
}
|
|
}
|
|
|
|
|
|
-let isInsideXData = false
|
|
|
|
-
|
|
|
|
-export function eagerlyRunXModelIfMagicModelIsUsedInsideThisExpression(callback) {
|
|
|
|
- isInsideXData = true
|
|
|
|
-
|
|
|
|
- callback()
|
|
|
|
-
|
|
|
|
- isInsideXData = false
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
function eagerlyRunXModelIfNeeded(el) {
|
|
function eagerlyRunXModelIfNeeded(el) {
|
|
- if (! isInsideXData) return
|
|
|
|
|
|
+ // Looks like x-model has already been run so we're good...
|
|
|
|
+ if (el._x_model) return
|
|
|
|
|
|
|
|
+ // We only care to run x-model on elements WITH x-model...
|
|
if (! el.hasAttribute('x-model')) return
|
|
if (! el.hasAttribute('x-model')) return
|
|
|
|
|
|
let attribute = { name: 'x-model', value: el.getAttribute('x-model') }
|
|
let attribute = { name: 'x-model', value: el.getAttribute('x-model') }
|
|
@@ -84,3 +68,19 @@ function eagerlyRunXModelIfNeeded(el) {
|
|
handle()
|
|
handle()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+function destroyModelListeners(modelEl) {
|
|
|
|
+ if (! modelEl._x_removeModelListeners) return
|
|
|
|
+
|
|
|
|
+ if (isInputyElement(modelEl)) return
|
|
|
|
+
|
|
|
|
+ modelEl._x_removeModelListeners['default']()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function isInputyElement(el) {
|
|
|
|
+ let tag = el.tagName.toLowerCase()
|
|
|
|
+
|
|
|
|
+ inputTags = ['input', 'textarea', 'select']
|
|
|
|
+
|
|
|
|
+ return inputTags.includes(tag)
|
|
|
|
+}
|