forked from livewire/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lifecycle-hooks.blade.php
executable file
·118 lines (98 loc) · 3.79 KB
/
lifecycle-hooks.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@include('includes.screencast-cta')
## Class Hooks
Each Livewire component undergoes a lifecycle. Lifecycle hooks allow you to run code at any part of the component's lifecyle, or before specific properties are updated.
@component('components.table')
Hooks | Description
--- | ---
mount | Runs once, immediately after the component is instantiated, but before `render()` is called
hydrate | Runs on every request, after the component is hydrated, but before an action is performed, or `render()` is called
hydrateFoo | Runs before a property called `$foo` is hydrated
dehydrate | Runs on every request, before the component is dehydrated, but after `render()` is called
dehydrateFoo | Runs before a property called `$foo` is dehydrated
updating | Runs before any update to the Livewire component's data (Using `wire:model`, not directly inside PHP)
updated | Runs after any update to the Livewire component's data (Using `wire:model`, not directly inside PHP)
updatingFoo | Runs before a property called `$foo` is updated
updatedFoo | Runs after a property called `$foo` is updated
updatingFooBar | Runs before updating a nested property `bar` on the `$foo` property
updatedFooBar | Runs after updating a nested property `bar` on the `$foo` property
@endcomponent
@component('components.code', ['lang' => 'php'])
class HelloWorld extends Component
{
public $foo;
public function mount()
{
//
}
public function hydrateFoo($value)
{
//
}
public function dehydrateFoo($value)
{
//
}
public function hydrate()
{
//
}
public function dehydrate()
{
//
}
public function updating($name, $value)
{
//
}
public function updated($name, $value)
{
//
}
public function updatingFoo($value)
{
//
}
public function updatedFoo($value)
{
//
}
public function updatingFooBar($value)
{
//
}
public function updatedFooBar($value)
{
//
}
}
@endcomponent
## Javascript Hooks {#js-hooks}
Livewire gives you the opportunity to execute javascript during certain events.
@component('components.table')
Hooks | Description
--- | ---
component.initialized | Called when a component has been initialized on the page by Livewire
element.initialized | Called when Livewire initializes an individual element
element.updating | Called before Livewire updates an element during its DOM-diffing cycle after a network roundtrip
element.updated | Called after Livewire updates an element during its DOM-diffing cycle after a network roundtrip
element.removed | Called after Livewire removes an element durting its DOM-diffing cycle
message.sent | Called when a Livewire update triggers a message sent to the server via AJAX
message.failed | Called if the message send fails for some reason
message.received | Called when a message has finished its roudtrip, but before Livewire updates the DOM
message.processed | Called after Livewire processes all side effects (including DOM-diffing) from a message
@endcomponent
@component('components.code', ['lang' => 'js'])
<script>
document.addEventListener("DOMContentLoaded", () => {
Livewire.hook('component.initialized', (component) => {})
Livewire.hook('element.initialized', (el, component) => {})
Livewire.hook('element.updating', (fromEl, toEl, component) => {})
Livewire.hook('element.updated', (el, component) => {})
Livewire.hook('element.removed', (el, component) => {})
Livewire.hook('message.sent', (message, component) => {})
Livewire.hook('message.failed', (message, component) => {})
Livewire.hook('message.received', (message, component) => {})
Livewire.hook('message.processed', (message, component) => {})
});
</script>
@endcomponent