Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 45 lines (33 sloc) 1.085 kB
676439e @isaacs initial
authored
1 # emcee
2
3 A model loader that a controller calls. Basically, just the M and C
4 bits of MVC.
5
6 An interface for controllers to specify that certain models will be
7 needed, and then have them get loaded.
8
9 ## Usage
10
11 ```javascript
12 var MC = require('emcee')
13
14 // add a bunch of models
15 MC.model('login', function (req, cb) {
16 // callback is called with (er, data)
17 req.session.get('login', cb)
18 })
19
20 MC.model('train', function (url, res, cb) {
21
22 })
23
24 // later on...
25
26 http.createServer(function (req, res) {
27 // check if the user is logged in.
28 var m = new MC()
29
93d6d7b @isaacs Add loadAs for aliasing
authored
30 // modelname, args...
676439e @isaacs initial
authored
31 m.load('login', req)
32 m.load('bike', req.url, res)
93d6d7b @isaacs Add loadAs for aliasing
authored
33 // different kind of bike: modelname, alias, args...
34 m.loadAs('bike', 'motorbike', 'dirt', 'roads')
676439e @isaacs initial
authored
35
36 m.end(function (er, models) {
37 // either there is an error, or all models are loaded on the
38 // 'models' object. note that all errors are assumed to be
39 // catastrophic, so you only get the first error, and the
40 // models object will only contain the models that got loaded
41 // before the error occurred.
42 })
43 }).listen(1337)
44 ```
Something went wrong with that request. Please try again.