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-composition-global-subscription

v0.1.19

Published

A Component to handle global events and data

Downloads

3

Readme

vue-composition-global-subscription

A component to handle global events and data

Vue CompositionAPI に下記の機能を追加します

  • pub sub タイプ グローバル イベントストリーム
  • グローバル データ キャッシュ
  • 非同期 API データ要求
  • Storage API 等によるデータキャッシュ

CompositionAPI Reactive - Watch 機能を利用することにより 処理が非同期に行われUI処理が常に高速に保たれます

unSubscribe 機能により不要なデータキャッシュを削除し省メモリで動作します

Componentの外側からでも利用できます

Object 及び Primitive Value の両方を同様に扱えます

Installation

NPM

npm install vue-composition-global-subscription
# or
yarn add vue-composition-global-subscription

Event Stream

Create Subscription Store

最初にサブスクリプションストアを作成します First, Create Subscription Store

イベントメッセージの型と初期化関数を定義します

import useGlobalSubscription from 'vue-composition-global-subscription'

export interface IMessage{
  id : string
  text : string
  sender : string
}

export default function useMessageSubscription () {
  const initialData = () => { return { id: '', text: '', sender: '' } }
  const subscription = useGlobalSubscription<IMessage>(initialData)
  return {
    ...subscription
  }
}

Publish Message

サブスクリプションストアにイベントメッセージを通知します

import { defineComponent, reactive } from '@vue/composition-api'
import useMessageSubscription from 'src/compsitionStore/use-messageSubscription'

export default defineComponent({
  setup () {
    const state = reactive({
      newMessage: '',
      sender: ''
    })
    const { publish } = useMessageSubscription()
    const sendMessage = () => {
      const id = uid()
      publish('message', { id, text: state.newMessage, sender: state.sender })
      state.newMessage = ''
    }
    return {
      state,
      sendMessage
    }
  }
})

Subscribe Message

サブスクリプションストアからイベントメッセージを購読します アンマウント時に購読解除します

import { defineComponent, onBeforeUnmount, watch, ref } from '@vue/composition-api'
import useMessageSubscription, { IMessage } from 'src/compsitionStore/use-messageSubscription'

export default defineComponent({
  setup () {
    const messages = ref<Array<IMessage>>([])
    const { subscribe } = useMessageSubscription()
    const subscription = subscribe('message')
    watch(subscription.data, (value) => {
      messages.value.unshift(value)
    })
    onBeforeUnmount(() => {
      subscription.unSubscribe()
    })
    return {
      messages
    }
  }
})