Traits with ES7 Decorators
In this post we are going to explore how to use ES7 features to define traits with a brand new module: traits-decorator
.
In this post we are going to explore how to use ES7 features to define traits with a brand new module: traits-decorator
.
CocktailJS is a very versatile library. You can follow the single argument class definition where you can define your properties and methods, extend from another class, mix traits and export the class all in one single operation. But sometimes you already have a module definition where you want to keep the current code style. In this post we are going to explore how to use Traits or Talents in an exisiting class definition.
Read MoreJavaScript has five primitive data types: String, Number, Boolean, Null and Undefined. All of these are inmutable, meaning that their values cannot be changed, while Objects, Array, Date, and others are mutable.
This post is intended to show a very subtle difference while defining properties values for a Class inside a prototype versus in the constructor.
TL;DR Do not define mutable properties (Object, Array, Date, etc) in the prototype.
Read MoreWe are happy to announce a new version of CocktailJS! CocktailJS v0.5.0 is available on npm!
#A new version and more!
With this new release we added more functionality to cocktail
by adding a new way to create, use and share custom annotations. We also improved the code by refactoring some internals to avoid duplicated code, fixed some issues and we have added some tests too.
But that’s not all. We have created a few CocktailJS Extensions and you can expect more of them to be released in a near future.
One of the most used modules in NodeJS is events
. This module exposes a class called EventEmitter
that allows you to listen to events in your application using the on
or addListener
methods. You can, as well, emit or fire your own custom events using emit
.
Commonly, you would create an instance of EventEmitter or you could extend from it when you want to give your class the ability to listen to or fire events.
Read MoreWe consider tests mandatory in CocktailJS repository, not only unit tests but integration tests as well. And with those tests we found ourselves having to create some test helper methods to create some possible scenarios and restore state for example. We added some comments in lib/cocktail.js
file as a friendly reminder that those methods should go away when we find a better design or strategy.
#It’s all about describing code
An annotation is a note that is made while reading any form of text.
Annotations are used as a special form of syntactic metadata in the source code. The term metadata refers to “data about data”. While it is an ambiguous definition, the concept in CocktailJS is used to describe actions performed over a class or object . We need “metadata” to perform those actions but at the same time they describe -or annotate- the code.
Read More