Skip to content

Commit 0a0492d

Browse files
committed
added AMD support
1 parent c4f701a commit 0a0492d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,15 @@ Create a 'main' style class and instantiate your facade with your provided appli
112112
```js
113113
var facade = new ApplicationFacade();
114114
facade.startup();
115+
```
116+
117+
### AMD support
118+
119+
If you are using a AMD supported plugin, BackMVC supports this. Just prefix any of the classes with BackMVC. Example:
120+
121+
```js
122+
var YourFacade = BackMVC.Facade.extend({});
123+
var SomeCommand = BackMVC.Command.extend({});
124+
var SomeModel = BackMVC.Model.extend({});
125+
var SomeView = BackMVC.View.extend({});
115126
```

src/js/BackMVC.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* BackMVC.js 0.1.0
2+
* BackMVC.js 0.3.0
33
* May be freely distributed under the MIT license
44
* https://github.com/krange/backmvc
55
*/
@@ -8,7 +8,7 @@
88
RouterObserver, ViewObserver, Model, Collection, View, Command, Router,
99
Facade, BackMVC;
1010

11-
global.BackMVC = BackMVC = {};
11+
BackMVC = {};
1212

1313
/**
1414
* Base object that can register and remove a facade object. Each actor in
@@ -558,7 +558,7 @@
558558
this._routerObserver.registerFacade(this);
559559
this._viewObserver.registerFacade(this);
560560
};
561-
global.Facade = BackMVC.Facade = Facade;
561+
BackMVC.Facade = Facade;
562562
Facade.extend = Backbone.Model.extend;
563563
_.extend(Facade.prototype, {
564564
/**
@@ -741,7 +741,7 @@
741741
this.name = name;
742742
Backbone.Model.call(this, attributes, options);
743743
};
744-
global.Model = BackMVC.Model = Model;
744+
BackMVC.Model = Model;
745745
Model.extend = Backbone.Model.extend;
746746
_.extend(Model.prototype, Actor, Backbone.Model.prototype);
747747
delete Model.prototype.registerView;
@@ -762,7 +762,7 @@
762762
this.name = name;
763763
Backbone.Router.call(this, options);
764764
};
765-
global.Router = BackMVC.Router = Router;
765+
BackMVC.Router = Router;
766766
Router.extend = Backbone.Router.extend;
767767
_.extend(Router.prototype, Actor, Backbone.Router.prototype);
768768

@@ -783,7 +783,7 @@
783783
Backbone.Collection.call(this, attributes, options);
784784
};
785785

786-
global.Collection = BackMVC.Collection = Collection;
786+
BackMVC.Collection = Collection;
787787
Collection.extend = Backbone.Collection.extend;
788788
_.extend(Collection.prototype, Actor, Backbone.Collection.prototype);
789789
delete Collection.prototype.registerView;
@@ -799,7 +799,7 @@
799799
Command = function () {
800800
this.facade = undefined;
801801
};
802-
global.Command = BackMVC.Command = Command;
802+
BackMVC.Command = Command;
803803
Command.extend = Backbone.Model.extend;
804804
_.extend(Command.prototype, Actor, {
805805
/**
@@ -850,7 +850,7 @@
850850

851851
Backbone.View.call(this, attributes, options);
852852
};
853-
global.View = BackMVC.View = View;
853+
BackMVC.View = View;
854854
View.extend = Backbone.View.extend;
855855
_.extend(View.prototype, Actor, Backbone.View.prototype, {
856856
/**
@@ -866,4 +866,12 @@
866866
return this.messageInterests;
867867
}
868868
});
869-
}(window))
869+
870+
if (typeof define === 'function' && define.amd) {
871+
define(BackMVC);
872+
} else if (typeof module !== 'undefined' && module.exports) {
873+
module.exports = BackMVC;
874+
} else {
875+
global['signals'] = BackMVC;
876+
}
877+
}(window));

0 commit comments

Comments
 (0)