jsdm v0.5.1
Note:
please wait docs and apidoc.
JSDM
Domain development , DDD-CRS framework for node.js and browser's component/component framework .
Node.js Install
npm install jsdm
Component Install
component install brighthas/jsdm
domain mean?
domain is a black box , outside operate must use domain.exec function.
domain inside include Aggre, EventHandle, Service and CommandHandle.
domain.exec ---> command handle ---> serivce / Aggre object (generate events) ---> event handle
step 1. define Aggre
// User.js
module.exports = wrap;
function wrap(my){
function User(name){
this._name = name;
}
User.prototype = {
getName:function(){
return this._name;
},
changeName:function(name){
this._name = name;
my.publish("user."+this.id+".changeName",name);
my.publish("user.*.changeName",this.id,name);
}
}
User.className = "User";
return User;
}
step 2. define user repository
// user_repo.js
moduel.exports = wrap
// define aggre repository
function wrap(my){
var repository = new Repository("User");
var User = Aggres.User;
// repository is Repository instance , must implement _create/_data2aggre/_aggre2data
repository._create = function(data,callback){
var user = new User(data.name);
callback(undefined,user);
}
repository._data2aggre = function(data){
var user = new User(data.name);
user.id = data.id;
return user;
}
repository._aggre2data = function(aggre){
var data = {
name:aggre.getName(),
id:aggre.id
}
return data;
}
return repository;
}
step 3. define command handle
// handle.js
function wrap(my){
// define command handle 1
function handle1(args,callback){
var repo = my.repos.user;
repo.get(args.id,function(err,user){
user.changeName(args.name);
callback();
})
}
handle1.commandName = "change user name";
// define command handle 2
function handle2(args,callback){
var repo = my.repos.user;
repo.create({name:args.name},callback)
}
handle2.commandName = "create a user";
return [handle1,handle2];
}
module.exports = wrap;
step 4. register and run
var domain = require("jsdm")();
var UserClass = require("./User"),
user_repo = require("./user_repo"),
handles = require("./handle");
domain.register("AggreClass",UserClass)
.register("repository",user_repo)
.register("commandHandle",handles)
.seal();
domain.exec("create a user",{name:"bright.has"},function(){
console.log("lol")
})
domain.register
domain.register("AggreClass",UserClass)
.register("repository",user_repo)
.register("commandHandle",handles)
.seal();
or
domain.register("AggreClass",UserClass,"repository",user_repo,"commandHandle",handles)
.seal();
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago