How to use the emittery function in emittery

To help you get started, we’ve selected a few emittery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atomiclabs / hyperdex / app / renderer / swap-db.js View on Github external
constructor(portfolioId, seedPhrase) {
		// Using `2` so it won't conflict with HyperDEX versions using marketmaker v1.
		this.db = new PouchDB(`swaps2-${portfolioId}`, {adapter: 'idb'});

		this.db.crypto(seedPhrase);

		const ee = new Emittery();
		this.on = ee.on.bind(ee);
		this.off = ee.off.bind(ee);
		this.once = ee.once.bind(ee);

		this.db.changes({
			since: 'now',
			live: true,
			include_docs: true, // eslint-disable-line camelcase
		}).on('change', ({doc: swap}) => ee.emit('change', swap));

		// To be able to sort via timeStarted it MUST be the fist item in the index.
		// https://github.com/pouchdb/pouchdb/issues/7207
		this.ready = (async () => {
			await this.db.createIndex({index: {fields: ['timeStarted', 'uuid']}});
			await this.migrate();
github atomiclabs / hyperdex / app / renderer / marketmaker-socket.js View on Github external
subscribeToSwap(uuid) {
		if (typeof uuid === 'undefined') {
			throw new TypeError(`uuid is required`);
		}

		const swapEmitter = new Emittery();

		const removeListener = this.on('message', message => {
			if (message.uuid !== uuid) {
				return;
			}

			swapEmitter.emit('progress', message);
			if (message.method) {
				swapEmitter.emit(message.method, message);
			}
			if (message.method === 'tradestatus' && message.status === 'finished') {
				swapEmitter.emit('completed', message);
			}
		});

		// We should wait for 10 minutes before removing the listener
github accounts-js / accounts / packages / server / src / accounts-server.ts View on Github external
console.log(`
You are using the default secret "${this.options.tokenSecret}" which is not secure.
Please change it with a strong random token.`);
    }

    this.services = services || {};
    this.db = this.options.db;

    // Set the db to all services
    for (const service in this.services) {
      this.services[service].setStore(this.db);
      this.services[service].server = this;
    }

    // Initialize hooks
    this.hooks = new Emittery();
  }
github BrightID / BrightID / BrightID-rn / src / emitter.js View on Github external
import Emittery from 'emittery';

// global event emitter

const emitter = Emittery();

export default emitter;
github HydroProtocol / hydro-sdk-web / src / lib / orderbook.js View on Github external
import BigNumber from 'bignumber.js';
import Emittery from 'emittery';
import { store } from '../index';
import { setBestAsk, setBestBid } from '../actions/orderbook';
export const OrderbookEmittery = new Emittery();

class MemroyOrderbook {
  aggregatedAsks = [];
  aggregatedBids = [];
  marketId = null;
  aggregation = '0.00000001';
  bids = [];
  asks = [];
  bidsAmount = new BigNumber(0);
  asksAmount = new BigNumber(0);

  updateAggregateDataAtIndex = (side, index, delta) => {
    let aggregatedData;

    if (side === 'buy') {
      aggregatedData = this.aggregatedBids;
github vadimdemedes / draqula / src / Draqula.ts View on Github external
constructor(url: string, options: DraqulaOptions = {}) {
		this.url = url;
		this.options = options;
		this.events = new Emittery();
		this.graph = new DependencyGraph();
		this.queryCache = new WeakMap();
		this.queryIds = new WeakMap();
		this.dataCache = new Map();
	}
github atomiclabs / hyperdex / app / renderer / marketmaker-socket.js View on Github external
constructor(endpoint) {
		this._ws = new WebSocket(endpoint, ['pair.sp.nanomsg.org']);
		this.connected = pEvent(this._ws, 'open');

		const ee = new Emittery();
		this._ee = ee;
		this.on = ee.on.bind(ee);
		this.off = ee.off.bind(ee);
		this.once = ee.once.bind(ee);

		this._ws.addEventListener('message', this._handleMessage);
	}

emittery

Simple and modern async event emitter

MIT
Latest version published 8 months ago

Package Health Score

80 / 100
Full package analysis

Popular emittery functions