Socket
Socket
Sign inDemoInstall

cqrsnode

Package Overview
Dependencies
3
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cqrsnode

cqrs framework for node.js


Version published
Weekly downloads
63
increased by800%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Note

publish version 0.1.0alpha , Please note this version is still too unstable.Need to wait for 0.2.0 stable version.

cqrsnode

CQRS framework for node.js

install

npm install cqrsnode 

create a app

cqrsnode appName

result is create dirs:
    Aggres | eventHandles | commandHandles | queryHandles | services

Aggre code example

	module.exports = User;

	function User(){

	}
	
	User.prototype = {
	  // all update operating for .
		$updateState:function(){
			this.on('change name',function(name){
			  this.data('name',name);	
			});

			this.on('change age',function(age){
				this.data('age',age);	
			})

			this.on('change',function(info){
				this.data('age',info.age);	
				this.data('name',info.name);	
			})
		},
		changeName:function(name){
			var e = ['change name',name];
			this.publish(e);
		},
		changeAge:function(age){
			var e = ['change age',age];
			this.publish(e);
		},
		changeUser:function(name,age){
			var e = ['change',{name:name,age:age}]	
			this.publish(e);
		}
	}	

	User.findByIds = function(ids,callback){
		...
	}

	User.findByName = function(name,callback){
		...	
	}

command handle example

module.exports = {

  'change user name':function(cmd,callback){
 var User = this.aggre('User')	
	 User.get(cmd,id,function(u,next){
	    u.changeName(cmd.name); 
			callback();
			next();
	 })
  },

  'change user age':function(cmd,callback){
 var User = this.aggre('User')	
	 User.get(cmd,id,function(u,next){
	    u.changeAge(cmd.age); 
			callback();
			next();
	 })
  },

	'transfer':function(cmd,callback){
	   this.service(cmd.id1,cmdid2,cmd.money) 
	}

}

query handle example

module.exports = {

'same user':function(query,callback){
		var User = this.aggre('User');	
		User.findByIds(query.ids,callback)
	},

	'get a user':function(query,callback){
		var User = this.aggre('User');	
		User.findById(query.id,callback)
	}

}

event handle example

module.exports = {

'User.change name':[
 function(event){},
 function(event){}
],

	'User.change age':[
 function(event){},
 function(event){}
]
}

service example

module.exports = {
 'transfer':function(id1,id2,money){
	 		var User = this.aggre('User');	 
			var user_1 = null;
			var user_2 = null;
			User.get(id1,function(u,next){
				user_1 = u;
				next();
				User.get(id2,function(u2,next2){
				user_2 = u2;
				next2();
				})	

     	user_1.Outlay(money); 
				user_2.Income(money);

			})
	 }	
	}

Keywords

FAQs

Last updated on 17 Dec 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc