mirror of
https://github.com/archtechx/alpine-reactive.git
synced 2025-12-12 16:34:03 +00:00
Installation instructions
This commit is contained in:
parent
b8a040f629
commit
0a77f7a361
2 changed files with 52 additions and 4 deletions
42
README.md
42
README.md
|
|
@ -24,6 +24,48 @@ This package provides a reactive proxy wrapper for these objects. The syntax is
|
||||||
|
|
||||||
One difference between this package's solution and Vue's `reactive()` is that Alpine requires the calls to be **component-specific**. Meaning, the `reactive()` helper also needs the component instance/element. To simplify that, the package also provides a magic Alpine property, `$reactive`.
|
One difference between this package's solution and Vue's `reactive()` is that Alpine requires the calls to be **component-specific**. Meaning, the `reactive()` helper also needs the component instance/element. To simplify that, the package also provides a magic Alpine property, `$reactive`.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### npm
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save-dev @archtechx/alpine-reactive
|
||||||
|
```
|
||||||
|
|
||||||
|
Then import the library **before importing Alpine**:
|
||||||
|
```js
|
||||||
|
import '@archtechx/alpine-reactive'
|
||||||
|
|
||||||
|
// import 'alpinejs'
|
||||||
|
```
|
||||||
|
|
||||||
|
To create reactive proxies, import the `reactive` helper:
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { reactive } from '@archtechx/alpine-reactive'
|
||||||
|
|
||||||
|
window.clickCounter = reactive({
|
||||||
|
counter: 10,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
The Alpine hook is executed automatically regardless of what parts of the library you import. For a full reference of the available helpers, see the [Full API](#full-api) section below.
|
||||||
|
|
||||||
|
### CDN
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script type="module">
|
||||||
|
import { reactive } from 'https://unpkg.com/@archtechx/alpine-reactive'
|
||||||
|
|
||||||
|
window.clickCounter = reactive({
|
||||||
|
counter: 10,
|
||||||
|
})
|
||||||
|
|
||||||
|
// If you want to use reactive() outside of this script tag:
|
||||||
|
// window.reactive = reactive
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
[View online](https://archtechx.github.io/alpine-reactive/demo.html)
|
[View online](https://archtechx.github.io/alpine-reactive/demo.html)
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,10 @@ export function addMagicProperty() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.__ALPINE_REACTIVE_REGISTERED__ = false
|
||||||
|
|
||||||
export function register() {
|
export function register() {
|
||||||
|
if (! window.__ALPINE_REACTIVE_REGISTERED__) {
|
||||||
const deferrer = window.deferLoadingAlpine || function (callback) { callback() }
|
const deferrer = window.deferLoadingAlpine || function (callback) { callback() }
|
||||||
|
|
||||||
window.deferLoadingAlpine = function (callback) {
|
window.deferLoadingAlpine = function (callback) {
|
||||||
|
|
@ -107,6 +110,9 @@ export function register() {
|
||||||
|
|
||||||
deferrer(callback)
|
deferrer(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.__ALPINE_REACTIVE_REGISTERED__ = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
register()
|
register()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue