CQRS的node版eventBus開發完成

brighthas發表於2012-07-23
希望各位大神指教

node 版本的 eventBus 的 API

使用程式碼如下:

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');

<p class="indent">

相關文章