In my previous post I talked about the problems of controllers (both at the back-end and the front-end). The issue is that controllers are too general and tend to become full with mixed logic, especially if the page they control has many UI pieces. So instead of having one controller per page, we can have one controller per component and hence decrease the coupling in one’s code.
In Angular 2 the notion of controller is completely removed. You should work with directives only and you can actually choose what kind of a directive you want to use for the specific case:
- Component directives provide a “static” template with some logic behind. It is the same as a directive with a template and an isolated scope in Angular 1.x
- Template directives work with a user-defined template. It is similar to a directive with transclude in Angular 1.x
- Decorator directives add extra functionality to an existing DOM element (see Decorator pattern). It is the same as a directive with no translude, no own scope and no template in Angular 1.x
If you think you will miss the mapping to a controller from the router in Angular 2, you can actually do a mapping to a ComponentDirective instead, but I would still opt for slicing your views into smaller components.
The nature of HTTP is to provide resources where each resource is identified by a unique URL. A resource can be any kind of file: image, text file, font. Initially web sites used to deliver static HTML pages, which were pretty much limited in terms of content. CGI and server-side scripting languages like PHP, ASP(.NET), and JSP changed this by generating dynamic HTML on the server and sending it back to the client. This allowed the page content to be “configured” by the browser, f.x. using query string. This traditional web architecture is denoted on the diagram below.
It all worked fine until the Web became more complex and developers started to put more and more logic on the server. We ended up having to make requests like /index.php?module=employees&id=5 (especially with some CMS systems). This architecture tended eventually to cause many problems, from search-engine optimization to code maintenance. Continue Reading…
ASP.NET Identity brings the authentication and authorization to a new level. Based on the OWIN middleware, one can plug & play different authentication and authorization providers, f.x. OAuth, OpenID, simple forms authentication. The beauty of the new identity model is that it provides a unified interface to work with. One can write her own log-in providers that still rely on the same unified interface.
Besides the typical scenarios where a user logs in with her username and password, or Twitter/Facebook/Google, or maybe a two factor log-in with SMS/e-mail confirmation, there is another interesting one. In some cases you would want to enable users to log in with simple forms authentication to access a basic area of functionality, f.x. just reading data. On the contrary you would want to protect other areas of the web site where the user can edit sensitive information, f.x. his password. In this case you may want to require that the user logs in again – either with the same provider or with another one.
To solve this issue I decided to write a simple extension for ASP.NET Identity, which I called Double confirm identity. It provides a set of utility methods you can use to achieve the described scenario.
var source = [4, 6, 8, 9];
var mapped = source.map(x => x * 2);
// mapped is [8, 12, 16, 18]
Note, the lambda expression is part of ES6
Polymer is Google’s implementation of WebComponents for today’s browser. If you are not familiar with it, check out this nice tutorial by Pankaj Parashar. The main idea behind WebComponents is that we should be able to create our own web components (hence the name). A web component is just a custom HTML element with some styles and behavior attached to it. An example can be the following:
<my-video-player url="movie.mp4" width="250" height="150" auto-play>
Polymer provides two sets of components one can use directly or build on:
- Core – basic elements, both visual and non-visual, that can help one built layouts, scaffolding, and user interaction
- Paper – these elements implement the material design philosophy of Google