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

Commit

Permalink
Merge pull request #21 from jhonoryza/livewire-3-compatibility
Browse files Browse the repository at this point in the history
Livewire 3 compatibility
  • Loading branch information
simonhamp authored Apr 1, 2024
2 parents 7541516 + b2dd81b commit 92a39d5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 43 deletions.
36 changes: 19 additions & 17 deletions dist/preload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,25 @@ electron_1.ipcRenderer.on('log', (event, { level, message, context }) => {
}
});
electron_1.ipcRenderer.on('native-event', (event, data) => {
if (!window.livewire) {
return;
if (window.Livewire) {
window.Livewire.dispatch('native:' + data.event, data.payload);
}
window.livewire.components.components().forEach(component => {
if (Array.isArray(component.listeners)) {
component.listeners.forEach(event => {
if (event.startsWith('native')) {
let event_parts = event.split(/(native:|native-)|:|,/);
if (event_parts[1] == 'native:') {
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined);
if (window.livewire) {
window.livewire.components.components().forEach(component => {
if (Array.isArray(component.listeners)) {
component.listeners.forEach(event => {
if (event.startsWith('native')) {
let event_parts = event.split(/(native:|native-)|:|,/);
if (event_parts[1] == 'native:') {
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined);
}
let [s1, signature, channel_type, s2, channel, s3, event_name,] = event_parts;
if (data.event === event_name) {
window.livewire.emit(event, data.payload);
}
}
let [s1, signature, channel_type, s2, channel, s3, event_name,] = event_parts;
if (data.event === event_name) {
window.livewire.emit(event, data.payload);
}
}
});
}
});
});
}
});
}
});
60 changes: 34 additions & 26 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,45 @@ ipcRenderer.on('log', (event, {level, message, context}) => {

// Add Livewire event listeners
ipcRenderer.on('native-event', (event, data) => {

// add support for livewire 3
// @ts-ignore
if (!window.livewire) {
return;
if (window.Livewire) {
// @ts-ignore
window.Livewire.dispatch('native:' + data.event, data.payload);
}

// add support for livewire 2
// @ts-ignore
window.livewire.components.components().forEach(component => {
if (Array.isArray(component.listeners)) {
component.listeners.forEach(event => {
if (event.startsWith('native')) {
let event_parts = event.split(/(native:|native-)|:|,/)
if (window.livewire) {
// @ts-ignore
window.livewire.components.components().forEach(component => {
if (Array.isArray(component.listeners)) {
component.listeners.forEach(event => {
if (event.startsWith('native')) {
let event_parts = event.split(/(native:|native-)|:|,/)

if (event_parts[1] == 'native:') {
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined)
}
if (event_parts[1] == 'native:') {
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined)
}

let [
s1,
signature,
channel_type,
s2,
channel,
s3,
event_name,
] = event_parts
let [
s1,
signature,
channel_type,
s2,
channel,
s3,
event_name,
] = event_parts

if (data.event === event_name) {
// @ts-ignore
window.livewire.emit(event, data.payload)
if (data.event === event_name) {
// @ts-ignore
window.livewire.emit(event, data.payload)
}
}
}
})
}
})
})
}
})
}
})

0 comments on commit 92a39d5

Please sign in to comment.