Skip to content

Commit 75420ec

Browse files
author
Andres Vargas
committed
update livewire
1 parent 8054e25 commit 75420ec

File tree

6 files changed

+90
-15
lines changed

6 files changed

+90
-15
lines changed

.coveragerc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[run]
2+
branch = true
3+
source = .
4+
omit = */tests/*, */migrations/*, */urls.py, */settings/*
5+
*/asgi.py, */wsgi.py, manage.py, fabfile.py, */apps.py, populate.py
6+
7+
[report]
8+
show_missing = true
9+
skip_covered = true

livewire/static/livewire/HookManager.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export default {
99
'messageFailed',
1010
'responseReceived',
1111
'beforeDomUpdate',
12+
'beforeElementUpdate',
13+
'afterElementUpdate',
1214
'afterDomUpdate',
1315
'interceptWireModelSetValue',
1416
'interceptWireModelAttachListener',

livewire/static/livewire/Store.js

+29
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const store = {
2525
return this.componentsById[id]
2626
},
2727

28+
getComponentsByName(name) {
29+
return this.components()
30+
.filter(component => {
31+
return component.name === name
32+
})
33+
},
34+
2835
hasComponent(id) {
2936
return !! this.componentsById[id]
3037
},
@@ -57,6 +64,28 @@ const store = {
5764
)
5865
},
5966

67+
emitSelf(componentId, event, ...params) {
68+
let component = this.findComponent(componentId)
69+
70+
if (component.events.includes(event)) {
71+
component.addAction(new EventAction(
72+
event, params
73+
))
74+
}
75+
},
76+
77+
emitTo(componentName, event, ...params) {
78+
let components = this.getComponentsByName(componentName)
79+
80+
components.forEach(component => {
81+
if (component.events.includes(event)) {
82+
component.addAction(new EventAction(
83+
event, params
84+
))
85+
}
86+
})
87+
},
88+
6089
componentsListeningForEventThatAreTreeAncestors(el, event) {
6190
var parentIds = []
6291

livewire/static/livewire/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
import '@/dom/polyfills/index';
12
import componentStore from '@/Store'
23
import DOM from "@/dom/dom";
34
import Component from "@/component/index";
45
import Connection from '@/connection'
56
import drivers from '@/connection/drivers'
6-
import '@/dom/polyfills/index';
77
import { dispatch } from './util';
8+
import FileUploads from '@/component/FileUploads'
89
import LoadingStates from '@/component/LoadingStates'
910
import DisableForms from '@/component/DisableForms'
1011
import DirtyStates from '@/component/DirtyStates'
1112
import OfflineStates from '@/component/OfflineStates'
1213
import Polling from '@/component/Polling'
1314
import UpdateQueryString from '@/component/UpdateQueryString'
14-
import SupportVueJs from '@/component/SupportVueJs'
1515

1616
class Livewire {
1717
constructor(options = {}) {
@@ -50,6 +50,10 @@ class Livewire {
5050
this.components.emit(event, ...params)
5151
}
5252

53+
emitTo(name, event, ...params) {
54+
this.components.emitTo(name, event, ...params)
55+
}
56+
5357
on(event, callback) {
5458
this.components.on(event, callback)
5559
}
@@ -73,10 +77,6 @@ class Livewire {
7377
this.onLoadCallback()
7478
dispatch('livewire:load')
7579

76-
window.addEventListener('beforeunload', () => {
77-
this.components.tearDownComponents()
78-
})
79-
8080
document.addEventListener('visibilitychange', () => {
8181
this.components.livewireIsInBackground = document.hidden
8282
}, false);
@@ -103,11 +103,11 @@ if (! window.Livewire) {
103103
}
104104

105105
UpdateQueryString()
106-
SupportVueJs()
106+
OfflineStates()
107107
LoadingStates()
108108
DisableForms()
109+
FileUploads()
109110
DirtyStates()
110-
OfflineStates()
111111
Polling()
112112

113113
dispatch('livewire:available')

livewire/static/livewire/node_initializer.js

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { kebabCase } from '@/util'
1+
import { kebabCase, debounce } from '@/util'
22
import ModelAction from '@/action/model'
33
import MethodAction from '@/action/method'
44
import DOMElement from '@/dom/dom_element'
@@ -50,16 +50,20 @@ export default {
5050

5151
store.callHook('interceptWireModelAttachListener', el, directive, component, debounceIf)
5252

53+
// File uploads are handled by UploadFiles.js.
54+
if (el.rawNode().tagName.toLowerCase() === 'input' && el.rawNode().type === 'file') return
55+
5356
const event = (el.rawNode().tagName.toLowerCase() === 'select')
5457
|| ['checkbox', 'radio'].includes(el.rawNode().type)
5558
|| directive.modifiers.includes('lazy')
5659
? 'change' : 'input'
5760

5861
// If it's a text input and not .lazy, debounce, otherwise fire immediately.
59-
const handler = debounceIf(hasDebounceModifier || (el.isTextInput() && ! isLazy), e => {
62+
let handler = debounceIf(hasDebounceModifier || (el.isTextInput() && ! isLazy), e => {
6063
const model = directive.value
6164
const el = new DOMElement(e.target)
62-
const value = e instanceof CustomEvent
65+
// We have to check for typeof e.detail here for IE 11.
66+
const value = e instanceof CustomEvent && typeof e.detail != 'undefined'
6367
? e.detail
6468
: el.valueFromInput(component)
6569

@@ -93,9 +97,15 @@ export default {
9397
if (selectedButNotPressedKeyModifiers.length > 0) return false;
9498
}
9599

100+
// Strip 'debounce' modifier and time modifiers from modifiers list
101+
let modifiers = directive.modifiers.filter(modifier => {
102+
return ! modifier.match(/debounce/)
103+
&& ! modifier.match(/[0-9ms]/)
104+
&& ! modifier.match(/[0-9s]/)
105+
})
106+
96107
// Only handle listener if no, or matching key modifiers are passed.
97-
return (directive.modifiers.length === 0
98-
|| directive.modifiers.includes(kebabCase(e.key)))
108+
return modifiers.length === 0 || modifiers.includes(kebabCase(e.key))
99109
})
100110
break;
101111
case 'click':
@@ -155,16 +165,35 @@ export default {
155165
return
156166
}
157167

168+
if (method === '$emitSelf') {
169+
store.emitSelf(component.id, ...params)
170+
return
171+
}
172+
173+
if (method === '$emitTo') {
174+
store.emitTo(...params)
175+
return
176+
}
177+
158178
if (directive.value) {
159179
component.addAction(new MethodAction(method, params, el))
160180
}
161181
})
162182
}
163183

164-
el.addEventListener(event, handler)
184+
const debounceIf = (condition, callback, time) => {
185+
return condition
186+
? debounce(callback, time)
187+
: callback
188+
}
189+
190+
const hasDebounceModifier = directive.modifiers.includes('debounce')
191+
const debouncedHandler = debounceIf(hasDebounceModifier, handler, directive.durationOr(150))
192+
193+
el.addEventListener(event, debouncedHandler)
165194

166195
component.addListenerForTeardown(() => {
167-
el.removeEventListener(event, handler)
196+
el.removeEventListener(event, debouncedHandler)
168197
})
169198
},
170199

updatelivewire.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set -x
2+
TMPDIR=$(mktemp -d )
3+
wget https://github.com/livewire/livewire/archive/master.zip -O $TMPDIR/master.zip
4+
5+
7z x $TMPDIR/master.zip -o$TMPDIR
6+
cp $TMPDIR/livewire-master/js/* livewire/static/livewire/

0 commit comments

Comments
 (0)