npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@archtechx/livewire-petite-vue

v0.1.1

Published

petite-vue driver for Livewire

Downloads

2

Readme

petite-vue driver for Livewire

This package provides petite-vue support for Livewire.

Installation

Currently it's only possible to use this library using a <script type="module">. Later we'd also like to support a self-initializing non-module <script> as well as an npm package.

<script type="module">
    import { createApp } from 'https://unpkg.com/@archtechx/livewire-petite-vue'

    window.addEventListener('livewire:load', () => {
        createApp().mount()
    })
</script>

The imported createApp automatically includes a bit of global state and a v-livewire directive. If you'd like to do this manually, you can use:

<script type="module">
    import { state, directive } from 'https://unpkg.com/@archtechx/livewire-petite-vue'
    import { createApp } from 'https://unpkg.com/petite-vue?module'

    window.addEventListener('livewire:load', () => {
        createApp(state).directive('livewire', directive).mount()
    })
</script>

Usage

The package provides a v-livewire directive that lets you configure bi-directional links between Vue state and Livewire state.

For example, if you had a messages property in Vue and an items property in Livewire, you could do:

<div v-livewire="{ messages: 'items' }" v-scope="{ messages: {} }">

Note that you always need to have the property in Vue as well. You need some initial state, and your template must work with the empty state. In our case, an empty state for messages is just {}.

If the properties are named the same, you can simply pass an array:

<div v-livewire="['messages']" v-scope="{ messages: {} }">

If you'd like to defer value changes, i.e. have reactive state in Vue but only update Livewire backend state when a Livewire action is executed, you can use the .defer modifier:

<div v-livewire.defer="['messages']" v-scope="{ messages: {} }">

After your bindings are configured, you can simply update state and the changes will sync between Vue and Livewire. Any changes done in Livewire will be reflected in Vue, and any changes done in Vue (e.g. via v-model inputs) will be reflected in Livewire.

That's the state. But Livewire can also call methods.

For that, you can simply use the wire proxy in your component's state:

<button type="button" @click="wire.send(id)">
    Send
</button>

If the methods return a value, you can do something like await wire.foo('bar').

<div v-livewire="['messages']" v-scope="{ messages: {}, foo: 'bar' }">
    You can use Vue-only state in the component: {{ foo }}
    <input v-model="foo">

    <template v-for="(message, id) in messages">
        <div>
            <div>
                <label :for="`message-${id}`">Message</label>
                <input :id="`message-${id}`" v-model.lazy="messages[id].message">
            </div>

            <button type="button" @click="wire.send(id)">
                Send
            </button>

            <button type="button" @click="wire.remove(id)">
                Remove
            </button>
        </div>
    </template>
</div>

Things to note

Vue uses templates which contain {{ these }} things, and that doesn't pair with Livewire as well as Alpine.

For that reason, the library automatically adds wire:ignore to the root element of each petite-vue component.