KEEPING THINGS SIMPLE IN A GROWING ANGULARJS APPLICATION 5 LESSONS LEARNED FROM 40K LINES OF JAVASCRIPT
KEEPING THINGS SIMPLEIN A GROWING
ANGULARJS APPLICATION5 LESSONS LEARNED FROM 40K LINES OF JAVASCRIPT
An authoring tool that enables doctors and clinical staff to illustrate the optimal way to treat any illness and share that knowledge with
those involved in care.
StackRails API
+AngularJS Client Application
+Sometimes a NodeWebkit Wrapper 1
1 IE8 Is Still Very Much Alive In Hospitals
LESSON 1:DON’T STORE ANYTHING USEFUL IN YOUR CONTROLLERS
Because You Will Probably Need Access To That Stuff
Javascript angular.module('dorsata') .controller('pathwayCtrl', [ function(){ $scope.pathway = {}; } ]);
HTML <input type="html" ng-model="pathway.title">
INJECT Data Objects USING SERVICES**SERVICES == FACTORIES == PROVIDERS.
Put Them All Together In Your App
A REALLY SIMPLE DATA OBJECTangular.module('dorsata') .factory('currentPathway', [ function(){ return { "pathway": {} } }]);
Javascriptangular.module('dorsata') .controller('pathwayCtrl', [ 'currentPathway', function(currentPathway){ // <--- Inject Object $scope.currentPathway = currentPathway; // <--- Bind It To Scope }]);
HTML<input type="html" ng-model="currentPathway.pathway.title">
LESSON 2:SIMPLE CONTROLLERS, COMPLEX SERVICES.
Because You Will Probably Need To Handle Multiple Interactions
angular.module('dorsata') .controller('pathwayCtrl', [ 'currentPathway', 'pathwayRepo', function(currentPathway, pathwayRepo){ $scope.currentPathway = currentPathway;
// Handling The Event $scope.save = function(pathway){ //Setting Loading States $scope.loading = true; //Calling Service Code pathwayRepo.save(pathway) // Trigger Analytics, $http.put, Notify Collections Of Change .finally(function(){ $scope.loading = false; }); }; }]);
THINGS TO MAKE INTO DIRECTIVES
▸ Shared UI Components▸ Behavior/Interaction Patterns (Utility Directives)
SHARED UI COMPONENTS AT DORSATA:▸ Sidebars▸ Menus▸ Menu-items
▸ Comment Boxes (Autocomplete)▸ User Avatars
Javascriptangular.module('dorsata') .directive('focusOnLoad', function() { return function(scope, elem, attr) { elem[0].focus(); }; });
HTML<form> <input type="text" focus-on-load></input></form>
EXAMPLES▸ Tab => onTab
▸ Shift+Tab => onShiftTab▸ Escape Key => onEscape▸ Ctrl+Enter => onCtrlEnter
▸ Focusing/Blurring Inputs => focusOn▸ Confirm-Clicks => confirmClick
AngularJS Production App Checklist:
[ ✓ ] - Error Tracking (Bugsnag) [ ✓ ] - Continuous Integration (Codeship)
[ ✓ ] - User Analytics (Mixpanel)