October 2017
Intermediate to advanced
280 pages
6h 50m
English
Let's take a look at a simple example, which doesn't use any framework. Suppose, we have a model called User, which has a property called name:
class User extends EventEmitter {
private name: string;
setName(name: string) {
this.name = name;
this.emit('change');
}
getName(): string {
return this.name;
}
}
The preceding snippet again uses TypeScript. Do not worry if the syntax does not look familiar to you, we will make an introduction to the language in the next chapter.
The user class extends the EventEmitter class. This provides primitives for emitting and subscribing to events.
Now, let's define a view, which displays name of an instance of the User class, passed as an argument to its constructor:
class View ...
Read now
Unlock full access