phx-wildcard
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

phx-wildcard

Wildcard support for phoenix channels

Installation

npm i phx-wildcard

Usage

import { Socket } from 'phoenix';
import { Wildcard } from 'phx-wildcard';

const socket = new Socket('url');
socket.connect();
const ch = socket.channel('ch');
ch.join();

// phx-wildcard mutates channel's onMessage property(but saves the old one), 
// so if you need to rewrite onMessage(for logging or whatever)
// do your thing before creating a wildcard instance
const wc = new Wildcard(ch);
const cb1 = (e: string, payload: any) => {});
const cb2 = (e: string, payload: any) => {});
// any pattern supported by Matcher(https://github.com/sindresorhus/matcher)
wc.on('*', cb1);
wc.on(['event-*', '*-123'], cb2);
wc.off('*', cb1);
wc.off(['event-*', '*-123'], cb2);
wc.destroy();

Package Sidebar

Install

npm i phx-wildcard

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

9.88 kB

Total Files

5

Last publish

Collaborators

  • strax77