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

squelch-client-state

v2.0.0

Published

A Redux reducer + state for squelch-client

Downloads

12

Readme

squelch-client-state Build Status Coverage Status

A Redux reducer + state for squelch-client. This keeps track of the data for the channels that squelch-client joins, including the topic, mode, and users.

A plugin for squelch-client is also available to automatically hook into the client and automatically dispatch actions for events as they happen.

Installing

npm install squelch-client-state

Example usage

const { createStore } = require('redux')
const Client = require('squelch-client')
const { reducer, plugin, actions } = require('squelch-client-state');

// Create a squelch-client
const client = new Client({/* squelch-client config*/})

// Pass in a redux store using the reducer.
const store = createStore(reducer)
client.use(plugin(store))

It's likely that your store will not have squelch-client-state's reducer as the root reducer. In that case, you can tell the plugin where the subreducer's state is by passing the optional getState argument:

const store = createStore(combineReducers({
    // The client reducer is now a subreducer
    client: reducer
}))
// Pass in a function that tells the plugin where to get the state from
const getState = (store) => store.getState().client
client.use(plugin(store, getState))

If you find the names reducer, plugin, actions too generic or conflicting with other variable names, use the ES6 object notation to rename them:

const {
    reducer: StateReducer,
    plugin: StatePlugin,
    actions: StateActions
} = require('squelch-client-state');

Actions

If you need to manually call the actions, you can access the action types and creators in actions. See actions.js for all available actions.

Furthermore, all actions have an id property in their payload that correspond to the specific instance of squelch-client event that it was created from. This is useful if you are managing multiple client reducers, and need to know which client an action is for.

TODO: document actions

Extended squelch-client functionality

This plugin adds a few things to squelch-client for convenience.

Events

quit

Event Properties: {nick, reason, channels}

A new channels property will be added to the quit event emitted by the client. It is an array of the channels that the user who quit was known to be in before they quit.

Methods

client.getChannel(chan)

Returns the store data for chan. The data will have a shape like this:

{
    joined: true,
    topic: '',
    topicwho: /* Hostmask of topic setter */,
    topictime: /* Date of topic set time */,
    mode: [], // Array of mode characters set on the channel
    users: {
        nickname: '',
        oppedNick: '@',
        voicedNick: '+'
    }
}

client.getChannels()

Returns an object with channel names for keys, and values from getChannel(chan) from above.

client.getJoinedChannels()

Same as getChannels(), but filtered by channels that are currently joined.

client.isInChannel(chan)

Returns true if the client is currently joined in the chan.

client.getTopic(chan)

Returns the topic of the channel. Returns null if the channel doesn't exist in the store.

client.getMode(chan)

Returns an array of mode characters set on the channel. Returns null if the channel doesn't exist in the store.

client.getUsers(chan)

Returns an array of the nicknames who are currently joined in chan.

client.getUserStatus(chan, nick)

Returns the status string of user nick in chan, like @, +, or the empty string if the user is a normal user. Returns null if the user isn't in the channel or the channel doesn't exist in the store.