How to use the eventemitter2 function in eventemitter2

To help you get started, we’ve selected a few eventemitter2 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 mudin / indoorjs / dist / indoor.esm.js View on Github external
function touchPinch(target) {
  target = target || window;
  var emitter = new EventEmitter2();
  var _fingers = [null, null];
  var activeCount = 0;
  var lastDistance = 0;
  var ended = false;
  var enabled = false; // some read-only values

  Object.defineProperties(emitter, {
    pinching: function pinching() {
      return activeCount === 2;
    },
    fingers: function fingers() {
      return _fingers;
    }
  });
  enable();
  emitter.enable = enable;
github coralproject / talk / client / coral-framework / services / bootstrap.js View on Github external
export async function createContext({
  reducers = {},
  pluginsConfig = [],
  graphqlExtension = {},
  notification,
  preInit,
  init = noop,
  checkLogin = true,
  addExternalConfig = true,
} = {}) {
  const inIframe = areWeInIframe();
  const eventEmitter = new EventEmitter({ wildcard: true });
  const localStorage = createStorage('localStorage');
  const sessionStorage = createStorage('sessionStorage');
  const pymLocalStorage = inIframe
    ? createPymStorage(pym, 'localStorage')
    : localStorage;
  const pymSessionStorage = inIframe
    ? createPymStorage(pym, 'sessionStorage')
    : sessionStorage;
  const history = createHistory(BASE_PATH);
  const introspection = createIntrospection(introspectionData);
  let store = null;
  const token = () => {
    // Try to get the token from localStorage. If it isn't here, it may
    // be passed as a cookie.

    // NOTE: THIS IS ONLY EVER EVALUATED ONCE, IN ORDER TO SEND A DIFFERENT
github brackets-userland / brackets-git / src / event-emitter.ts View on Github external
import EventEmitter from 'eventemitter2';
import { debug, logError } from './log';

// const debugOn = Preferences.get('debugMode');
const debugOn = true;
const emInstance = new EventEmitter({ wildcard: false });

if (debugOn) {
  emInstance._emit = emInstance.emit;
  emInstance.emit = function (eventName, ...args) {

    if (!eventName) {
      throw new Error('no event has been thrown!');
    }

    let listenersCount = this.listeners(eventName).length;
    let argsString = args.map(function (arg) {
      if (arg === null) {
        return 'null';
      }
      if (typeof arg === 'undefined') {
        return 'undefined';
github folz / reaction-packs / index.js View on Github external
import EventEmitter2 from 'eventemitter2';

import reactions from './reactions';

// Include browser-specific code and assets. (See webpack.config.js.)
var browser = require('--browser');

// Include styles.
require('./style.css');


const emitter = new EventEmitter2();
const packs_api_path = `${document.location.protocol}//${document.location.host}/api/v1/packs/`;

function buildPackStyle(pack) {
    return [].reduce.call(Object.keys(reactions), (sum, reaction) => {
        var opts = reactions[reaction];

        return sum + `
            ${opts['wwwBlingSelector']},
            ${opts['touchBlingSelector']} {
                background-image: url(${pack['px32']}) !important;
                background-size: 16px 128px !important;
                background-position: ${opts['offsetBling']} !important;
            }
            ._39m[data-reaction="${opts['order']}"] ._39n > div:first-child {
                background-position: ${opts['offsetLarge']} !important;
            }
github coralproject / talk / client / coral-embed / src / Bridge.js View on Github external
lazy = process.env.TALK_DEFAULT_LAZY_RENDER === 'TRUE',
      // Any additional options are extracted to be sent to the embed via the
      // pym bridge.
      amp,
      ...opts
    }
  ) {
    this.pym = null;
    this.element = element;
    this.amp = amp;
    this.lazy = !amp && lazy;

    // Parse amp hash.
    this.opts = amp ? parseAMPHash(opts) : opts;
    this.query = buildQuery(this.opts);
    this.emitter = new EventEmitter({ wildcard: true });
    this.snackBar = amp ? null : new SnackBar(snackBarStyles || {});
    this.onAuthChanged = onAuthChanged;
    this.talkBaseUrl = ensureEndSlash(talkBaseUrl);
    this.talkStaticUrl = ensureEndSlash(talkStaticUrl);

    // Store queued operations in a queue that can be processed once the stream
    // is rendered.
    this.queued = [];

    // Attach to the events emitted by the pym parent.
    if (events) {
      events(this.emitter);
    }

    // Start the embed loading process.
    if (this.lazy) {
github coralproject / talk / client / coral-embed / src / Stream.js View on Github external
constructor(el, talkBaseUrl, query, config) {
    this.query = query;

    // Extract the non-opts opts from the object.
    const {
      events = null,
      snackBarStyles = null,
      onAuthChanged = null,
      ...opts
    } = config;

    this.opts = opts;

    this.emitter = new EventEmitter({ wildcard: true });
    this.pym = new pym.Parent(el.id, buildStreamIframeUrl(talkBaseUrl, query), {
      title: opts.title,
      id: `${el.id}_iframe`,
      name: `${el.id}_iframe`,
    });
    this.snackBar = new Snackbar(snackBarStyles || {});

    // Workaround: IOS Safari ignores `width` but respects `min-width` value.
    this.pym.el.firstChild.style.width = '1px';
    this.pym.el.firstChild.style.minWidth = '100%';

    // Resize parent iframe height when child height changes
    let cachedHeight;
    this.pym.onMessage('height', height => {
      if (height !== cachedHeight) {
        this.pym.el.firstChild.style.height = `${height}px`;
github mudin / indoorjs / src / lib / touch-pinch.js View on Github external
function touchPinch (target) {
  target = target || window

  var emitter = new EventEmitter2()
  var fingers = [ null, null ]
  var activeCount = 0

  var lastDistance = 0
  var ended = false
  var enabled = false

  // some read-only values
  Object.defineProperties(emitter, {
    pinching(){
      return activeCount === 2
    },

    fingers() {
      return fingers
    }
github onfido / onfido-sdk-ui / src / index.js View on Github external
import { h, render, Component } from 'preact'
import { Provider as ReduxProvider } from 'react-redux'
import EventEmitter from 'eventemitter2'
import { isSupportedCountry } from 'libphonenumber-js'

import { fetchUrlsFromJWT } from '~utils/jwt'
import { store, actions } from './core'
import Modal from './components/Modal'
import Router from './components/Router'
import * as Tracker from './Tracker'
import { LocaleProvider } from './locales'
import { upperCase } from '~utils/string'
import { enabledDocuments } from './components/Router/StepComponentMap'

const events = new EventEmitter()

Tracker.setUp()

const ModalApp = ({ options:{ useModal, isModalOpen, onModalRequestClose, containerId, shouldCloseOnOverlayClick, ...otherOptions}, ...otherProps }) =>
  
    
  

class Container extends Component {
  componentDidMount() {
    this.prepareInitialStore(this.props.options)
  }

  componentDidUpdate(prevProps) {
    this.prepareInitialStore(this.props.options, prevProps.options)
  }
github formio / formio.js / src / Webform.js View on Github external
function getOptions(options) {
  options = _.defaults(options, {
    submitOnEnter: false,
    icons: Formio.icons || '',
    i18next,
  });
  if (!options.events) {
    options.events = new EventEmitter({
      wildcard: false,
      maxListeners: 0
    });
  }
  return options;
}

eventemitter2

A feature-rich Node.js event emitter implementation with namespaces, wildcards, TTL, async listeners and browser/worker support.

MIT
Latest version published 2 years ago

Package Health Score

82 / 100
Full package analysis