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

Conversation

gwleuverink
Copy link
Contributor

As mentioned in NativePHP/nativephp.com#44 (comment) there is an opportunity to flesh out the api for working with broadcasted server events on the client side.

This PR introduces a window.Native object that exposes a event listener for any server side events broadcasted over ICP

<script>
    Native.on('\\App\\Events\\BroadcastOverIpc', payload => {
        alert('Event caught in client via Native helper')
    })
</script>

I'm considering replacing the event name match in native.st:6 with event.endsWith(data.event) (or possibly strip trailing slashes before the conditional). This way the leading \\ in the passed event name.

I'll revisit this PR tomorrow.

@gwleuverink
Copy link
Contributor Author

Leading slashes can now be omitted

<script>
    Native.on('App\\Events\\BroadcastOverIpc', payload => {
        alert('Event caught with Native helper')
    })
</script>

@gwleuverink
Copy link
Contributor Author

Because the callback is returned when invoked you can do stuff like this

let podcastId = Native.on('App\\Events\\PodcastProcessed', payload => payload.podcastId)

@gwleuverink gwleuverink marked this pull request as ready for review September 13, 2024 08:36
@simonhamp simonhamp merged commit 7bae295 into NativePHP:main Sep 13, 2024
1 check failed
@simonhamp
Copy link
Member

Do you fancy updating your docs PR with the detail of how to use this?

@gwleuverink
Copy link
Contributor Author

Done!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants