浏览代码

Make "el" not return a proxy

Caleb Porzio 5 年之前
父节点
当前提交
123e6ae2d4
共有 6 个文件被更改,包括 24 次插入2 次删除
  1. 1 1
      README.md
  2. 0 0
      dist/alpine.js
  3. 0 0
      dist/alpine.js.map
  4. 1 1
      package.json
  5. 3 0
      src/component.js
  6. 19 0
      test/el.spec.js

+ 1 - 1
README.md

@@ -14,7 +14,7 @@ Think of it like [Tailwind](https://tailwindcss.com/) for JavaScript.
 
 **From CDN:** Add the following script to the end of your `<head>` section.
 ```html
-<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v1.6.0/dist/alpine.js" defer></script>
+<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v1.6.1/dist/alpine.js" defer></script>
 ```
 
 That's it. It will initialize itself.

文件差异内容过多而无法显示
+ 0 - 0
dist/alpine.js


文件差异内容过多而无法显示
+ 0 - 0
dist/alpine.js.map


+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
   "main": "dist/alpine.js",
   "name": "alpinejs",
-  "version": "1.6.0",
+  "version": "1.6.1",
   "repository": {
     "type": "git",
     "url": "git://github.com/alpinejs/alpine.git"

+ 3 - 0
src/component.js

@@ -86,6 +86,9 @@ export default class Component {
                 // Like in the case of $refs
                 if (target[key] && target[key].isProxy) return target[key]
 
+                // If property is a DOM node, just return it. (like in the case of this.$el)
+                if (target[key] && target[key] instanceof Node) return target[key]
+
                 // If accessing a nested property, retur this proxy recursively.
                 if (typeof target[key] === 'object' && target[key] !== null) {
                     const propertyName = keyPrefix ? `${keyPrefix}.${key}` : key

+ 19 - 0
test/el.spec.js

@@ -20,3 +20,22 @@ test('$el', async () => {
 
     await wait(() => { expect(document.querySelector('div').innerHTML).toEqual('foo') })
 })
+
+test('$el doesnt return a proxy', async () => {
+    var isProxy
+    window.setIsProxy = function (el) {
+        isProxy = !! el.isProxy
+    }
+
+    document.body.innerHTML = `
+        <div x-data>
+            <button @click="setIsProxy($el)"></button>
+        </div>
+    `
+
+    Alpine.start()
+
+    document.querySelector('button').click()
+
+    expect(isProxy).toEqual(false)
+})

部分文件因为文件数量过多而无法显示