Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions resources/views/docs/mobile/3/the-basics/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Events are 'broadcast' to the frontend of your application via the web view thro
easily listen for these events through JavaScript in a few ways:

- The globally available `Native.on()` helper
- Directly importing the `on` function
- Directly importing the `On` function
- The `#[OnNative()]` PHP attribute Livewire extension

<aside>
Expand All @@ -133,43 +133,43 @@ Register the event listener directly in JavaScript:

This approach is useful if you're not using any particular frontend JavaScript framework.

#### The `on` import
#### The `On` import

<aside>

Make sure you've [set up the `Native` plugin](native-functions#install-the-plugin) in your `package.json` first.

</aside>

If you're using a SPA framework like Vue or React, it's more convenient to import the `on` function directly to
If you're using a SPA framework like Vue or React, it's more convenient to import the `On` function directly to
register your event listeners. Here's an example using the amazing Vue:

```js
import { on, Events } from '#nativephp';
import { On, Events } from '#nativephp';
import { onMounted } from 'vue';

const handleButtonPressed = (payload: any) => {};

onMounted(() => {
on(Events.Alert.ButtonPressed, handleButtonPressed);
On(Events.Alert.ButtonPressed, handleButtonPressed);
});
```

Note how we're also using the `Events` object above to simplify our use of built-in event names. For custom event
classes, you will need to reference these by their full name:

```js
on('App\\Events\\MyButtonPressedEvent', handleButtonPressed);
On('App\\Events\\MyButtonPressedEvent', handleButtonPressed);
```

In SPA land, don't forget to de-register your event handlers using the `off` function too:
In SPA land, don't forget to de-register your event handlers using the `Off` function too:

```js
import { off, Events } from '#nativephp';
import { Off, Events } from '#nativephp';
import { onUnmounted } from 'vue';

onUnmounted(() => {
off(Events.Alert.ButtonPressed, handleButtonPressed);
Off(Events.Alert.ButtonPressed, handleButtonPressed);
});
```

Expand Down
6 changes: 3 additions & 3 deletions resources/views/docs/mobile/3/the-basics/native-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ section to the JSON:
Run `npm install`, then in your JavaScript, simply import the relevant functions from the plugin:

```js
import { on, off, Microphone, Events } from '#nativephp';
import { On, Off, Microphone, Events } from '#nativephp';
import { onMounted, onUnmounted } from 'vue';

const buttonClicked = () => {
Expand All @@ -64,11 +64,11 @@ const handleRecordingFinished = () => {
};

onMounted(() => {
on(Events.Microphone.MicrophoneRecorded, handleRecordingFinished);
On(Events.Microphone.MicrophoneRecorded, handleRecordingFinished);
});

onUnmounted(() => {
off(Events.Microphone.MicrophoneRecorded, handleRecordingFinished);
Off(Events.Microphone.MicrophoneRecorded, handleRecordingFinished);
});
```

Expand Down
Loading