Share
Embed
Transcript
51 slides
-
“All the gensokyo characters services are written in Framework Gensokyo.”
–XadillaX <The Remilia Bible> 1-1-3, Gensokyo Prologue -
Installation $ npm install -g git+ssh://[email protected]:65422/huaban/gensokyo.git#<VERSION> Or … $ cnpm
install -g gensokyo [--registry=http://registry.npm.huaban.org] -
module.exports = { echo1: [ "before1", "echo2" ], echo2: [
"before1", [ "echo1", "echo2" ], "after1" ], echo3: "echo1", echo4: { before: [ "before1" ], ctrller: "echo1" } }; -
function makeSequence(before, controller, after, routerName, keyName) { var sequence =
[]; sequence.add(before); sequence.add(controller); sequence.add(after); var func = function(req, resp, callback) { var funcIdx = 0; var funcCount = sequence.length; app.logger.info("Received a request \"{router}.{action}\".".assign({ router : routerName, action : keyName })); // do the sequence async.whilst( function() { return funcIdx < funcCount; }, function(next) { var func = sequence[funcIdx]; func(req, resp, function() { funcIdx++; next(); }); }, function(err) { if(err) { app.logger.err("An error occurred in `{router}` -> `{action}`: {error}".assign({ router : routerName, action : keyName, error : err.message })); return; } callback(); } ); }; return func; } -
var util = require("util"); var Controller = require("gensokyo").Controller; var EchoController
= function(gensokyo) { Controller.call(this, gensokyo); }; util.inherits(EchoController, Controller); EchoController.prototype.echo1 = function(req, resp, next) { this.logger.info("echo1"); next(); }; EchoController.prototype.echo2 = function(req, resp, next) { this.logger.info("echo2"); resp.message.ok = true; // 测试⼈人品 if(Number.random(1, 100) < 50) { resp.error("You're unlucky!"); return; } next(); }; module.exports = EchoController; -
“All ciphertext is from Sanae and into Cellar.” –Kochiya Sanae
<The Remilia Bible> 5-3-12, Sanae Ciphertext -
The Cellar (Ver. 1) Fetch wet data from mongodb stored
by Sanae regularly Dry the wet data into useful data and store back to another collection -
The Cellar (Ver. 2) Wait for Illyria Requests. Get data
from Sanae’s storage. Response the data. -
“Cellar is a raw data fetcher & sender. And the
Gate is to peep the raw data to fetch dry information.” –Remilia Scarlet <The Remilia Bible> 6-2-13, Gate T estament -
“The Gate is a hub between the Cellar and the
Koumakan. And the peep hole is the core soul of the Gate.” –Remilia Scarlet <The Remilia Bible> 6-2-13, Gate T estament -
Gate Wait for peep requests. Peep the raw data from
the Cellar. Response the peeped data back. -
“One peep hole per rule. And one rule per hole.”
–Puppets <The Remilia Bible> 9-8-1, Puppet Oath -
“We peep the image links, the site links.” –Puppets <The
Remilia Bible> 9-8-1, Puppet Oath -
“Of cause, we peep the description of that heavenly image.
And we peep the kind of it.” –Puppets <The Remilia Bible> 9-8-1, Puppet Oath -
“At last, don’t forget to peep the raw board name
for it.” –Puppets <The Remilia Bible> 9-8-1, Puppet Oath -
Koumakan The palace puppets live. The magic controls all the
puppets. A puppet owns a Huaban account. Each puppet is independent. -
“Remilia created a factory to create puppets at the first
day.” –<The Remilia Bible> 2-1-1, Factday -
Puppet Manager The puppet factory var PuppetManager = function() {};
PuppetManager.prototype.addPuppets = function() {}; PuppetManager.prototype.startOne = function() {}; …… -
“At the second day, she gave puppets body, blood and
soul.” –<The Remilia Bible> 2-1-2, Thouday -
Puppets builds with Composition Account Composition Peeped Queue Composition Schedule
Composition (Pin) Hand Composition Board Composition … -
Base Composition var BaseComposition = function(puppetId, parent) { EventEmitter.call(this); this.gensokyo
= gensokyo; this.logger = gensokyo.logger; this.puppetId = puppetId; this.parent = parent; }; util.inherits(BaseComposition, EventEmitter); module.exports = BaseComposition; BaseComposition.type = "BaseComposition"; -
Compositions var FooComposition = function(puppetId, parent) { BaseComposition.call(this, puppetId, parent);
}; util.inherts(FooComposition, BaseComposition); … -
So Puppets var Puppet = function(puppetId) { EventEmitter.call(this); this.gensokyo =
gensokyo; this.logger = gensokyo.logger; this.puppetId = puppetId; // 账号组件 this.account = new Compositions.Account(puppetId, this); // 缓存数据队列 this.peepedQueue = new Compositions.PeepedQueue(puppetId, this); // 时间表 this.schedule = new Compositions.Schedule(puppetId, this); // ⼊入库之⽖爪 this.pinHand = new Compositions.PinHand(puppetId, this); // 魔貫光殺砲 ƅЧƅ)σ━00000000000━• … this.logger.info("Puppet " + puppetId + " created."); }; -
“Remilia endued puppets the ability to acquire an outside world,
Huaban at the third day.” –<The Remilia Bible> 2-1-3, Huaday -
Account Composition var AccountComposition = function() {}; AccountComposition.prototype.fetchInformation = function()
{}; AccountComposition.prototype.createAccount = function() {}; AccountComposition.prototype.signIn = function() {}; … -
The Other Sides of the World http://www.qzone.cc/ http://bbs.duowan.com/ Waiting for
you, my new God of creation… -
“Puppets got the ability of peeping from Gate at the
forth day due to Remilia.” –<The Remilia Bible> 2-1-4, Gatday -
Peeped Queue Composition var PeepedQueueComposition = function() {}; PeepedQueueComposition.prototype.nextImage =
function() {}; PeepedQueueComposition.prototype.clean = function() {}; PeepedQueueComposition.prototype.peepCrowd = function() {}; ... -
“Fifth day, Remilia gave puppets the ability to create Boards.”
–<The Remilia Bible> 2-1-5, Boarday -
Board Composition var BoardComposition = function() {}; BoardComposition.prototype.getBoard = function()
{}; BoardComposition.randomStyleName = function() {}; ... -
“Sixth day, puppets got the ability to pin to Huaban
from Remilia.” –<The Remilia Bible> 2-1-6, Pinsday -
“The last day, each puppet made its own schedule to
pin. And Remilia went to rest.” –<The Remilia Bible> 2-1-7, Scheday -
Schedule Composition var ScheduleComposition = function() {}; ScheduleComposition.prototype.genSchedule = function()
{}; ScheduleComposition.prototype.nextCanAndCant = function() {}; ... -
“Let me be like a human!” –Puppets <The Remilia Bible>
2-1-7, Huaday -
“Boom is a Bang to implement interacting with Huaban.” –Remilia
Scarlet <The Remilia Bible> 17-3-8, Big Boom -
“We need a centre control magic!” –Remilia Scarlet <The Remilia
Bible> 21-7-14, Residual Page XIV