squelch-client-state
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 = const Client = const reducer plugin actions = ; // Create a squelch-clientconst client = /* squelch-client config*/ // Pass in a redux store using the reducer.const store = client
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 = // Pass in a function that tells the plugin where to get the state fromconst getState = storeclientclient
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 } = ;
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.