Giter Club home page Giter Club logo

brighthas-jsdm's Introduction

This repository is a mirror of the component module brighthas/jsdm. It has been modified to work with NPM+Browserify. You can install it using the command npm install npmcomponent/brighthas-jsdm. Please do not open issues or send pull requests against this repo. If you have issues with this repo, report it to npmcomponent. 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();

brighthas-jsdm's People

Contributors

airportyh avatar brighthas avatar lelandtseng avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.