0.5.1 • Published 10 years ago

jsdm v0.5.1

Weekly downloads
12
License
MIT
Repository
github
Last release
10 years ago

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();
0.5.1

10 years ago

0.5.0

10 years ago

0.4.9

10 years ago

0.4.8

10 years ago

0.4.7

10 years ago

0.4.6

10 years ago

0.4.5

10 years ago

0.4.4

10 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.9

10 years ago

0.3.8

10 years ago

0.3.7

10 years ago

0.3.6

10 years ago

0.3.5

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.9

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.9

11 years ago

0.1.7

11 years ago

0.1.6

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.24

11 years ago

0.0.23

11 years ago

0.0.22

11 years ago

0.0.21

11 years ago

0.0.20

11 years ago

0.0.19

11 years ago

0.0.18

11 years ago

0.0.17

11 years ago

0.0.16

11 years ago

0.0.15

11 years ago

0.0.14

11 years ago

0.0.13

11 years ago

0.0.12

11 years ago

0.0.11

11 years ago

0.0.1

11 years ago