cqrs

cqrs for javascript

API DOC

Install

npm install cqrs --save

Test

npm test

Use

var Domain = require("cqrs").Domain;
var Actor = require("cqrs").Actor;
var domain = new Domain(options);  // create a cqrs domain
class User extends Actor{

    _when(event){
        switch(event.name){
            case "changeName":
                this._data.name = event.name;
            break;
        }
    }

    changeName(name){
        this._apply("changeName",name);
    }

}
domain.register(User);
domain.on("User.changeName",function(event){
    // ......
})
domain.get("User",userId,function(err,actor){

});

// or

domain.get("User",userId).then(function(actor){
    actor.changeName("leo giese");
});

Advanced Usage

export default
class Transfer extends Actor {

    static get type() {
        return "Transfer";
    }

    transfer(fromId, toId, money) {
        ......

        this._listen("User." + fromId + ":deduct&" + this.id, "__userDeduct");
        this._listen("User." + toId + ":recharge&" + this.id, "__userRecharge");

        ......
    }

    // event handle method
    __userDeduct(event) {
        ......
    }

    __userRecharge(event) {
        ......
    }

}

LICENSE

MIT