|
@@ -14,7 +14,7 @@
|
|
|
</blockquote>
|
|
|
<h2 id="install">Install</h2>
|
|
|
<p><strong>From CDN:</strong> Add the following script to the end of your <code><head></code> section.</p>
|
|
|
-<pre><code class="lang-html"><script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v1.9.5/dist/alpine.js" defer></script>
|
|
|
+<pre><code class="lang-html"><script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v1.9.8/dist/alpine.js" defer></script>
|
|
|
</code></pre>
|
|
|
<p>That's it. It will initialize itself.</p>
|
|
|
<p><strong>From NPM:</strong> Install the package from NPM.</p>
|
|
@@ -117,7 +117,7 @@
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
-<p>And 3 magic properties:</p>
|
|
|
+<p>And 5 magic properties:</p>
|
|
|
<table>
|
|
|
<thead>
|
|
|
<tr>
|
|
@@ -132,6 +132,9 @@
|
|
|
<td><a href="#refs"><code>$refs</code></a></td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
+<td><a href="#event"><code>$event</code></a></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
<td><a href="#dispatch"><code>$dispatch</code></a></td>
|
|
|
</tr>
|
|
|
<tr>
|
|
@@ -175,7 +178,7 @@
|
|
|
<p><strong>Example:</strong> <code><div x-data="{ foo: 'bar' }" x-init="foo = 'baz'"></div></code></p>
|
|
|
<p><strong>Structure:</strong> <code><div x-data="..." x-init="[expression]"></div></code></p>
|
|
|
<p><code>x-init</code> runs an expression when a component is initialized.</p>
|
|
|
-<p>If you wish to run code AFTER Alpine has made it's initial updates to the DOM (something like a <code>mounted()</code> hook in VueJS), you can return a callback from <code>x-init</code>, and it will be run after:</p>
|
|
|
+<p>If you wish to run code AFTER Alpine has made its initial updates to the DOM (something like a <code>mounted()</code> hook in VueJS), you can return a callback from <code>x-init</code>, and it will be run after:</p>
|
|
|
<p><code>x-init="return () => { // we have access to the post-dom-initialization state here // }"</code></p>
|
|
|
<hr>
|
|
|
<h3 id="x-show"><code>x-show</code></h3>
|
|
@@ -189,7 +192,7 @@
|
|
|
</blockquote>
|
|
|
<p><strong>Example:</strong> <code><input x-bind:type="inputType"></code></p>
|
|
|
<p><strong>Structure:</strong> <code><input x-bind:[attribute]="[expression]"></code></p>
|
|
|
-<p><code>x-bind</code> sets the value of an attribute to the result of a JavaScript expression. The expression has access to all the keys of the component's data object, and will update every-time it's data is updated.</p>
|
|
|
+<p><code>x-bind</code> sets the value of an attribute to the result of a JavaScript expression. The expression has access to all the keys of the component's data object, and will update every-time its data is updated.</p>
|
|
|
<blockquote>
|
|
|
<p>Note: attribute bindings ONLY update when their dependencies update. The framework is smart enough to observe data changes and detect which bindings care about them.</p>
|
|
|
</blockquote>
|
|
@@ -212,7 +215,7 @@
|
|
|
</blockquote>
|
|
|
<p><strong>Example:</strong> <code><button x-on:click="foo = 'bar'"></button></code></p>
|
|
|
<p><strong>Structure:</strong> <code><button x-on:[event]="[expression]"></button></code></p>
|
|
|
-<p><code>x-on</code> attaches an event listener to the element it's declared on. When that event is emitted, the JavaScript expression set as it's value is executed.</p>
|
|
|
+<p><code>x-on</code> attaches an event listener to the element it's declared on. When that event is emitted, the JavaScript expression set as its value is executed.</p>
|
|
|
<p>If any data is modified in the expression, other element attributes "bound" to this data, will be updated.</p>
|
|
|
<p><strong><code>keydown</code> modifiers</strong></p>
|
|
|
<p><strong>Example:</strong> <code><input type="text" x-on:keydown.escape="open = false"></code></p>
|
|
@@ -269,7 +272,7 @@
|
|
|
<p><strong>Example:</strong> <code><template x-if="true"><div>Some Element</div></template></code></p>
|
|
|
<p><strong>Structure:</strong> <code><template x-if="[expression]"><div>Some Element</div></template></code></p>
|
|
|
<p>For cases where <code>x-show</code> isn't sufficient (<code>x-show</code> sets an element to <code>display: none</code> if it's false), <code>x-if</code> can be used to actually remove an element completely from the DOM.</p>
|
|
|
-<p>It's important that <code>x-if</code> is used on a <code><template></template></code> tag because Alpine doesn't use a virtual DOM. This implementation allows Alpine to stay rugged and use the real DOM to work it's magic.</p>
|
|
|
+<p>It's important that <code>x-if</code> is used on a <code><template></template></code> tag because Alpine doesn't use a virtual DOM. This implementation allows Alpine to stay rugged and use the real DOM to work its magic.</p>
|
|
|
<blockquote>
|
|
|
<p>Note: <code>x-if</code> must have a single element root inside the <code><template></template></code> tag.</p>
|
|
|
</blockquote>
|
|
@@ -369,6 +372,12 @@
|
|
|
</code></pre>
|
|
|
<p><code>$refs</code> is a magic property that can be used to retrieve DOM elements marked with <code>x-ref</code> inside the component. This is useful when you need to manually manipulate DOM elements.</p>
|
|
|
<hr>
|
|
|
+<h3 id="-event"><code>$event</code></h3>
|
|
|
+<p><strong>Example:</strong></p>
|
|
|
+<pre><code class="lang-html"><input x-on:input="alert($event.target.value)">
|
|
|
+</code></pre>
|
|
|
+<p><code>$event</code> is a magic property that can be used within an event listener to retrieve the native browser "Event" object.</p>
|
|
|
+<hr>
|
|
|
<h3 id="-dispatch"><code>$dispatch</code></h3>
|
|
|
<p><strong>Example:</strong></p>
|
|
|
<pre><code class="lang-html"><div @custom-event="console.log($event.detail.foo)">
|
|
@@ -399,7 +408,7 @@
|
|
|
></button>
|
|
|
</div>
|
|
|
</code></pre>
|
|
|
-<p><code>$nextTick</code> is a magic property that allows you to only execute a given expression AFTER Alpine has made it's reactive DOM updates. This is useful for times you want to interact with the DOM state AFTER it's reflected any data updates you've made.</p>
|
|
|
+<p><code>$nextTick</code> is a magic property that allows you to only execute a given expression AFTER Alpine has made its reactive DOM updates. This is useful for times you want to interact with the DOM state AFTER it's reflected any data updates you've made.</p>
|
|
|
<h2 id="license">License</h2>
|
|
|
<p>Copyright © 2019-2020 Caleb Porzio and contributors</p>
|
|
|
<p>Licensed under the MIT license, see <a href="LICENSE.md">LICENSE.md</a> for details.</p>
|