Skip to content

Instantly share code, notes, and snippets.

View dspangen's full-sized avatar

Dan Spangenberger dspangen

  • Explo
  • New York, NY
View GitHub Profile
@dspangen
dspangen / mapping.json
Created December 1, 2012 21:52
ES mapping for docs
{
"document" : {
"dynamic": "strict",
"properties" : {
"name" : { "type" : "string" },
"external_id" : {
"type" : "string",
"index" : "not_analyzed"
},
"internal_id" : { "type" : "long" },
@dspangen
dspangen / digitalAssetsCollection.js
Last active December 18, 2015 14:28
Mixins blogpost
var DigitalAssetsCollection = Backbone.Collection.extend({
model: Backbone.Model,
initialize: function(undefined, options) {
this.parent = options && options.parent;
if ( !this.parent ) {
throw "a parent product must be provided at initialization";
}
_.bindAll(this, "url");
},
var DigitalAssetsCollection = Backbone.Collection.extend({
model: Backbone.Model,
initialize: function(undefined, options) {
Backbone.Collection.prototype.initialize.apply(this, arguments);
this.parent = options && options.parent;
if ( !this.parent ) {
throw "a parent product must be provided at initialization";
}
},
var NestedCollection = Backbone.Collection.extend({
// Takes parent and nestedPath, corresponding to the parent
// of this nested collection, and the name of the nested
// resource to be used in the url for this collection.
initialize: function(undefined, options) {
Backbone.Collection.prototype.initialize.apply(this, arguments);
this.parent = options && options.parent;
if ( !this.parent || ! this.nestedPath ) {
throw "a parent model, corresponding to the parent of this Nested, " +
"must be provided at initialization, as well as the nestedPath";
var NestedCollection = Backbone.Collection.extend({
// Takes parent and nestedPath, corresponding to the parent
// of this nested collection, and the name of the nested
// resource to be used in the url for this collection.
initialize: function(undefined, options) {
Backbone.Collection.prototype.initialize.apply(this, arguments);
this.parent = options && options.parent;
if ( !this.parent || ! this.nestedPath ) {
throw "a parent model, corresponding to the parent of this Nested, " +
"must be provided at initialization, as well as the nestedPath";
var Mixin = {
mixedInFunction: function() {
console.log("I'm a mixed-in function!");
}
}
var ModelWithMixin = Backbone.Model.extend(_.extend({
initialize: function() {
console.log("I'm a constructor!");
}
var NestedModelMixin = {
initialize: function(undefined, options) {
this.parent = options && options.parent;
if ( !this.parent || ! this.nestedPath ) {
throw "a parent model, corresponding to the parent of this Nested, " +
"must be provided at initialization, as well as the nestedPath";
}
},
// Path to query against is the root path of the parent model, plus the collection key, e.g.
var DigitalAssetsCollection = Backbone.Collection.extend({
mixins: [ NestedModelMixin, PageableCollectionMixin ]
});
var PageableViewMixin {
events: {
"click a.nextPage": "nextPage",
"click a.prevPage": "prevPage"
},
nextPage: function(e) {
// paging logic
},
prevPage: function(e) {
// paging logic
define(["backbone", "backbone.marionette", "backbone.epoxy", "views/mixins/epoxyCustomBindingHandlers", "views/mixins/epoxyCustomBindingFilters"],
function(Backbone, Marionette, Epoxy, EpoxyCustomBindingHandlers, EpoxyCustomBindingFilters) {
// Base set of functions that can be mixed into standard views such as ItemViews, CompositeViews, etc.
return {
bindingHandlers: EpoxyCustomBindingHandlers,
bindingFilters: EpoxyCustomBindingFilters,