-
Notifications
You must be signed in to change notification settings - Fork 120
Packages
Ready events are simple events that are triggered when a particular system component is ready. For instance, when the routing system is ready to accept routes, as well as the HTTP server, it would call Tower.ready('routing', true)
. Any package that requires the routing functionality, for example, it wouldn't be loaded until all dependencies are ready.
To check if a dependency is ready you can use the asynchronous, or synchronous syntax.
Tower.ready('routing', function(){
// Code here...
});
// or:
Tower.ready('routing'); // true/false
For your packages, you don't need to use either of these APIs, the package system automatically handles dependencies.
Creating a Tower package is extremely simple. The easiest way would be to create a vendor/packages
folder inside one of your Tower applications. This folder is automatically loaded by the package manager.
Create a new folder for your package. For example, if you're writing an authentication package, you would create a authentication
folder. The name of the folder should match your package.
Create a new file named package.js
. This is similar to a package.json
but a little more powerful and advanced because it's in JavaScript.
//package.js
Tower.Package.register(function(){
// Add information to the package.
this.info({
name: "Auth",
description: "Hello, World",
version: "0.0.1",
author: "Daniel Fagnan"
});
this.dependencies(['routing', 'sockets', 'models', 'controllers', 'views', 'templates', 'core']);
// Register files the package is going to use:
this.addFile('client.js', 'client');
this.addFile('server.js', 'server');
this.addFile('shared.js', '*');
// Automatically load these files:
this.init(['server.js']);
});
To API is fairly straight forward. You use this
keyword to access the package API. You first start by giving details about your package, such as the name, version, description, author, etc...
Next, you'll list the system dependencies you need. As previously described in the Ready Events
section, these are all ready events that you need. If you're working on giving extra capabilities to controllers, then you'll want everything before any controllers load or required. Instead of listing every single ready state before the controllers', we have made some aliases that will help you.
this.dependencies(['pre:controllers']);
Anything with pre:
before it, will be loaded before it's ready or started.
If you have any suggestions, please add them below:
- routing
- http
- sockets:initialized
- sockets:connected
- sockets:closed
- controllers
- models
- request
- views
- templates
- watcher
- store
- database
- mailer
- authentication
Again, these are not Hooks, but ready states/events.