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

@apicase/vue

v0.5.1

Published

Apicase + Vue = <3

Downloads

21

Readme

Apicase Vue

Helper functions for better experience with Apicase and Vue.js and Nuxt!

Apicase docs

Installation

yarn add @apicase/vue
npm install @apicase/vue

Vue.js helpers

injectService - service, config={ name: "api }

Creates mixin that injects service to component instance. Adds request state to config.name and service to service.name properties

import { GetPosts } from "./api"
import { injectService } from "@apicase/vue"

export default {
  mixins: [injectService(GetPosts, { name: "posts" })],
  async created() {
    await this.getPost.doRequest()
    console.log(this.posts) // { success, payload, result, ... }
  }
}

injectFromTree - tree => (service, config={ name: "api })

Like injectService, but accepts tree and gets service by its name from @apicase/services tree

import fetch from '@apicase/adapter-fetch'
import { ApiTree } from '@apicase/services'
import { injectFromTree } from '@apicase/vue'

export const tree = new ApiTree(fetch, [
  { name: 'getPosts', { url: 'posts' }},
  { name: 'helloFoo', { url: 'fooba' }}
])

export const inject = injectFromTree(tree)
import { inject } from "./api"

export default {
  mixin: [inject("getPosts", { name: "posts" })]
}

Nuxt helpers

NOTE: these helpers require Nuxt plugin for Apicase

asyncData - config

Creates asyncData callback that calls service and returns data

<template>
  <div v-if="success">
    <post :item="item" v-for="item in data" />
  </div>
  <div v-else>
    <h4>Error happened</h4>
    <p>{{data}}</p>
  </div>
</template>

<script>
import { asyncData } from "@apicase/vue"

export default {
  asyncData: asyncData({
    service: "getPosts",
    payload: ({ route }) => ({
      query: { pageId: route.params.pageId }
    }),
    result: ({ success, result }) => ({
      success,
      data: success ? result.body : result
    })
  })
}
</script>

payload and result properties are optional. Default values are:

const defaultPayload = ctx => ({})
const defaultResult = ({ success, result }) => ({
  success: success,
  data: success ? result.body : result
})

commitToStore/dispatchToStore - (name, converter)

Helper for events that commits mutation or dipatches action to store that was passed in meta.
Nuxt plugin automatically adds store to meta but you also can do it manually

import fetch from "@apicase/adapter-fetch"
import { ApiTree } from "@apicase/services"
import { ApiService } from "@apicase/core"
import { commitToStore, dispatchToStore } from "@apicase/vue"

import store from "./store"

const WithStore = new ApiService({
  meta: { store }
})

export const tree = new ApiTree(WithStore, [
  {
    url: "posts",
    on: {
      done: commitToStore("posts/setList", ({ result }) => result.body),
      fail: dispatchToStore("alerts/push", ({ result }) => result)
    }
  }
])

2nd callback accepts state and converts it for action/mutation. It's optional, default value:

const defaultConverter = ({ result }) => (result && result.body) || result

License

MIT