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

vuelve

v2.0.0

Published

A declarative syntax for the Composition API in Vue 3.

Downloads

16

Readme

vuelve

npm version Build Status Coverage Status dependencies Status GitHub license FOSSA Status

Vuelve enables the creation of declarative composables in Vue 3, offering a smooth transition for Vue 2 codebases by emulating the Options API.

Motivation

Composition in software is an ideal way to build scalable solutions, and it's often preferred to other methods of code sharing. However, declarative programming is a better ideal. The more we can get away from imperative programming, the easier our programs become to reason about.

Vue 2 was a great step in the right direction with its declarative Options API. Vue 3, in this regard, is a step back, because it requires you to implement all the functionality in an imperative way. You are forced to use a single scope for all your variables and methods, and even worse, to mix the declaration of your lifecycle hooks with your business logic.

We believe this leads to a confusion in bigger codebases, and a better solution can exist, merging the best of both worlds. Enter Vuelve.

Installation

Install Vuelve via npm:

$ npm i vuelve

Usage

Let's explore transitioning from the Composition API to a more declarative approach using Vuelve, using a simple useMouse composable from the Composables guide in Vue.js documentation as our starting point.

Original Composition API Example:

The mouse.js composable tracks mouse movements.

mouse.js (The composable)

import { ref, onMounted, onUnmounted } from 'vue'

export default function useMouse() {
  const x = ref(0)
  const y = ref(0)

  function update(event) {
    x.value = event.pageX
    y.value = event.pageY
  }

  onMounted(() => window.addEventListener('mousemove', update))
  onUnmounted(() => window.removeEventListener('mousemove', update))

  return { x, y }
}

Used in MouseTracker.vue to display the mouse position:

<script setup>
import useMouse from './mouse.js'

const { x, y } = useMouse()
</script>

<template>Mouse position is at: {{ x }}, {{ y }}</template>

Transforming with Vuelve:

Transform mouse.js into a declarative composable, improving maintainability and readability.

mouse.js

import vuelve from 'vuelve'

export default vuelve({
  data: { x: 0, y: 0 },
  methods: {
    update(event) {
      this.x.value = event.pageX
      this.y.value = event.pageY
    },
  },
  mounted() {
    window.addEventListener('mousemove', this.update)
  },
  unmounted() {
    window.removeEventListener('mousemove', this.update)
  },
})

This transformation retains the functionality while adopting a more intuitive, Vue 2-like syntax. It facilitates a smoother development experience, particularly in larger applications where the clarity and separation of concerns offered by declarative programming can significantly reduce complexity.

Since this is a drop-in replacement, the component that uses this composable will remain the same.

Future work

Vuelve is not complete in its support for all lifecycle hooks the Composition API provides. We are still working on adding more functionality and the goal is to support 100% of the Composition API syntax.

Since Vuelve is declarative in its nature, there will be certain tricks that you won't be able to do with Vuelve which would be possible with the raw Composition API, but this would involve depending too much on imperative order of execution, and we believe this is a bad practice.

Contribution

We are looking for contributors actively to bring missing features of the Composition API into Vuelve. Furthermore, as the community adopts Composition API, we need to expand our examples of declarative composables.

If you would like to see a feature implemented or want to contribute a new feature, you are welcome to open an issue to discuss it and we will be more than happy to help.

If you choose to make a contribution, please fork this repository, work on a feature and submit a pull request. We offer timely and thoughtful code reviews.

License

MIT License

Copyright (c) 2020 Armagan Amcalar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.