How to use the backbone.Events function in backbone

To help you get started, we’ve selected a few backbone 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 Kitware / minerva / web_external / views / adapters / Adapters.js View on Github external
//
            // Instead of dataset.loadGeoData, ideally this would allow a call
            // to the server to load the geo data rendered.
            //
            // girder.RestRequest({
            //     type: "POST"
            //     url: "adapter/" + dataset._id + "/" + layerType.toString()(),
            //     params: userInput,
            // }).success(function (data){
            //     createLayer
            // });
        }
    };
}

const adapterRegistry = _.extend(new AdapterRegistry(), Backbone.Events);

export default adapterRegistry;

const rendering = { geo: {} };

/**
 * Utility function to define a map representation and add it to the Adapter Registry.
 * @param {string} layerType - The type of map visualization used to render the dataset
 * @param {rendering.geo.MapRepresentation} layerDefinition - The definition of a GeoJs layer representation
 * @param {rendering.geo.MapRepresentation} [ParentDefinition] - The definition of a GeoJs layer representation,
 * to be used as the constructor set as the prototype of layerDefinition
 */
rendering.geo.defineMapLayer = function (layerType, layerDefinition, ParentDefinition) {
    if (ParentDefinition) {
        layerDefinition.prototype = new ParentDefinition();
    }
github cyverse / troposphere / troposphere / static / js / stores / BaseStore.js View on Github external
// isFetchingModel: dictionary of ids as keys and individual models as the values.  Used
    // when we need to make sure to fetch an individual model
    //
    // fetchedModels is a cache of models which have been fetched by id
    this.isFetchingModel = {};
    this.fetchedModels = {};

    // isFetchingMore: True or false depending on whether the next page of data
    // for this.models is being fetched
    this.isFetchingMore = false;

    this.initialize.apply(this, arguments);
};

_.extend(Store.prototype, Backbone.Events, {
    // ---------------
    // Event listeners
    // ---------------

    clearCache: function() {
        this.models = null;
        this.queryModels = {};
    },

    addChangeListener: function(callback) {
        this.on(CHANGE_EVENT, callback);
    },

    removeChangeListener: function(callback) {
        this.off(CHANGE_EVENT, callback);
    },
github microsoft / projection-grid / js / vnext / model / editor.js View on Github external
constructor(storage, model) {
    _.extend(this, Backbone.Events);
    this._storage = normalizeStorage(storage);
    this._data = {}; /* key: dataItem */
    this._orignal = {}; /* original data array from dataStorage */
    this._changedData = {}; /* primaryKey: {item, editState, onCommit} */
    this._commandChain = [];
    this._head = -1;
    this._serverEditID = _.uniqueId('serverEditID');
    this.model = model;
    this._autoCommit = false;
  }
github reboundjs / rebound / packages / rebound-data / lib / computed-property.js View on Github external
// On Change their new values are pushed to the object it is tracking
  this.cache = {
    model: new Rebound.Model({}, lineage),
    collection: new Rebound.Collection([], lineage),
    value: undefined
  };

  // Listen to objects in the cache and push changes to them on modify
  this.listenTo(this.cache.model, 'all', this.onModify);
  this.listenTo(this.cache.collection, 'all', this.onModify);

  this.wire();

};

_.extend(ComputedProperty.prototype, Backbone.Events, {

  isComputedProperty: true,
  isData: true,
  __path: function(){ return ''; },

  getter: NOOP,
  setter: NOOP,

  // If the Computed Property is not already dirty, mark it as such and trigger
  // a `dirty` event.
  markDirty: function(){
    if(this.isDirty){ return void 0; }
    this.isDirty = true;
    this.trigger('dirty', this);
  },
github marionettejs / backbone-metal / test / unit / events.js View on Github external
it('should contain Backbone.Events', function() {
    expect(Metal.Events)
      .to.contain(Backbone.Events);
  });
});
github Kitware / minerva / web_external / views / adapters / registry.js View on Github external
this._createRepresentation = function (container, dataset, layerType, visProperties) {
        if (layerType === null || !_.has(this.registry, layerType)) {
            var message = 'This dataset cannot be adapted to a map layer of type [' + layerType + '].';
            console.error(message);
            return Promise.reject(message);
        } else {
            var Adapter = this.registry[layerType];
            var layerRepr = _.extend(new Adapter(), Backbone.Events);
            return dataset
                .loadGeoData()
                .then(() => {
                    try {
                        layerRepr.init(container, dataset, visProperties, dataset.get('geoData'));
                        return layerRepr;
                    } catch (err) {
                        throw layerRepr;
                    }
                });
        }
    };
}
github marionettejs / backbone-metal / src / events.js View on Github external
import Backbone from 'backbone';
import Mixin from './mixin';

/**
 * A `Metal.Mixin` version of `Backbone.Events`.
 *
 * @mixin Events
 * @memberOf Metal
 * @memberOf Backbone
 * @extends Metal.Mixin
 * @mixes Backbone.Events
 */
const Events = new Mixin(Backbone.Events);

export default Events;
github misantronic / rbtv.youtube / app / utils / watchlist.js View on Github external
storage.set('watchlist', newList);

        if(newList.length !== list.length) {
            this.trigger('removed');
        }
    },

    has(id) {
        const list = this.getList();

        return !!_.findWhere(list, { id });
    }
};

module.exports = _.extend(watchlist, Events);
github mozilla / fxa / packages / fxa-content-server / app / scripts / lib / channels / inter-tab.js View on Github external
/**
   * stringify a message, exposed for testing
   *
   * @param {String} name
   * @param {Object} [data]
   * @returns {String}
   */
  stringify(name, data = {}) {
    return JSON.stringify({
      data: data,
      name: name,
    });
  },
};

_.extend(BroadcastChannelAdapter.prototype, Backbone.Events);
export default BroadcastChannelAdapter;
github girder / girder / girder / web_client / src / utilities / S3UploadHandler.js View on Github external
uploadHandlers.s3 = function (params) {
    this.params = params;
    this.startByte = 0;
    return _.extend(this, Backbone.Events);
};