How to use the tiny-emitter.prototype function in tiny-emitter

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 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 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');
  });
github caleb531 / connect-four / test / game / end-game.spec.js View on Github external
it('should end', function () {
    const game = new Game();
    game.setPlayers({ gameType: '2P' });
    game.startGame();
    sinon.spy(Emitter.prototype, 'emit');
    try {
      game.endGame();
      expect(Emitter.prototype.emit).to.have.been.calledWith('game:end');
    } finally {
      Emitter.prototype.emit.restore();
    }
    expect(game.currentPlayer).to.be.null;
    expect(game.inProgress).to.be.false;
    expect(game.pendingChip).to.be.null;
  });
github caleb531 / connect-four / test / game.spec.js View on Github external
it('should win horizontally', function () {
    var game = new Game();
    game.setPlayers(2);
    game.startGame();
    sinon.spy(Emitter.prototype, 'emit');
    try {
      placeChips({
        game: 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');
  });
github caleb531 / connect-four / test / game / start-game.spec.js View on Github external
it('should start', function () {
    const game = new Game();
    game.setPlayers({ gameType: '2P' });
    sinon.spy(Emitter.prototype, 'emit');
    try {
      game.startGame();
      expect(Emitter.prototype.emit).to.have.been.calledWith('game:start');
    } finally {
      Emitter.prototype.emit.restore();
    }
    expect(game.currentPlayer).to.equal(game.players[0]);
    expect(game.inProgress).to.be.true;
  });
github caleb531 / connect-four / test / game / start-game.spec.js View on Github external
it('should start', function () {
    const game = new Game();
    game.setPlayers({ gameType: '2P' });
    sinon.spy(Emitter.prototype, 'emit');
    try {
      game.startGame();
      expect(Emitter.prototype.emit).to.have.been.calledWith('game:start');
    } finally {
      Emitter.prototype.emit.restore();
    }
    expect(game.currentPlayer).to.equal(game.players[0]);
    expect(game.inProgress).to.be.true;
  });
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');
  });
github adobe / reactor-turbine / src / public / EventEmitter.js View on Github external
EventEmitter.mixin = function(obj) {
  assign(typeof obj === 'function' ? obj.prototype : obj, EventEmitter.prototype);
};
github anvilresearch / connect-js / src / anvil-connect.js View on Github external
}
  }

  return target
}

/**
 * Support events, e.g. 'authenticated'
 *
 * The 'authenticated' event is emitted in response to a
 * local storage 'anvil.connect' event when the user is authenticated.
 *
 * This can be leveraged to react to an authentiation performed in
 * other windows or tabs.
 */
extend(Anvil, TinyEmitter.prototype)

/**
 * Provider configuration
 */
function configure (options) {
  var params
  Anvil.issuer = options.issuer
  jwks.setJWK(options.jwk)

  Anvil.params = params = {}
  params.response_type = options.response_type || 'id_token token'
  params.client_id = options.client_id
  params.redirect_uri = options.redirect_uri
  params.scope = [
    'openid',
    'profile'
github watsondg / youtube-player / index.js View on Github external
hasAutoplay: opts.hasAutoplay === true ? true : false,
        hasCueAutoplay: (opts.hasCueAutoplay || opts.hasAutoplay) === true ? true : false
    };
    this.el = el;

    this._isPopulated = false;
    this._hasPlayed = false;
    this._isPlaying = false;
    this.playbackInterval = -1;

    this.onPlayerPopulated = this.onPlayerPopulated.bind(this);
    this.onPlayerStateChange = this.onPlayerStateChange.bind(this);
    this.onPlaybackUpdate = this.onPlaybackUpdate.bind(this);
}

Youtube.prototype = Object.create(Emitter.prototype);
Youtube.prototype.constructor = Youtube;

Youtube.prototype.populatePlayer = function(videoId, startTime) {
    this.player = new YT.Player(this.el, {
        width: '100%',
        height: '100%',
        videoId: videoId,
        playerVars: {
            modestbranding: 1,
            rel: 0,
            controls: this.options.controls === true ? 1 : 0,
            showinfo: 0,
            allowfullscreen: this.options.allowFullscreen,
            autoplay: this.options.hasAutoplay === true ? 1 : 0,
            wmode: 'transparent',
            startSeconds: startTime,

tiny-emitter

A tiny (less than 1k) event emitter library

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis