Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
/* @date 05/31/2011 @class Backbone.Subset @name Backbone Subset @desc Implements an imaginary subset of a Backbone Collection (as superset) */ // Extend the default Backbone.Collection _extendBackboneCollectionprototype var model = attrs; thisaddmodel; return model; thisaddcollectionmodels; return this ; // Standard Constructor thisoptions = options || options=; // use the comparator supplied by the options ifoptionscomparator thiscomparator = optionscomparator; delete optionscomparator; if!optionssuperset throw 'Subset must belong to a superset!'; if!optionsfilter throw 'Subset must have a filter'; if!optionssuperset instanceof BackboneCollection && !optionssuperset instanceof BackboneSubset throw "Subset must have Backbone.Collection or Backbone.Subset as its superset!"; var self = this; // transform method, to be applied on models thistransform = optionstransform || functionecho return echo; ; thisfilter = optionsfilter; thissuperset = optionssuperset; // hook on superset's events thissupersetbind"all"functionev // TODO: CLEAN UP RESET!!! switchev case "add": case "remove": ifselffilterarguments1 // we are affected, forward events on this subset self_reset; selftriggerapplyselfarguments; break; case "refresh": self_reset; break; default: // model has changed, maybe it doesn't belong in this subset anymore ifevindexOf"change:" === 0 // sub collection already has object so it could be removed ifselfgetByCidarguments1 // maybe trigger remove if!selffilterarguments1 self_reset; selftrigger'remove'arguments1self; else // still in the set, forward event to this subset self_reset; selftriggerapplyselfarguments; // we got a new element, yay! if!selfgetByCidarguments1 && selffilterarguments1 self_reset; selftrigger'add'arguments1self; ; // remove crucial entries from options delete optionsfilter delete optionssuperset; // get an event if a model changes this_boundOnModelEvent = _bindthis_onModelEventthis; // refresh the models this_reset; // call custom constructor thisinitializeoptions; ; _extendBackboneSubsetprototypeBackboneCollectionprototype // array holding the models as json objects return thismapfunctionc return ctoJSON; // add models var self = this; models = _filtermodelsthisfilter; // return if no models resist ifmodelslength == 0 return; // actually add the models to the superset thissupersetaddmodelsoptions; return this; // remove models // remove model from superset thissupersetremove_filter_filtermodelsfunctioncm return m != null; thisfilteroptions; // get a certain model by id! return _selectthismodelsfunctioncm return cmid == model_id; 0 // get a certain model by cid ! return _selectthismodelsfunctioncm return cmcid == model_cidcid || model_cid; 0 // get a model at a certain position in the _subset_ return thismodelsindex // sorting thissupersetsortoptions; return this; // pluck an attribute from each model in the subset return _mapthismodelsfunctionmodel return modelgetm // refresh the superset (triggers event to refresh this one too) thissupersetrefreshmodelsoptions; return this; thissupersetfetchoptions; return this; return thissupersetcreatemodeloptions; return resp; this_reset; return thismodelslength; return thissupersetchain; // reset state and refresh the models thismodel = thisoptionsmodel || thissupersetmodel; thismodels = this_models; // get the models which belong to this collection // using internal filter method to filter the models that belong to this subset return _filter_filterthistransformthissupersetmodelsfunctioncm return cm != null; thisfilter; ; var subsetMethods = "forEach""each""map""reduce""reduceRight""find""detect""filter""select""reject""every""all""some""any""include""invoke""max""min""sortBy""sortedIndex""toArray""size""first""rest""last""without""indexOf""lastIndexOf""isEmpty"; // add common function to this subset _eachsubsetMethodsfunctioncMethod BackboneSubsetprototypecMethod = function return _cMethodapply_this_modelsconcat_toArrayarguments ; ; |