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

Commit 92a39d5

Browse files
authored
Merge pull request #21 from jhonoryza/livewire-3-compatibility
Livewire 3 compatibility
2 parents 7541516 + b2dd81b commit 92a39d5

File tree

2 files changed

+53
-43
lines changed

2 files changed

+53
-43
lines changed

dist/preload/index.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,25 @@ electron_1.ipcRenderer.on('log', (event, { level, message, context }) => {
3838
}
3939
});
4040
electron_1.ipcRenderer.on('native-event', (event, data) => {
41-
if (!window.livewire) {
42-
return;
41+
if (window.Livewire) {
42+
window.Livewire.dispatch('native:' + data.event, data.payload);
4343
}
44-
window.livewire.components.components().forEach(component => {
45-
if (Array.isArray(component.listeners)) {
46-
component.listeners.forEach(event => {
47-
if (event.startsWith('native')) {
48-
let event_parts = event.split(/(native:|native-)|:|,/);
49-
if (event_parts[1] == 'native:') {
50-
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined);
44+
if (window.livewire) {
45+
window.livewire.components.components().forEach(component => {
46+
if (Array.isArray(component.listeners)) {
47+
component.listeners.forEach(event => {
48+
if (event.startsWith('native')) {
49+
let event_parts = event.split(/(native:|native-)|:|,/);
50+
if (event_parts[1] == 'native:') {
51+
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined);
52+
}
53+
let [s1, signature, channel_type, s2, channel, s3, event_name,] = event_parts;
54+
if (data.event === event_name) {
55+
window.livewire.emit(event, data.payload);
56+
}
5157
}
52-
let [s1, signature, channel_type, s2, channel, s3, event_name,] = event_parts;
53-
if (data.event === event_name) {
54-
window.livewire.emit(event, data.payload);
55-
}
56-
}
57-
});
58-
}
59-
});
58+
});
59+
}
60+
});
61+
}
6062
});

src/preload/index.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,45 @@ ipcRenderer.on('log', (event, {level, message, context}) => {
1616

1717
// Add Livewire event listeners
1818
ipcRenderer.on('native-event', (event, data) => {
19+
20+
// add support for livewire 3
1921
// @ts-ignore
20-
if (!window.livewire) {
21-
return;
22+
if (window.Livewire) {
23+
// @ts-ignore
24+
window.Livewire.dispatch('native:' + data.event, data.payload);
2225
}
26+
27+
// add support for livewire 2
2328
// @ts-ignore
24-
window.livewire.components.components().forEach(component => {
25-
if (Array.isArray(component.listeners)) {
26-
component.listeners.forEach(event => {
27-
if (event.startsWith('native')) {
28-
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-)|:|,/)
2936

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

34-
let [
35-
s1,
36-
signature,
37-
channel_type,
38-
s2,
39-
channel,
40-
s3,
41-
event_name,
42-
] = event_parts
41+
let [
42+
s1,
43+
signature,
44+
channel_type,
45+
s2,
46+
channel,
47+
s3,
48+
event_name,
49+
] = event_parts
4350

44-
if (data.event === event_name) {
45-
// @ts-ignore
46-
window.livewire.emit(event, data.payload)
51+
if (data.event === event_name) {
52+
// @ts-ignore
53+
window.livewire.emit(event, data.payload)
54+
}
4755
}
48-
}
49-
})
50-
}
51-
})
56+
})
57+
}
58+
})
59+
}
5260
})

0 commit comments

Comments
 (0)