Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 77615d8

Browse files
committed
refactor livewire 2
1 parent def6df8 commit 77615d8

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/preload/index.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,37 @@ ipcRenderer.on('native-event', (event, data) => {
2424
window.Livewire.dispatch('nativephp:' + data.event, data.payload);
2525
}
2626

27+
// add support for livewire 2
2728
// @ts-ignore
28-
if (!window.livewire) {
29-
return;
30-
}
31-
// @ts-ignore
32-
window.livewire.components.components().forEach(component => {
33-
if (Array.isArray(component.listeners)) {
34-
component.listeners.forEach(event => {
35-
if (event.startsWith('native')) {
36-
let event_parts = event.split(/(native:|native-)|:|,/)
29+
if (window.livewire) {
30+
// @ts-ignore
31+
window.livewire.components.components().forEach(component => {
32+
if (Array.isArray(component.listeners)) {
33+
component.listeners.forEach(event => {
34+
if (event.startsWith('native')) {
35+
let event_parts = event.split(/(native:|native-)|:|,/)
3736

38-
if (event_parts[1] == 'native:') {
39-
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined)
40-
}
37+
if (event_parts[1] == 'native:') {
38+
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined)
39+
}
4140

42-
let [
43-
s1,
44-
signature,
45-
channel_type,
46-
s2,
47-
channel,
48-
s3,
49-
event_name,
50-
] = event_parts
41+
let [
42+
s1,
43+
signature,
44+
channel_type,
45+
s2,
46+
channel,
47+
s3,
48+
event_name,
49+
] = event_parts
5150

52-
if (data.event === event_name) {
53-
// @ts-ignore
54-
window.livewire.emit(event, data.payload)
51+
if (data.event === event_name) {
52+
// @ts-ignore
53+
window.livewire.emit(event, data.payload)
54+
}
5555
}
56-
}
57-
})
58-
}
59-
})
56+
})
57+
}
58+
})
59+
}
6060
})

0 commit comments

Comments
 (0)