marionette-rails 1.0.0.rc3 → 1.0.0.rc4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // Backbone.Marionette, v1.0.0-rc3
1
+ // Backbone.Marionette, v1.0.0-rc4
2
2
  // Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
3
3
  // Distributed under MIT license
4
4
  // http://github.com/marionettejs/backbone.marionette
@@ -207,12 +207,12 @@ Backbone.ChildViewContainer = (function(Backbone, _){
207
207
  return Container;
208
208
  })(Backbone, _);
209
209
 
210
- // Backbone.Wreqr, v0.2.0
211
- // Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
210
+ // Backbone.Wreqr, v0.1.1
211
+ // Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
212
212
  // Distributed under MIT license
213
213
  // http://github.com/marionettejs/backbone.wreqr
214
214
  Backbone.Wreqr = (function(Backbone, Marionette, _){
215
- "option strict";
215
+ "use strict";
216
216
  var Wreqr = {};
217
217
 
218
218
  // Handlers
@@ -220,13 +220,12 @@ Backbone.Wreqr = (function(Backbone, Marionette, _){
220
220
  // A registry of functions to call, given a name
221
221
 
222
222
  Wreqr.Handlers = (function(Backbone, _){
223
- "option strict";
223
+ "use strict";
224
224
 
225
225
  // Constructor
226
226
  // -----------
227
227
 
228
228
  var Handlers = function(){
229
- "use strict";
230
229
  this._handlers = {};
231
230
  };
232
231
 
@@ -284,7 +283,7 @@ Backbone.Wreqr = (function(Backbone, Marionette, _){
284
283
  // A simple command pattern implementation. Register a command
285
284
  // handler and execute it.
286
285
  Wreqr.Commands = (function(Wreqr){
287
- "option strict";
286
+ "use strict";
288
287
 
289
288
  return Wreqr.Handlers.extend({
290
289
  execute: function(){
@@ -303,7 +302,7 @@ Backbone.Wreqr = (function(Backbone, Marionette, _){
303
302
  // A simple request/response implementation. Register a
304
303
  // request handler, and return a response from it
305
304
  Wreqr.RequestResponse = (function(Wreqr){
306
- "option strict";
305
+ "use strict";
307
306
 
308
307
  return Wreqr.Handlers.extend({
309
308
  request: function(){
@@ -322,32 +321,16 @@ Backbone.Wreqr = (function(Backbone, Marionette, _){
322
321
  // of an application through event-driven architecture.
323
322
 
324
323
  Wreqr.EventAggregator = (function(Backbone, _){
324
+ "use strict";
325
+ var EA = function(){};
325
326
 
326
- // Grab a reference to the original listenTo
327
- var listenTo = Backbone.Events.listenTo;
327
+ // Copy the `extend` function used by Backbone's classes
328
+ EA.extend = Backbone.Model.extend;
328
329
 
329
- // Create a version of listenTo that allows contexting binding
330
- function contextBoundListenTo(obj, evtSource, events, callback, context){
331
- context = context || obj;
332
- return listenTo.call(obj, evtSource, events, _.bind(callback, context));
333
- }
330
+ // Copy the basic Backbone.Events on to the event aggregator
331
+ _.extend(EA.prototype, Backbone.Events);
334
332
 
335
- // Define the EventAggregator
336
- function EventAggregator(){}
337
-
338
- // Mix Backbone.Events in to it
339
- _.extend(EventAggregator.prototype, Backbone.Events, {
340
- // Override the listenTo so that we can have a version that
341
- // correctly binds context
342
- listenTo: function(evtSource, events, callback, context){
343
- return contextBoundListenTo(this, evtSource, events, callback, context);
344
- }
345
- });
346
-
347
- // Allow it to be extended
348
- EventAggregator.extend = Backbone.Model.extend;
349
-
350
- return EventAggregator;
333
+ return EA;
351
334
  })(Backbone, _);
352
335
 
353
336
 
@@ -381,7 +364,7 @@ Marionette.getOption = function(target, optionName){
381
364
  if (!target || !optionName){ return; }
382
365
  var value;
383
366
 
384
- if (target.options && target.options[optionName]){
367
+ if (target.options && (optionName in target.options) && (target.options[optionName] !== undefined)){
385
368
  value = target.options[optionName];
386
369
  } else {
387
370
  value = target[optionName];
@@ -509,56 +492,6 @@ Marionette.MonitorDOMRefresh = (function(){
509
492
  })();
510
493
 
511
494
 
512
- // addEventBinder
513
- // --------------
514
- //
515
- // Mixes in Backbone.Events to the target object, if it is not present
516
- // already. Also adjusts the listenTo method to accept a 4th parameter
517
- // for the callback context.
518
-
519
- (function(Backbone, Marionette, _){
520
-
521
- // grab a reference to the original listenTo
522
- var listenTo = Backbone.Events.listenTo;
523
-
524
- // Fix the listenTo method on the target object, allowing the 4th
525
- // context parameter to be specified
526
- Marionette.addEventBinder = function(target){
527
- // If the target is not already extending Backbone.Events,
528
- // then extend that on to it first
529
- if (!target.on && !target.off && !target.listenTo && !target.stopListening){
530
- _.extend(target, Backbone.Events);
531
- }
532
-
533
- // Override the built-in listenTo method to make sure we
534
- // account for context
535
- target.listenTo = function(evtSource, events, callback, context){
536
- context = context || this;
537
- return listenTo.call(this, evtSource, events, _.bind(callback, context));
538
- };
539
- };
540
-
541
- })(Backbone, Marionette, _);
542
-
543
-
544
- // Event Aggregator
545
- // ----------------
546
- // A pub-sub object that can be used to decouple various parts
547
- // of an application through event-driven architecture.
548
- //
549
- // Extends [Backbone.Wreqr.EventAggregator](https://github.com/marionettejs/backbone.wreqr)
550
- // and mixes in an EventBinder from [Backbone.EventBinder](https://github.com/marionettejs/backbone.eventbinder).
551
- Marionette.EventAggregator = Backbone.Wreqr.EventAggregator.extend({
552
-
553
- constructor: function(){
554
- Marionette.addEventBinder(this);
555
-
556
- var args = Array.prototype.slice.apply(arguments);
557
- Backbone.Wreqr.EventAggregator.prototype.constructor.apply(this, args);
558
- }
559
-
560
- });
561
-
562
495
  // Marionette.bindEntityEvents & unbindEntityEvents
563
496
  // ---------------------------
564
497
  //
@@ -707,8 +640,6 @@ Marionette.Controller = function(options){
707
640
  this.triggerMethod = Marionette.triggerMethod;
708
641
  this.options = options || {};
709
642
 
710
- Marionette.addEventBinder(this);
711
-
712
643
  if (_.isFunction(this.initialize)){
713
644
  this.initialize(this.options);
714
645
  }
@@ -737,8 +668,6 @@ _.extend(Marionette.Controller.prototype, Backbone.Events, {
737
668
  Marionette.Region = function(options){
738
669
  this.options = options || {};
739
670
 
740
- Marionette.addEventBinder(this);
741
-
742
671
  this.el = Marionette.getOption(this, "el");
743
672
 
744
673
  if (!this.el){
@@ -953,7 +882,7 @@ _.extend(Marionette.TemplateCache, {
953
882
  // and know whether or not it has been loaded
954
883
  _.extend(Marionette.TemplateCache.prototype, {
955
884
 
956
- // Internal method to load the template asynchronously.
885
+ // Internal method to load the template
957
886
  load: function(){
958
887
  var that = this;
959
888
 
@@ -970,8 +899,10 @@ _.extend(Marionette.TemplateCache.prototype, {
970
899
  },
971
900
 
972
901
  // Load a template from the DOM, by default. Override
973
- // this method to provide your own template retrieval,
974
- // such as asynchronous loading from a server.
902
+ // this method to provide your own template retrieval
903
+ // For asynchronous loading with AMD/RequireJS, consider
904
+ // using a template-loader plugin as described here:
905
+ // https://github.com/marionettejs/backbone.marionette/wiki/Using-marionette-with-requirejs
975
906
  loadTemplate: function(templateId){
976
907
  var template = $(templateId).html();
977
908
 
@@ -1023,7 +954,6 @@ Marionette.View = Backbone.View.extend({
1023
954
 
1024
955
  constructor: function(){
1025
956
  _.bindAll(this, "render");
1026
- Marionette.addEventBinder(this);
1027
957
 
1028
958
  var args = Array.prototype.slice.apply(arguments);
1029
959
  Backbone.View.prototype.constructor.apply(this, args);
@@ -1088,7 +1018,7 @@ Marionette.View = Backbone.View.extend({
1088
1018
  };
1089
1019
 
1090
1020
  // trigger the event
1091
- that.trigger(value, args);
1021
+ that.triggerMethod(value, args);
1092
1022
  };
1093
1023
 
1094
1024
  });
@@ -1444,6 +1374,7 @@ Marionette.CollectionView = Marionette.View.extend({
1444
1374
  removeItemView: function(item){
1445
1375
  var view = this.children.findByModel(item);
1446
1376
  this.removeChildView(view);
1377
+ this.checkEmpty();
1447
1378
  },
1448
1379
 
1449
1380
  // Remove the child view and close it
@@ -1461,13 +1392,16 @@ Marionette.CollectionView = Marionette.View.extend({
1461
1392
  this.children.remove(view);
1462
1393
  }
1463
1394
 
1395
+ this.triggerMethod("item:removed", view);
1396
+ },
1397
+
1398
+ // helper to show the empty view if the collection is empty
1399
+ checkEmpty: function() {
1464
1400
  // check if we're empty now, and if we are, show the
1465
1401
  // empty view
1466
1402
  if (!this.collection || this.collection.length === 0){
1467
1403
  this.showEmptyView();
1468
1404
  }
1469
-
1470
- this.triggerMethod("item:removed", view);
1471
1405
  },
1472
1406
 
1473
1407
  // Append the HTML to the collection's `el`.
@@ -1502,9 +1436,7 @@ Marionette.CollectionView = Marionette.View.extend({
1502
1436
  this.children.each(function(child){
1503
1437
  this.removeChildView(child);
1504
1438
  }, this);
1505
-
1506
- // re-initialize to clean up after ourselves
1507
- this._initChildViewStorage();
1439
+ this.checkEmpty();
1508
1440
  }
1509
1441
  });
1510
1442
 
@@ -1842,14 +1774,13 @@ Marionette.AppRouter = Backbone.Router.extend({
1842
1774
  // event aggregator as `app.vent`
1843
1775
  Marionette.Application = function(options){
1844
1776
  this.initCallbacks = new Marionette.Callbacks();
1845
- this.vent = new Marionette.EventAggregator();
1777
+ this.vent = new Backbone.Wreqr.EventAggregator();
1846
1778
  this.commands = new Backbone.Wreqr.Commands();
1847
1779
  this.reqres = new Backbone.Wreqr.RequestResponse();
1848
1780
  this.submodules = {};
1849
1781
 
1850
1782
  _.extend(this, options);
1851
1783
 
1852
- Marionette.addEventBinder(this);
1853
1784
  this.triggerMethod = Marionette.triggerMethod;
1854
1785
  };
1855
1786
 
@@ -1936,8 +1867,6 @@ Marionette.Module = function(moduleName, app){
1936
1867
  this.app = app;
1937
1868
  this.startWithParent = true;
1938
1869
 
1939
- // extend this module with an event binder
1940
- Marionette.addEventBinder(this);
1941
1870
  this.triggerMethod = Marionette.triggerMethod;
1942
1871
  };
1943
1872
 
@@ -1998,7 +1927,7 @@ _.extend(Marionette.Module.prototype, Backbone.Events, {
1998
1927
  _.each(this.submodules, function(mod){ mod.stop(); });
1999
1928
 
2000
1929
  // run the finalizers
2001
- this._finalizerCallbacks.run();
1930
+ this._finalizerCallbacks.run(undefined,this);
2002
1931
 
2003
1932
  // reset the initializers and finalizers
2004
1933
  this._initializerCallbacks.reset();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marionette-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.0.rc4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: