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

vuex-socket-sync

v1.2.1

Published

Vuex plugin which adds ability to connect store actions with socket events and socket events with store actions

Downloads

10

Readme

vuex-socket-sync Coverage Status Build Status

Vuex plugin, which makes simple, but very powerful job:

  • on each action dispatch it emits socket event, specified for that action, with same payload
  • on each received socket event it dispatches one or more actions, specified for such event, with same payload

Installation

npm i vuex-socket-sync

Usage

It works only with vuex modules.

Into each module describing object u can add optional property socket, which should consists from two sub properties: events and actions.

events should be object representing event-to-action mapping and actions should represent action-to-event mapping

Simplest example of socket mapping:

{
  events: {
    answer: 'setAnswer'
  },
  actions: {
    ask: 'question'
  }
}

No problem if you want few modules actions to be dispatched by one event:

events: {
  answer: [
    'setAnswer',
    'logger/logAnswer'
  ] 
}

In case we haven't slash '/' in event or action mapping value it shall be namespaced or prefixed with current module name.

Be patient: that is actual only for right part of mapping. left part always belongs to current module and same named namespace. So you can write:

  event: 'otherModule/action'

but you cannot

  'otherModule/event': 'myAction'

In case we have '=' as mapping value it means, that we shall use same name for event or action

Full Store Example

import socket from 'vuex-socket-sync';
import io from 'socket.io-client/dist/socket.io.slim';

const modules = {
  folders: {
    namespaced: true,
    state: {
      choosenFolder: null,
      path: '',
      tree: [],
      paths: []
    },
    actions,
    mutations,
    socket: {
      events: {
        paths: [
          'fillQueryPaths',
          'settings/saveActualPaths'
        ]
      },
      actions: {
        openUserFolder: 'browse',
        execute: 'interpreter/execute',
        search: '='
      }
    }
  }
};
const state = {};

export default new Vuex.Store({
  strict: 'true',
  state,
  modules,
  plugins: [
    socket(io, modules)
  ]
});

So, what we have here?

On socket event from namespace /folders with name paths shall be dispatched two actions: folders/fillQueryPaths and settings/saveActualPaths.

On dispatch action folders/openUserFolder shall be emitted event browse of namespace /folders.

On dispatch action folders/execute shall be emitted event execute of namespace /interpreter.

On dispatch action folders/search shall be emitted event search of namespace /folders.

As you see you just give socket.io client builder to plugin. It takes care about everything else by it's own