Skip to content

including files

corneliu edited this page · 9 revisions

entry points

Requests for your application can either be http calls or intervals being triggered (see more about http routing or intervals). For a http request, a controller will be included. If an interval is scheduled to run its coresponding class will get loaded.

All included files will have access to :

  • this.kernel
  • this.instance

Including files is done by calling the .include method, available in both kernel and instance context. Inside the instance context, there are also shortcuts to including models/controllers/intervals. The included object will reside inside the calling context (scroll down to read more about the kernel and instance contexts)

 * Loading via the instance context
function exampleController() {
    //processing input data from get or post
    var modelObj = this.instance.model('example').new(someId);

 * Loading via the kernel context
 function exampleModel(id) {
    //application logic
    var subModelObj = this.kernel.include('models/example/sub').new(id);

kernel and instance contexts

The main difference is that the kernel context is persistent whereas the instance context is short-lived. The kernel is available from the start to the end of the application and stores links, configuration, utility objects (see more about the kernel)

The kernel context is always the same. The instance context depending on its creator can have different methods. For example, the instance context created by the http daemon has post, get, header properties.

The instance context is created when a http request comes in or a new interval is spawned. Once the requests ends or the interval finishes its execution, the instance is terminated and all references destroyed.

new and singleton

Objects can be created as a new entity :

var newObj = this.instance.model('model/path/here').new(param1, param2);

or a singleton :

var singletonObj = this.instance.model('model/path/here').singleton(uniquekey, param1, param2);

Depending on the context in which they are included, singletons can have a wide spread (kernel context, available everywhere) or be boxed inside the instance context.

extension based including

  • .js or no extension : base model as described above
  • .swig : template object (more about templates)
Something went wrong with that request. Please try again.