How to use the evt.mix function in evt

To help you get started, we’ve selected a few evt 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 mozilla-b2g / gaia / apps / email / js / vscroll.js View on Github external
this._scrollStopTimeout = setTimeout(this._scrollTimeoutPoll, 300);
      }
    },

    /**
     * Starts checking for the end of scroll events.
     */
    _startScrollStopPolling: function() {
      if (!this._scrollStopTimeout) {
        // "this" binding for _scrollTimeoutPoll done in constructor
        this._scrollStopTimeout = setTimeout(this._scrollTimeoutPoll, 300);
      }
    }
  };

  evt.mix(VScroll.prototype);

  // Override on() to allow for a lazy firing of scrollStopped,
  // particularly when the list is not scrolling, so the stop
  // polling is not currently running. This is useful for "once"
  // listeners that just want to be sure to do work when scroll
  // is not in action.
  var originalOn = VScroll.prototype.on;
  VScroll.prototype.on = function(id, fn) {
    if (id === 'scrollStopped') {
      this._startScrollStopPolling();
    }

    return originalOn.apply(this, slice.call(arguments));
  };

  // Introspection tools --------------------------------------------
github mozilla-b2g / gaia-email-libs-and-more / js / clientapi / mail_attachment.js View on Github external
// Create an absolute id that uniquely identifies the attachment.  (There's
  // no API that cares about this id yet, though.)
  this.id = _message.id + '.' + wireRep.relId;
  // The unique id for the attachment on this message.  Not unique elsewhere.
  this.relId = wireRep.relId;
  // The IMAP part number for this attachment.  If you need this for anything
  // other than debugging, then it's a sad day for all.
  this.partId = wireRep.part;
  this.filename = wireRep.name;
  this.mimetype = wireRep.type;
  this.sizeEstimateInBytes = wireRep.sizeEstimate;
  this._file = wireRep.file;

  this.__updateDownloadOverlay(null);
}
MailAttachment.prototype = evt.mix({
  toString: function() {
    return '[MailAttachment: "' + this.filename + '"]';
  },
  toJSON: function() {
    return {
      type: 'MailAttachment',
      filename: this.filename
    };
  },

  __update: function(wireRep) {
    this.mimetype = wireRep.type;
    this.sizeEstimateInBytes = wireRep.sizeEstimate;
    this._file = wireRep.file;
  },
github mozilla-b2g / gaia-email-libs-and-more / js / clientapi / mail_body.js View on Github external
this._handle = handle;

  this.attachments = null;
  if (wireRep.attachments) {
    this.attachments = [];
    for (var iAtt = 0; iAtt < wireRep.attachments.length; iAtt++) {
      this.attachments.push(
        new MailAttachment(this, wireRep.attachments[iAtt]));
    }
  }
  this._relatedParts = wireRep.relatedParts;
  this.bodyReps = wireRep.bodyReps;
  // references is included for debug/unit testing purposes, hence is private
  this._references = wireRep.references;
}
MailBody.prototype = evt.mix({
  toString: function() {
    return '[MailBody: ' + this.id + ']';
  },
  toJSON: function() {
    return {
      type: 'MailBody',
      id: this.id
    };
  },

  __update: function(wireRep, detail) {
    // Related parts and bodyReps have no state we need to maintain.  Just
    // replace them with the new copies for simplicity.
    this._relatedParts = wireRep.relatedParts;
    this.bodyReps = wireRep.bodyReps;
github mozilla-b2g / gaia / apps / email / js / app_messages.js View on Github external
var appSelf = require('app_self'),
      evt = require('evt'),
      queryURI = require('query_uri');

  var pending = {};
  // htmlCacheRestorePendingMessage defined in html_cache_restore,
  // see comment for it.
  var cachedList = (window.htmlCacheRestorePendingMessage &&
                    window.htmlCacheRestorePendingMessage.length) ?
      window.htmlCacheRestorePendingMessage : [];
  // Convert the cached list to named properties on pending.
  cachedList.forEach(function(type) {
    pending[type] = true;
  });

  var appMessages = evt.mix({
    /**
     * Whether or not we have pending messages.
     *
     * @param {string} type message type.
     * @return {boolean} Whether or there are pending message(s) of the type.
     */
    hasPending: function(type) {
      return pending.hasOwnProperty(type) ||
             (navigator.mozHasPendingMessage &&
              navigator.mozHasPendingMessage(type));
    },

    /**
     * Perform requested activity.
     *
     * @param {MozActivityRequestHandler} req activity invocation.
github mozilla-b2g / gaia-email-libs-and-more / js / clientapi / raw_item.js View on Github external
var evt = require('evt');

function RawItem(api, wireRep, overlays, matchInfo) {
  evt.Emitter.call(this);

  // TODO: have the keying id be parameterized, easiest is probably just to have
  // caller pass the id in since in the windowed case it already knows the id
  // since that's how the naming/mapping occurs.
  this.id = wireRep.id || wireRep._id;

  this.__update(wireRep);
  this.__updateOverlays(overlays);
  this.matchInfo = matchInfo;
}
RawItem.prototype = evt.mix({
  toString: function() {
    return '[RawItem]';
  },
  toJSON: function() {
    return {
      data: this.data
    };
  },

  /**
   * Loads the current unread message count as reported by the FolderStorage
   * backend. this.unread is the current number of unread messages that are
   * stored within the FolderStorage object for this folder. Thus, it only
   * accounts for messages which the user has loaded from the server.
   */
  __update: function(wireRep) {
github mozilla-b2g / gaia-email-libs-and-more / js / clientapi / mail_conversation.js View on Github external
* @property {Boolean} hasAttachments
 */
function MailConversation(api, wireRep, overlays, matchInfo, slice, handle) {
  evt.Emitter.call(this);
  this._api = api;
  this._slice = slice;
  this._handle = handle;

  // Store the wireRep so it can be used for caching.
  this._wireRep = wireRep;

  this.id = wireRep.id;
  this.__update(wireRep, true);
  this.matchInfo = matchInfo;
}
MailConversation.prototype = evt.mix({
  toString: function() {
    return '[MailConversation: ' + this.id + ']';
  },
  toJSON: function() {
    return {
      type: 'MailConversation',
      id: this.id
    };
  },

  viewMessages: function() {
    return this._api.viewConversationMessages(this);
  },

  /**
   * Return the list of folders that correspond to labels that can be applied to
github mozilla-b2g / gaia-email-libs-and-more / js / clientapi / entire_list_view.js View on Github external
this._itemConstructor = itemConstructor;
  this.handle = handle;

  this.serial = 0;

  this.items = [];
  this.itemsById = new Map();

  /**
   * Has this slice been completely initially populated?  Use
   * latestOnce(`complete`, callback) if you want a unified way of waiting for
   * the event while processing ASAP if already available.
   */
  this.complete = false;
}
EntireListView.prototype = evt.mix({
  toString: function() {
    return '[EntireListView: ' + this._ns + ' ' + this.handle + ']';
  },
  toJSON: function() {
    return {
      type: 'EntireListView',
      namespace: this._ns,
      handle: this.handle
    };
  },

  __update: function(details) {
    let newSerial = ++this.serial;

    for (let change of details.changes) {
      if (change.type === 'add') {
github mozilla-b2g / gaia-email-libs-and-more / js / clientapi / mail_folder.js View on Github external
define(function(require) {
'use strict';

var evt = require('evt');

function MailFolder(api, wireRep, overlays, matchInfo) {
  evt.Emitter.call(this);
  this._api = api;

  this.__update(wireRep);
  this.__updateOverlays(overlays);
  this.matchInfo = matchInfo;
}
MailFolder.prototype = evt.mix({
  toString: function() {
    return '[MailFolder: ' + this.path + ']';
  },
  toJSON: function() {
    return {
      type: this.type,
      path: this.path
    };
  },
  /**
   * Loads the current unread message count as reported by the FolderStorage
   * backend. this.unread is the current number of unread messages that are
   * stored within the FolderStorage object for this folder. Thus, it only
   * accounts for messages which the user has loaded from the server.
   */
  __update: function(wireRep) {
github mozilla-b2g / gaia-email-libs-and-more / js / clientapi / windowed_list_view.js View on Github external
* Maps id's to non-null object instances.  If we don't have the data yet,
   * then there is no entry in the map.  (This is somewhat arbitrary for
   * control-flow purposes below; feel free to change if you update the control
   * flow.)
   */
  this._itemsById = new Map();

  this.tocMeta = {};

  /**
   * Has this slice been completely initially populated?  If you want to wait
   * for this, use once('complete').
   */
  this.complete = false;
}
WindowedListView.prototype = evt.mix({
  toString: function() {
    return '[WindowedListView: ' + this._itemConstructor.name + ' ' +
           this.handle + ']';
  },
  toJSON: function() {
    return {
      type: 'WindowedListView',
      namespace: this._ns,
      handle: this.handle
    };
  },

  __update: function(details) {
    let newSerial = ++this.serial;

    let existingSet = this._itemsById;
github mozilla-b2g / gaia-email-libs-and-more / js / clientapi / message_composition.js View on Github external
/**
   * @property attachments
   * @type Object[]
   *
   * A list of attachments currently attached or currently being attached with
   * the following attributes:
   * - name: The filename
   * - size: The size of the attachment payload in binary form.  This does not
   *   include transport encoding costs.
   *
   * Manipulating this list has no effect on reality; the methods addAttachment
   * and removeAttachment must be used.
   */
  this.attachments = null;
}
MessageComposition.prototype = evt.mix({
  toString: function() {
    return '[MessageComposition: ' + this._handle + ']';
  },
  toJSON: function() {
    return {
      type: 'MessageComposition',
      handle: this._handle
    };
  },

  __asyncInitFromMessage: function(message) {
    this._message = message;
    message.on('change', this._onMessageChange.bind(this));
    message.on('remove', this._onMessageRemove.bind(this));
    let wireRep = message._wireRep;
    this.serial++;