How to use the backbone.Collection.extend 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 MeoMix / StreamusChromeExtension / src / js / background / collection / clientErrors.js View on Github external
'use strict';
import {Collection, Model} from 'backbone';
import ClientError from 'background/model/clientError';

var ClientErrors = Collection.extend({
  model: ClientError,

  url: function() {
    return StreamusBG.serverUrl + 'ClientError/';
  },

  // Don't allow duplicate ClientErrors by stack + lineNumber.
  add: function(clientError) {
    var isAddingModel = clientError instanceof Model;
    var lineNumber = isAddingModel ? clientError.get('lineNumber') : clientError.lineNumber;
    var stack = isAddingModel ? clientError.get('stack') : clientError.stack;
    var hasDuplicate = this._hasDuplicate(lineNumber, stack);

    return hasDuplicate ? false : Collection.prototype.add.apply(this, arguments);
  },
github MeoMix / StreamusChromeExtension / src / js / background / collection / searchResults.js View on Github external
import {Collection} from 'backbone';
import CollectionMultiSelect from 'background/mixin/collectionMultiSelect';
import SearchResult from 'background/model/searchResult';

var SearchResults = Collection.extend({
  model: SearchResult,
  mixins: [CollectionMultiSelect],
  // SearchResults are unable to be destroyed by 'Delete' actions because they don't exist in a mutable collection.
  isImmutable: true,
  userFriendlyName: chrome.i18n.getMessage('searchResults'),

  addVideos: function(videos) {
    if (videos.length > 0) {
      var searchResults = this._mapVideosAsSearchResults(videos);
      this.add(searchResults);

      // Emit a custom event signaling items have been added.
      // Useful for not responding to add until all items have been added.
      this.trigger('add:completed', this);
    }
  },
github jamiebuilds / marionette-wires / src / flashes / collection.js View on Github external
import {Collection} from 'backbone';
import Model from './model';

export default Collection.extend({
  model: Model
});
github MeoMix / StreamusChromeExtension / src / js / foreground / collection / element / checkboxes.js View on Github external
'use strict';
import {Collection} from 'backbone';
import Checkbox from 'foreground/model/element/checkbox';

var Checkboxes = Collection.extend({
  model: Checkbox,

  isChecked: function(property) {
    return this.findWhere({
      property: property
    }).get('checked');
  }
});

export default Checkboxes;
github MeoMix / StreamusWebsite / src / snackbar / snackbars.js View on Github external
import { Collection } from 'backbone';
import Snackbar from './snackbar.js';

export default Collection.extend({
  model: Snackbar
});
github jamiebuilds / marionette-wires / src / books / collection.js View on Github external
import {Collection} from 'backbone';
import Model from './model';

export default Collection.extend({
  url: '/api/books',
  model: Model
});
github scott-w / reps-js / app / base / collections / notification.js View on Github external
import {Collection} from 'backbone';

import {Notification} from '../models/notification';

export const NotificationList = Collection.extend({
  model: Notification,

  addSuccessMsg: function(msg) {
    this.add({
      alert_text: msg,
      alert_type: 'success'
    });
  },

  addErrorMsg: function(msg) {
    this.add({
      alert_text: msg,
      alert_type: 'error'
    });
  },
github misantronic / rbtv.youtube / app / datasource / collections / PlaylistItemsCollection.js View on Github external
import _ from 'underscore';
const Collection = require('backbone').Collection;
import Config from '../../Config';
import PlaylistItemModel from './../models/PlaylistItemModel';

const PlaylistItems = Collection.extend({

    model: PlaylistItemModel,

    url() {
        return Config.endpoints.playlistItems + '?playlistId=' + this._playlistId;
    },

    setPlaylistId(val) {
        this._playlistId = val;
    },

    /** @returns {PlaylistListItem} */
    getNextPlaylistItem(videoId) {
        const model = this.getCurrentPlaylistItem(videoId);
        const index = this.indexOf(model) + 1;
github MeoMix / StreamusChromeExtension / src / js / foreground / collection / element / simpleListItems.js View on Github external
'use strict';
import {Collection} from 'backbone';
import SimpleListItem from 'foreground/model/element/simpleListItem';

var SimpleListItems = Collection.extend({
  model: SimpleListItem
});

export default SimpleListItems;
github misantronic / rbtv.youtube / app.old / modules / playlists / models / Playlists.js View on Github external
import _ from 'underscore';
import $ from 'jquery';
import {Collection} from 'backbone';
import Config from '../../../Config';
import PlaylistModel from './Playlist';

const defaultResults = 24;

/**
 * @class PlaylistsCollection
 */
const Playlists = Collection.extend({

    model: PlaylistModel,

    comparator: 'title',

    _playlistIds: [],
    _displayResults: defaultResults,

    url() {
        let param = '';

        if (this._playlistIds.length) {
            param = '?' +
                $.param([
                    { name: 'id', value: this._playlistIds.join(',') }
                ]);