Skip to content

Instantly share code, notes, and snippets.

@gatherKnowledge
Created May 6, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatherKnowledge/9efd77aac47e1f6143b381d89876a383 to your computer and use it in GitHub Desktop.
Save gatherKnowledge/9efd77aac47e1f6143b381d89876a383 to your computer and use it in GitHub Desktop.
var NotifySystem = /** @class */ (function () {
function NotifySystem() {
this.observList = new Array();
}
NotifySystem.prototype.registerObserver = function (o) {
this.observList.push(o);
};
NotifySystem.prototype.removeObserver = function (o) {
this.observList = this.observList.filter(function (x) { return x !== o; });
};
NotifySystem.prototype.notifyObserver = function () {
if (this.observList) {
this.observList.forEach(function (x) {
x.update();
});
}
};
return NotifySystem;
}());
var ObserveUser1 = /** @class */ (function () {
function ObserveUser1() {
}
ObserveUser1.prototype.update = function () {
console.log("1 아이템을 획득했습니다.");
};
return ObserveUser1;
}());
var ObserveUser2 = /** @class */ (function () {
function ObserveUser2() {
}
ObserveUser2.prototype.update = function () {
console.log("2 아이템을 획득했습니다.");
};
return ObserveUser2;
}());
var notifySystem = new NotifySystem();
var user1 = new ObserveUser1();
var user2 = new ObserveUser2();
console.log('------------------------------------');
notifySystem.registerObserver(user1);
notifySystem.registerObserver(user2);
notifySystem.notifyObserver();
console.log('------------------------------------');
notifySystem.removeObserver(user1);
notifySystem.removeObserver(user2);
notifySystem.notifyObserver();
console.log('------------------------------------');
notifySystem.registerObserver(user1);
notifySystem.removeObserver(user2);
notifySystem.notifyObserver();
@gatherKnowledge
Copy link
Author

ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment