You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.4 KiB
41 lines
1.4 KiB
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var UserModel = /** @class */ (function () {
|
|
function UserModel() {
|
|
/**
|
|
* @type {Observer[]} List of subscribers. In real life, the list of
|
|
* subscribers can be stored more comprehensively (categorized by event
|
|
* type, etc.).
|
|
*/
|
|
this.observers = [];
|
|
this.state = 0;
|
|
}
|
|
/**
|
|
* The subscription management methods.
|
|
*/
|
|
UserModel.prototype.attach = function (observer) {
|
|
console.log('Subject: Attached an observer.');
|
|
this.observers.push(observer);
|
|
};
|
|
UserModel.prototype.detach = function (observer) {
|
|
var observerIndex = this.observers.indexOf(observer);
|
|
this.observers.splice(observerIndex, 1);
|
|
console.log('Subject: Detached an observer.');
|
|
};
|
|
/**
|
|
* Trigger an update in each subscriber.
|
|
*/
|
|
UserModel.prototype.notify = function () {
|
|
console.log('Subject: Notifying observers...');
|
|
for (var _i = 0, _a = this.observers; _i < _a.length; _i++) {
|
|
var observer = _a[_i];
|
|
observer.update(this.state);
|
|
}
|
|
};
|
|
UserModel.prototype.someBusinessMethod = function () {
|
|
console.log("Subject: My state has just changed to: " + this.state);
|
|
this.notify();
|
|
};
|
|
return UserModel;
|
|
}());
|
|
exports.UserModel = UserModel;
|