Code Monkey home page Code Monkey logo

respublica's Introduction

Respublica.js

Respublica is a framework based on Vieux UI development architecture. For more information, visit vieux page.

Overview

function AJAXSatellite() {
  
}

function LoginRegime() {
  
}

function LoginUndertaker() {

}

function LoginCulture() {

}

function LoginRepresentative() {

}

function LoginDiplomat(regime) {
  
}

respublica.
  satellite(AJAXSatellite).
  regime(LoginRegime).
  undertaker(LoginUndertaker)



var LoginRegime = respublica.Regime({
  onRise: function () {
    // on regime rise
  },
  doLogin: function (username, password) {
    var user = new LoginStereotype({
      username: username,
      password: password
    });
    LoginUndertaker.doLogin(user).then(this.onLogin);
  },
  onLogin: function () {
    // Publish message to representatives
    this.publish('loggedIn', true);
  }
});

var AJAXSatellite = respublica.Satellite({
  onLaunch: function () {
    // on satellite launched.
  },
  post: function () {
    // impl. ajax post.
  }
});

var LoginUndertaker = LoginRegime.Undertaker({
  doLogin: function (user) {
    return AJAXSatellite.post('/login', user).then(this.done);
  }
});

var LoginCulture = LoginRegime.Culture({
  onRise: function () {
    this.territory.on('button[type="submit"]', 'click', this.doLogin);
    
    this.representative.on('loggedIn', this.territory.hide);
  },
  
  doLogin: function () {
    var user = this.territory.$('form').values(); // {username, password}
    this.representative.doLogin(user);
  }
  
  onFall: function () {
    // on culture fall
  }
});

var LoginRepresentative = LoginCulture.Representative({
  onAppoint: function () {
    this.regime.listen('loggedIn', this.publish); // forward regime's message to culture
  },
  doLogin: function (user) {
    this.regime.doLogin(user.username, user.password);
  }
});

var LoginDiplomat = LoginRegime.Diplomat({
  onAppoint: function () {
    this.regime.listen('loggedIn', this.onLogin);
  },
  onLogin: function (data) {
    // Say popup diplomat login status.
    PopupDiplomat.message('loggedIn', data);
  }
});

Integration

Simpler:

<script src="respublica.js"></script>
<script>
var MyRegime = respublica.Regime({
  // ...
});
</script>

Advanced: (for the people who love Browserify, Webpack, etc.)

var respublica = require("respublica");
var MyRegime = respublica.Regime({
  // ...
});

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.