anti-patterns

What's wrong with awaiting a promise chain?

冷暖自知 提交于 2019-11-26 01:45:52
问题 I’m working on an Angular 6 application and I’ve been told the following is an anti-pattern: await someFunction().then(result => { console.log(result); }); I realize that it is pointless to await a promise chain. If someFunction() returns a promise, you don’t need a promise chain if you’re awaiting it. You can do this: const result = await someFunction(); console.log(result); But I’m being told awaiting a promise chain can cause bugs, or that it will break things in my code. If the first code

Is ServiceLocator an anti-pattern?

£可爱£侵袭症+ 提交于 2019-11-26 01:39:43
问题 Recently I\'ve read Mark Seemann\'s article about Service Locator anti-pattern. Author points out two main reasons why ServiceLocator is an anti-pattern: API usage issue (which I\'m perfectly fine with) When class employs a Service locator it is very hard to see its dependencies as, in most cases, class has only one PARAMETERLESS constructor. In contrast with ServiceLocator, DI approach explicitly expose dependencies via constructor\'s parameters so dependencies are easy seen in IntelliSense.

Why is Singleton considered an anti-pattern? [duplicate]

爱⌒轻易说出口 提交于 2019-11-25 23:22:19
问题 Possible Duplicate: What is so bad about Singletons? Singleton Design Pattern: Pitfalls Singleton anti-pattern I\'ve heard recently that Singleton is an anti-pattern. I know it has to do with the fact making a class singleton is like making that unique instance a global variable, but it\'s also doing a lot more than that (limiting the number of instances of that object, managing instantiation, etc..). Why exactly is Singleton considered an anti-pattern? And what are the alternatives? 回答1: To

Why are Callbacks from Promise `.then` Methods an Anti-Pattern

冷暖自知 提交于 2019-11-25 23:17:07
问题 I have seen answers on StackOverflow where people suggest furnishing a callback function to an AngularJS service. app.controller(\'tokenCtrl\', function($scope, tokenService) { tokenService.getTokens(function callbackFn(tokens) { $scope.tokens = tokens; }); }); app.factory(\'tokenService\', function($http) { var getTokens = function(callbackFn) { $http.get(\'/api/tokens\').then (function onFulfilled(response) { callbackFn(response.data); }); }; return { getTokens: getTokens }; }); This seems