Last active
August 29, 2015 14:07
-
-
Save yitznewton/4c89252260487db1cfe8 to your computer and use it in GitHub Desktop.
Decoupled domain module in AngularJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define(function() { | |
| 'use strict'; | |
| function TrelloboardRepository($q) { | |
| this.$q = $q; | |
| } | |
| TrelloboardRepository.prototype = { | |
| find: function() { | |
| // first iteration: just return a hard-coded Trelloboard | |
| var output = this.$q.defer(); | |
| output.resolve({ | |
| cardGroups: [ | |
| { | |
| name: 'Ungrouped', | |
| cards: [] | |
| } | |
| ] | |
| }); | |
| return output.promise; | |
| } | |
| }; | |
| return TrelloboardRepository; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define(['trelloboard_repository', 'q'], function(TrelloboardRepository, q) { | |
| 'use strict'; | |
| var trelloboardRepository; | |
| describe('TrelloboardRepository', function() { | |
| beforeEach(function() { | |
| trelloboardRepository = new TrelloboardRepository(q); | |
| }); | |
| describe('#find', function() { | |
| it('returns a Trello board', function() { | |
| trelloboardRepository.find(1).then(function(trelloboard) { | |
| trelloboard.cardGroups.should.be.instanceof(Array); | |
| }); | |
| }); | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define([ | |
| 'bootstrap', // our app's main AngularJS bootstrap | |
| 'trelloboard_repository' | |
| ], function( | |
| app, | |
| TrelloboardRepository | |
| ) { | |
| 'use strict'; | |
| app.service('TrelloboardRepository', TrelloboardRepository); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define(['bootstrap', 'trelloboard_services'], function(app) { | |
| 'use strict'; | |
| // TrelloboardRepository is magically injected by Angular, now that we've wired it up in trelloboard_services | |
| app.controller('TrelloboardIndexController', function($scope, TrelloboardRepository, $stateParams) { | |
| TrelloboardRepository.find($stateParams.id).then(function(trelloboard) { | |
| $scope.model = trelloboard; | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment