var cqrs = require('cqrs') ,eventBus = cqrs.eventBus ,Event = cqrs.Event;
function ProductChangeEvent(Product,ID){ extends Event }
function Product(){ function ProductChangeHandle(event){ this.name = event.name; } eventBus.subScribeOnce(this.constructor,this.id,ProductChangeHandle); }
Product.prototype.changeName = function(name){ var event = new ProductChangeEvent(this.constructor,this.id); eventBus.publish(this.constructor,this.id,event); }
var product = new Product(id);
product.changeName('SUMMER');
|