How to use tiny-emitter - 10 common examples

To help you get started, we’ve selected a few tiny-emitter 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 syousif94 / frugalmaps / frugalapp / src / CalendarMap.js View on Github external
componentDidMount() {
    emitter.on("fit-bounds", this._fitBounds);
    // emitter.on("fit-marker", this._fitMarker);
    // emitter.on("reset-marker", this._resetMarker);
  }
github syousif94 / frugalmaps / frugalapp / src / InfoScreen.js View on Github external
this.props.fetch({
        id
      });
    }

    this._loadingTimeout = setTimeout(() => {
      this.setState({
        loading: false
      });
    }, 150);

    // if (IOS) {
    //   StatusBar.setBarStyle("light-content");
    // }

    emitter.on(InfoScreen.mapId, this._showLocation);
  }
github forest-watcher / forest-watcher / app / components / map / index.js View on Github external
componentWillUnmount() {
    AppState.removeEventListener('change', this.handleAppStateChange);
    BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);

    // If we're currently tracking a location, don't stop watching for updates!
    if (!this.isRouteTracking()) {
      stopTrackingLocation();
    }

    clearInterval(this.staleLocationTimer);

    // Do remove the emitter listeners here, as we don't want this screen to receive anything while it's non-existent!
    emitter.off(GFWOnLocationEvent, this.updateLocationFromGeolocation);
    emitter.off(GFWOnHeadingEvent);
    emitter.off(GFWOnErrorEvent, this.onLocationUpdateError);
    stopTrackingHeading();

    this.props.setSelectedAreaId('');
  }
github govau / performance-dashboard / client / src / dashboard / scripts / page.js View on Github external
constructor(options) {
    this.options = options;
    this.emitter = new Emitter();
    this.initBtlApp();

    // todo - refactor these in to the app
    this.runOnResize();
    this.runHighContrastSwitch();
  }
github watsondg / video-cache / index.js View on Github external
options = options || {};
    this.baseURL = options.baseURL || '';
    this.formats = options.formats || ['webm', 'mp4', 'ogv', 'ogg'];
    this.eventName = options.eventName || 'canplaythrough';
    this.assetsLoaded = 0;
    this.totalAssets = 0;
    this.crossOrigin = options.crossOrigin;
    this.cache = Object.create(null); // Pure hash, no prototype
    this.el = document.createElement('div');
    this.el.style.display = 'none';
    document.body.appendChild(this.el);

    this.onError = this.onError.bind(this);
}

VideoCache.prototype = Object.create(Emitter.prototype);

VideoCache.prototype.load = function(videos) {
    this.totalAssets = videos.length;

    videos.forEach(function(url) {
        var video = document.createElement('video');

        var formats = url.formats || this.formats;
        var videoId = url.path || url;

        // Clean listeners on load
        video.onerror = this.onError;

        var onVideoReady = function(video) {
            video.onerror = null;
            video['on' + this.eventName] = null;
github react-spring / react-three-fiber / src / canvas.tsx View on Github external
noEvents,
    invalidateFrameloop: false,
    frames: 0,
    aspect: 0,
    subscribers: [],
    camera: defaultCam,
    scene: defaultScene,
    raycaster: defaultRaycaster,
    mouse,
    clock,
    gl,
    size,
    viewport: { width: 0, height: 0, factor: 0 },
    initialClick: [0, 0],
    initialHits: [],
    pointer: new TinyEmitter(),
    captured: undefined,
    events: (undefined as unknown) as PointerEvents,

    subscribe: (ref: React.MutableRefObject, priority: number = 0) => {
      // If this subscription was given a priority, it takes rendering into its own hands
      // For that reason we switch off automatic rendering and increase the manual flag
      // As long as this flag is positive (there could be multiple render subscription)
      // ..there can be no internal rendering at all
      if (priority) state.current.manual++

      state.current.subscribers.push({ ref, priority: priority })
      // Sort layers from lowest to highest, meaning, highest priority renders last (on top of the other frames)
      state.current.subscribers = state.current.subscribers.sort((a, b) => a.priority - b.priority)
      return () => {
        // Decrease manual flag if this subscription had a priority
        if (priority) state.current.manual--
github adobe / reactor-turbine / src / public / EventEmitter.js View on Github external
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by all applicable intellectual property
* laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/

var assign = require('./assign');
var EventEmitter = require('tiny-emitter');

EventEmitter.mixin = function(obj) {
  assign(typeof obj === 'function' ? obj.prototype : obj, EventEmitter.prototype);
};

// Event emitter based on `tiny-emitter` library. It supports the following methods: `on`, `off`,
// `once`, `emit` and `mixin`. The `mixin` method can be used to add event emitter functionality to
// functions or existing instances.
module.exports = EventEmitter;
github zenorocha / clipboard.js / test / clipboard-action.js View on Github external
it('should select text from non-editable element', () => {
            let clip = new ClipboardAction({
                emitter: new Emitter(),
                container: document.body,
                target: document.querySelector('#paragraph')
            });

            assert.equal(clip.selectedText, clip.target.textContent);
        });
    });
github webcreate / infinite-ajax-scroll / test / events_spec.js View on Github external
it('should call event listener', () => {
    const emitter = new Emitter();

    const container = document.createElement('div');

    const ias = new InfiniteAjaxScroll(container, {emitter});

    const spy = {
      foo() {}
    };

    cy.spy(spy, 'foo');

    ias.on('my-event', spy.foo);

    emitter.emit('my-event', 'data1');
    emitter.emit('my-event', 'data2');
github caleb531 / connect-four / test / game / gameplay.spec.js View on Github external
it('should win horizontally', function () {
    const game = new Game();
    game.setPlayers({ gameType: '2P' });
    game.startGame();
    sinon.spy(Emitter.prototype, 'emit');
    try {
      placeChips({
        game,
        columns: [2, 2, 3, 3, 4, 4, 5]
      });
      expect(Emitter.prototype.emit).to.have.been.calledWith('game:declare-winner');
    } finally {
      Emitter.prototype.emit.restore();
    }
    expect(game.winner).not.to.be.null;
    expect(game.winner.name).to.equal('Human 1');
  });

tiny-emitter

A tiny (less than 1k) event emitter library

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis