Sha256: 3f36dd8ffaa6b7092a6bcc73d16157b1367b82a51aa87719b942a79b0f9fd682

Contents?: true

Size: 1.2 KB

Versions: 14

Compression:

Stored size: 1.2 KB

Contents

//= require ./CollectionQueryParameters

class BaseCollection extends Backbone.Collection {
  constructor(model, options) {
    super(model, options)
    this.queryParameters = new CollectionQueryParameters(this)
  }

  // Returns the collection class for a resource name, using our model
  // convention, i.e.
  // 'foos' -> App.Models.Foo.Collection
  static collectionClassForResource(resourceName) {
    return BaseModel.modelClassForResource(resourceName).Collection
  }

  // Return a collection class with intelligent defaults based on the resource
  // name, i.e. model class and urls set from the resource name
  // The class can be further extended through the typical mechanisms
  static forResource(resourceName) {
    return class extends BaseCollection {
      get model() {
        return BaseModel.modelClassForResource(resourceName)
      }
      //jsonapi-resources dasherizes multi-word resources by default
      url() { return `/${_.str.dasherize(resourceName)}.json` }
    }
  }

  handleLinks(topLevelLinks) {
    this.queryParameters.handleLinks(topLevelLinks)
  }

  fetch(options = {}) {
    if(!options.data) {
      options.data = this.queryParameters.fetchData
    }
    super.fetch(options)
  }
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
revelry_data-0.0.15 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.1.5 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.1.4 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.0.14 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.0.8.1 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.0.13 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.1.3 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.0.12 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.1.2 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.1.1 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.0.10 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.1.0 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.0.8 app/assets/javascripts/revelry_data/models/BaseCollection.es6
revelry_data-0.0.7 app/assets/javascripts/revelry_data/models/BaseCollection.es6