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

vue-api-platform

v0.9.0

Published

Link between APIPlatform (and mercure) and Vuejs

Downloads

11

Readme

vue-api-platform

How to install:

npm i -s vue-api-platform

Use in your project

import ApiPlugin from 'vue-api-platform/plugin'

Vue.use(ApiPlugin)

Use in a component

export default {
  data() {
    return {
      user_: null
    }
  },
  props: [
    'user'
  ],
  api: {
    user_() {
      return this.user
    }
  },
  apiBindError(key, error) {
    // An error occurs during the binding
  }
}

With parameters

export default {
  data() {
    return {
      users_: null,
      pages: [1,2,3]
    }
  },
  props: [
    'users'
  ],
  api: {
    users_: {
      func () {
        return this.users
      },
      pages () {
        return this.pages      
      }
    }
  },
  apiBindError(key, error) {
    // An error occurs during the binding
  }
}

Functions

  • $cacheDataApi set yourself ApiPlatform datas
fetch('/entities?page=1').then(response => {
  if (response.ok) return response.json()
  throw reponse
}).then(datas => {
  this.$cacheDataApi(datas)
})
  • $refreshApi force refresh of a key or an URI
import ApiMixin from 'vue-api-platform/mixin'

export default {
  mixins: [
    ApiMixin('user')
  ],
  methods: {
    refreshByKey() {
      this.$refreshApi('user_')
    },
    refreshByURI() {
      this.$refreshApi(this.user_['@id'])
    }
  }
}

Use with the mixin with props

import ApiMixin from 'vue-api-platform/mixin'

export default {
  mixins: [
    ApiMixin('user')
  ]
}

//Is the same than this
export default {
  data() {
    return {
      user_: null
    }
  },
  props: {
    user: {
      required: true
    }
  },
  api: {
    user_() {
      return this.user
    }
  }
}

The mixin have got many parameters:

  • expose (false) : create a mixin named like the property passed (only works with computed)
  • collection (false) : set the data is an URI of a collection, so the return datas are in an array
  • array (false) : set that the query is an array, so the return datas are in an array
  • required (true) : set the props required or not
  • pages: list of pages (only works with collection)

With parameters

import ApiMixin from 'vue-api-platform/mixin'

export default {
  data() {
    return {
      itemUrl: null,
    }
  },
  mixins: [
    ApiMixin('item', {
      computed () {
        return this.itemUrl
      },
      expose: true
    })
  ]
}

//Is the same than this
export default {
  data() {
    return {
      itemUrl: null,
      item_: null
    }
  },
  api: {
    item_() {
      return this.itemUrl
    }
  },
  computed: {
    item() {
      return this.item_
    }  
  }
}

Other utils mixin

isLoading

Create a computed apiIsLoading which return a boolean if the there's a resource which is actually downloading

import apiIsLoading from 'vue-api-platform/mixin/isLoading'

export default {
  mixins: [
    apiIsLoading
  ]
}

loadingRate

Create a computed apiLoadingRate which return a percent that correspond to the number of variable which are actually downloading (0 => nothing downloaded, 100 => everything is downloaded)

import apiLoadingRate from 'vue-api-platform/mixin/loadingRate'

export default {
  mixins: [
    apiLoadingRate
  ]
}

Debouncing queries

You can enable debounce for queries at a global level, or mixin level. The query will be executed once immediately the first time, afterwards it won't be executed again if it's called before its debounceTimeout is expired. This is useful if you need to fire a query according to a text input change for example. By default, debouncing is disabled for all queries.

use at global level

import ApiPlugin from 'vue-api-platform/plugin'

Vue.use(ApiPlugin, {
  debounce: Boolean, // default to false
  debounceTimeout: Number // defaults to 500ms
  // other options...
})

use at mixin level

import ApiMixin from 'vue-api-platform/mixin'
export default {
  mixin: [
    ApiMixin('myEntity', {
      options: {
        debounce: Boolean, // default to false
        debounceTimeout: Number // defaults to 500ms
      }
      // other options...
    })
  ]
}