Last active
August 29, 2015 14:02
-
-
Save klamping/caecc1409e3eee82b197 to your computer and use it in GitHub Desktop.
ng-diaper
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
angular.directive('ngDiaper', function ($rootScope, $timeout, wipesSvc) { | |
return { | |
replace: true, | |
priority: 1000, | |
restrict: 'E', | |
// TODO for some reason, even though we're trying to isolate the scope, properties inside this directive keep leaking out | |
scope: true, | |
template: '<form name="diaper" ng-submit="changeDiaper()"><input type="submit" id="plumbing"></form>', | |
link: function (scope, el) { | |
scope.changeDiaper = function () { | |
var wipe = wipesSvc.grab(); | |
wipe.clean(el); | |
// the fresh air on the skin always causes a reaction | |
scope.$emit('pee'); | |
// grab a new wipe | |
// TODO check for error thrown from svc just in case wipes run out (shouldn't happen though) | |
wipe = wipesSvc.grab(); | |
wipe.clean(el); | |
scope.diaper.$setPristine(); | |
// start a timeout to immediately dirty the diaper after finished changing it | |
$timeout(function () { | |
scope.diaper.$setDirty(); | |
}, 0); | |
}; | |
// dirty the diaper after every $digest | |
$rootScope.$watch(function(){ | |
scope.diaper.$setDirty(); | |
}); | |
} | |
}; | |
}); |
Kevin, I see that you're no longer writing the clean code that I recall from the past. That's a shame.
Michael, mind mentioning what 'code smells' you found with this?
💩
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1