Browse Source

Merge pull request #65 from keyurshah/allow-colons-in-event-name

allow colons in event names
Caleb Porzio 5 years ago
parent
commit
b809c39732
4 changed files with 22 additions and 1 deletions
  1. 0 0
      dist/alpine.js
  2. 0 0
      dist/alpine.js.map
  3. 1 1
      src/utils.js
  4. 21 0
      test/on.spec.js

File diff suppressed because it is too large
+ 0 - 0
dist/alpine.js


File diff suppressed because it is too large
+ 0 - 0
dist/alpine.js.map


+ 1 - 1
src/utils.js

@@ -80,7 +80,7 @@ export function getXAttrs(el, type) {
             const name = replaceAtAndColonWithStandardSyntax(attr.name)
             const name = replaceAtAndColonWithStandardSyntax(attr.name)
 
 
             const typeMatch = name.match(/x-(on|bind|data|text|html|model|if|show|cloak|transition|ref)/)
             const typeMatch = name.match(/x-(on|bind|data|text|html|model|if|show|cloak|transition|ref)/)
-            const valueMatch = name.match(/:([a-zA-Z\-]+)/)
+            const valueMatch = name.match(/:([a-zA-Z\-:]+)/)
             const modifiers = name.match(/\.[^.\]]+(?=[^\]]*$)/g) || []
             const modifiers = name.match(/\.[^.\]]+(?=[^\]]*$)/g) || []
 
 
             return {
             return {

+ 21 - 0
test/on.spec.js

@@ -223,3 +223,24 @@ test('supports short syntax', async () => {
 
 
     await wait(() => { expect(document.querySelector('span').getAttribute('foo')).toEqual('baz') })
     await wait(() => { expect(document.querySelector('span').getAttribute('foo')).toEqual('baz') })
 })
 })
+
+
+test('event with colon', async () => {
+    document.body.innerHTML = `
+        <div x-data="{ foo: 'bar' }">
+            <div x-on:my:event.document="foo = 'baz'"></div>
+
+            <span x-bind:foo="foo"></span>
+        </div>
+    `
+
+    Alpine.start()
+
+    expect(document.querySelector('span').getAttribute('foo')).toEqual('bar')
+
+    var event = new CustomEvent('my:event');
+
+    document.dispatchEvent(event);
+
+    await wait(() => { expect(document.querySelector('span').getAttribute('foo')).toEqual('baz') })
+})

Some files were not shown because too many files changed in this diff