@alpinejs/docs 3.12.3-revision.1 → 3.13.1-revision.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -72,3 +72,18 @@ Alpine.data('dropdown', () => ({
|
|
|
72
72
|
},
|
|
73
73
|
}))
|
|
74
74
|
```
|
|
75
|
+
|
|
76
|
+
If you have both an `x-data` object containing an `init()` method and an `x-init` directive, the `x-data` method will be called before the directive.
|
|
77
|
+
|
|
78
|
+
```alpine
|
|
79
|
+
<div
|
|
80
|
+
x-data="{
|
|
81
|
+
init() {
|
|
82
|
+
console.log('I am called first')
|
|
83
|
+
}
|
|
84
|
+
}"
|
|
85
|
+
x-init="console.log('I am called second')"
|
|
86
|
+
>
|
|
87
|
+
...
|
|
88
|
+
</div>
|
|
89
|
+
```
|
package/src/en/directives/on.md
CHANGED
|
@@ -303,7 +303,7 @@ If you are listening for touch events, it's important to add `.passive` to your
|
|
|
303
303
|
|
|
304
304
|
Add this modifier if you want to execute this listener in the event's capturing phase, e.g. before the event bubbles from the target element up the DOM.
|
|
305
305
|
|
|
306
|
-
```
|
|
306
|
+
```alpine
|
|
307
307
|
<div @click.capture="console.log('I will log first')">
|
|
308
308
|
<button @click="console.log('I will log second')"></button>
|
|
309
309
|
</div>
|
|
@@ -33,7 +33,7 @@ This is by far the simplest way to get started with Alpine. Include the followin
|
|
|
33
33
|
Notice the `@3.x.x` in the provided CDN link. This will pull the latest version of Alpine version 3. For stability in production, it's recommended that you hardcode the latest version in the CDN link.
|
|
34
34
|
|
|
35
35
|
```alpine
|
|
36
|
-
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.
|
|
36
|
+
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.13.1/dist/cdn.min.js"></script>
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
That's it! Alpine is now available for use inside your page.
|
|
@@ -61,8 +61,9 @@ Alpine.start()
|
|
|
61
61
|
|
|
62
62
|
> The `window.Alpine = Alpine` bit is optional, but is nice to have for freedom and flexibility. Like when tinkering with Alpine from the devtools for example.
|
|
63
63
|
|
|
64
|
-
|
|
65
64
|
> If you imported Alpine into a bundle, you have to make sure you are registering any extension code IN BETWEEN when you import the `Alpine` global object, and when you initialize Alpine by calling `Alpine.start()`.
|
|
66
65
|
|
|
66
|
+
> Ensure that `Alpine.start()` is only called once per page. Calling it more than once will result in multiple "instances" of Alpine running at the same time.
|
|
67
|
+
|
|
67
68
|
|
|
68
69
|
[→ Read more about extending Alpine](/advanced/extending)
|
|
@@ -87,6 +87,43 @@ Alpine.data('dropdown', () => ({
|
|
|
87
87
|
}))
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
<a name="destroy-functions"></a>
|
|
91
|
+
## Destroy functions
|
|
92
|
+
|
|
93
|
+
If your component contains a `destroy()` method, Alpine will automatically execute it before cleaning up the component.
|
|
94
|
+
|
|
95
|
+
A primary example for this is when registering an event handler with another library or a browser API that isn't available through Alpine.
|
|
96
|
+
See the following example code on how to use the `destroy()` method to clean up such a handler.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
Alpine.data('timer', () => ({
|
|
100
|
+
timer: null,
|
|
101
|
+
counter: 0,
|
|
102
|
+
init() {
|
|
103
|
+
// Register an event handler that references the component instance
|
|
104
|
+
this.timer = setInterval(() => {
|
|
105
|
+
console.log('Increased counter to', ++this.counter);
|
|
106
|
+
}, 1000);
|
|
107
|
+
},
|
|
108
|
+
destroy() {
|
|
109
|
+
// Detach the handler, avoiding memory and side-effect leakage
|
|
110
|
+
clearInterval(this.timer);
|
|
111
|
+
},
|
|
112
|
+
}))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
An example where a component is destroyed is when using one inside an `x-if`:
|
|
116
|
+
|
|
117
|
+
```html
|
|
118
|
+
<span x-data="{ enabled: false }">
|
|
119
|
+
<button @click.prevent="enabled = !enabled">Toggle</button>
|
|
120
|
+
|
|
121
|
+
<template x-if="enabled">
|
|
122
|
+
<span x-data="timer" x-text="counter"></span>
|
|
123
|
+
</template>
|
|
124
|
+
</span>
|
|
125
|
+
```
|
|
126
|
+
|
|
90
127
|
<a name="using-magic-properties"></a>
|
|
91
128
|
## Using magic properties
|
|
92
129
|
|
package/src/en/magics/watch.md
CHANGED
|
@@ -39,7 +39,7 @@ When the `<button>` is pressed, `foo.bar` will be set to "bob", and "bob" will b
|
|
|
39
39
|
<a name="deep-watching"></a>
|
|
40
40
|
### Deep watching
|
|
41
41
|
|
|
42
|
-
`$watch`
|
|
42
|
+
`$watch` automatically watches from changes at any level but you should keep in mind that, when a change is detected, the watcher will return the value of the observed property, not the value of the subproperty that has changed.
|
|
43
43
|
|
|
44
44
|
```alpine
|
|
45
45
|
<div x-data="{ foo: { bar: 'baz' }}" x-init="$watch('foo', (value, oldValue) => console.log(value, oldValue))">
|