Skip to content

Commit eb71a9a

Browse files
committed
add native:init to the broadcasting docs
1 parent 1ee78d6 commit eb71a9a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

resources/views/docs/desktop/2/digging-deeper/broadcasting.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ NativePHP injects a `window.Native` object into every window. The `on()` method
4646
the second parameter that will run when the event specified in the first parameter is fired:
4747

4848
```js
49-
Native.on(
50-
'Native\\Desktop\\Events\\Windows\\WindowBlurred',
51-
(payload, event) => {
49+
window.addEventListener('native:init', () => {
50+
51+
Native.on('Native\\Desktop\\Events\\Windows\\WindowBlurred', (payload, event) => {
5252
//
53-
},
54-
)
53+
})
54+
55+
//
56+
})
5557
```
5658

59+
Make sure you declare the listener inside a `native:init` handler, otherwise there is a possibility the `Native` object is not injected inside your window yet.
60+
5761
## Listening with Livewire
5862

5963
To make this process even easier when using [Livewire](https://livewire.laravel.com), you may use the `native:` prefix when

resources/views/docs/desktop/2/digging-deeper/child-processes.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,15 @@ Sometimes you may want to listen and react to these events in real-time, which i
317317
Child Process events to the `nativephp` broadcast channel. Any events broadcasted this way also get dispatched over IPC, enabling you to react to them on the front-end without using websockets.
318318

319319
```js
320-
Native.on('Native\\Desktop\\Events\\ChildProcess\\MessageReceived', (event) => {
321-
if (event.alias === 'tail') {
322-
container.append(event.data)
323-
}
320+
window.addEventListener('native:init', () => {
321+
322+
Native.on('Native\\Desktop\\Events\\ChildProcess\\MessageReceived', (event) => {
323+
if (event.alias === 'tail') {
324+
container.append(event.data)
325+
}
326+
})
327+
328+
//
324329
})
325330
```
326331

0 commit comments

Comments
 (0)