@alpinejs/docs 3.7.0-revision.3 → 3.7.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpinejs/docs",
3
- "version": "3.7.0-revision.3",
3
+ "version": "3.7.1-revision.1",
4
4
  "description": "The documentation for Alpine",
5
5
  "author": "Caleb Porzio",
6
6
  "license": "MIT"
@@ -18,7 +18,9 @@ This is useful for things like modals (especially nesting them), where it's help
18
18
 
19
19
  By attaching `x-teleport` to a `<template>` element, you are telling Alpine to "append" that element to the provided selector.
20
20
 
21
- > The `x-template` selector can be any string you would normally pass into something like `document.querySelector`
21
+ > The `x-template` selector can be any string you would normally pass into something like `document.querySelector`. It will find the first element that matches, be it a tag name (`body`), class name (`.my-class`), ID (`#my-id`), or any other valid CSS selector.
22
+
23
+ [→ Read more about `document.querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
22
24
 
23
25
  Here's a contrived modal example:
24
26
 
@@ -63,7 +65,7 @@ Notice how when toggling the modal, the actual modal contents show up AFTER the
63
65
  <a name="forwarding-events"></a>
64
66
  ## Forwarding events
65
67
 
66
- Alpine tries it's best to make the experience of teleporting seamless. Anything you would normally do in a template, you should be able to do inside an `x-teleport` template. Teleported content can access the normal Alpine scope of the component as well as other features like `$refs`, `$root`, etc...
68
+ Alpine tries its best to make the experience of teleporting seamless. Anything you would normally do in a template, you should be able to do inside an `x-teleport` template. Teleported content can access the normal Alpine scope of the component as well as other features like `$refs`, `$root`, etc...
67
69
 
68
70
  However, native DOM events have no concept of teleportation, so if, for example, you trigger a "click" event from inside a teleported element, that event will bubble up the DOM tree as it normally would.
69
71
 
@@ -138,11 +138,11 @@ For direct control over exactly what goes into your transitions, you can apply C
138
138
  <div
139
139
  x-show="open"
140
140
  x-transition:enter="transition ease-out duration-300"
141
- x-transition:enter-start="opacity-0 transform scale-90"
142
- x-transition:enter-end="opacity-100 transform scale-100"
141
+ x-transition:enter-start="opacity-0 scale-90"
142
+ x-transition:enter-end="opacity-100 scale-100"
143
143
  x-transition:leave="transition ease-in duration-300"
144
- x-transition:leave-start="opacity-100 transform scale-100"
145
- x-transition:leave-end="opacity-0 transform scale-90"
144
+ x-transition:leave-start="opacity-100 scale-100"
145
+ x-transition:leave-end="opacity-0 scale-90"
146
146
  >Hello 👋</div>
147
147
  </div>
148
148
  ```
@@ -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://unpkg.com/alpinejs@3.7.0/dist/cdn.min.js"></script>
36
+ <script defer src="https://unpkg.com/alpinejs@3.7.1/dist/cdn.min.js"></script>
37
37
  ```
38
38
 
39
39
  That's it! Alpine is now available for use inside your page.
@@ -35,3 +35,25 @@ When the `<button>` is pressed, `foo.bar` will be set to "bob", and "bob" will b
35
35
  <button @click="open = ! open">Toggle Open</button>
36
36
  </div>
37
37
  ```
38
+
39
+ <a name="deep-watching"></a>
40
+ ### Deep watching
41
+
42
+ `$watch` will 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
+
44
+ ```alpine
45
+ <div x-data="{ foo: { bar: 'baz' }}" x-init="$watch('foo', (value, oldValue) => console.log(value, oldValue))">
46
+ <button @click="foo.bar = 'bob'">Update</button>
47
+ </div>
48
+ ```
49
+
50
+ When the `<button>` is pressed, `foo.bar` will be set to "bob", and "{bar: 'bob'} {bar: 'baz'}" will be logged to the console (new and old value).
51
+
52
+ > ⚠️ Changing a property of a "watched" object as a side effect of the `$watch` callback will generate an infinite loop and eventually error.
53
+
54
+ ```alpine
55
+ <!-- 🚫 Infinite loop -->
56
+ <div x-data="{ foo: { bar: 'baz', bob: 'lob' }}" x-init="$watch('foo', value => foo.bob = foo.bar">
57
+ <button @click="foo.bar = 'bob'">Update</button>
58
+ </div>
59
+ ```