Decorators and i18n

Decorators are quite useful in Angular.
If you are not familiar with their usage, let’s say that they allow you to extend or overwrite a service (or directive or filter) in specific parts of your application without modifying the original one.

One of the advantages is that you don’t have to change too much of the implementation or your in-page code, but every part of your application will use the correct (decorated or original) version of every component.

If you need more information about decorators in Angular read the official documentation here

If you need more information about the decorator pattern in general you can find something here

i18n is the internationalization module provided by Angular: it is really useful for multi language applications as it offers an easy management not only for your labels, but calendar and currency as well.

Even if there is not a strict relation between Decorators and i18n, it’s quite possible that in multi language applications you need not only different translations, but custom rules depending on the language/country and in that situation the decorators come in handy.

Continue reading

Advertisements

The hangman in angularjs

Source Wikipedia:

The Hangman is a paper and pencil guessing game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it by suggesting letters or numbers.

The word to guess is represented by a row of dashes, giving the number of letters, numbers and category. If the guessing player suggests a letter or number which occurs in the word, the other player writes it in all its correct positions. If the suggested letter or number does not occur in the word, the other player draws one element of a hanged man stick figure as a tally mark. The game is over when:

  • The guessing player completes the word, or guesses the whole word correctly
  • The other player completes the diagram:

This diagram is, in fact, designed to look like a hanging man. Although debates have arisen about the questionable taste of this picture,[1] it is still in use today. A common alternative for teachers is to draw an apple tree with ten apples, erasing or crossing out the apples as the guesses are used up.

Continue reading

Blackjack in AngularJs (reprise)

After the first implementation of the game, my friend and I compared our versions.
He focused on the deck model instead of the dealer like I did.

This simple choice drove his design to a complete different path.
He put a lot of effort trying to replicate a realistic deck, implementing the shuffle logic and making impossible to draw the same card twice.

This hypotheses never came up to my mind because I knew that in the real game there are multiple decks in order to make almost impossible for the players the calculation of the drawn cards.
Continue reading

A platform game (more or less) in angularjs

If you read the introduction to angularjs, it’s stated clearly that angularjs can be not the best choice to create games.
I can imagine the reason easily: the performances can be very problematic, mostly if the game requires a complex DOM.

Moreover a lot of good frameworks exist to create amazing games in html5 (have you ever heard about impactjs?).

Nevertheless I have found very fascinating the idea to manage via directive a level design instead of a classic multidimensional array as I did in the pawn and tiles experiment.
Continue reading

Complex projects and maintainability

“Keep it simple” is a good advice, but sometimes it is not so easy even in projects very small.

The problem with javascript (most than in other languages) is that even if you know that the project won’t be a “very small” one, it is not so obvious how to proceed in order to keep the code maintainable for you and the future heirs of your code (yap, a lot of times your wonderful code for the next guy is the crappy legacy code).
Continue reading

A Memory game in AngularJs

Just for fun I have tried to recreate a Memory game in AngularJs.
As a kind of game it is not a complicated one, but it was interesting for me to evaluate the time needed in coding using the framework.

The memory game is quite famous among kids, but it is enjoyable even for the adult persons (http://en.wikipedia.org/wiki/Concentration_%28game%29). Continue reading

An Authentication directive

On the server side is absolutely normal to decorate your Controllers or Actions with the Authorization attribute in order to manage correctly permissions and access to the resources/routes.

Sometime the problem is to manage the permissions or the roles in a much more atomic way in the views.
The scenario that a friend described to me was: I want in the a page to show/hide or enable/disable parts of the it depending on the roles of the user.

Continue reading