symbiont
v1.0.0
Published
Symbiont is a class constructor for symbiose package (a symbiont is like a bundle but for Node.JS app)
Downloads
2
Readme
Symbiont
A symbiont is similar to a npm module but a symbiont can be directly used in Symbiose framework (like a bundle in Symfony). Check the list of third-party symbionts.
Creating a Symbiont
With command
You can use symbiose-generator, this will make a folder in package folder and update dependencies list in your package.json.
cd ./path/to/symbiose/project/
npm install symbiose-generator
symbiose-generator my-new-package --make-package
Manual
Move to your Symbiose project folder.
Create your package folder
Create a folder my-new-package in ./package/
and generate a package.json with npm init
. Your main script (by default is index.js) have to return an instance of Symbiont class.
Example for index.js:
const Symbiont = require('symbiont')
const myPackage = new Symbiont()
//your code
module.exports = myPackage
And create these folders: ./config/
, ./controller/
, ./model/
and ./view/
.
Register your package
You have to register your package in dependencies of package.json in your Symbiose project. Like that:
'dependencies': {
'my-new-package': 'file:./package/my-new-package'
}
API
Symbiont.registerController(controllerName, controller)
- controllerName (String): The name of the controller. Should be unique in your package.
- controller (Object): Controller object used to route views.
Example
const Symbiont = require('symbiont'),
path = require('path')
const resolve = (filename) => path.resolve(__dirname, 'controller', filename)
const myPackage = new Symbiont()
myPackage.registerController('home', require(resolve('home.js')))
Symbiont.registerEventListener(eventName, listener)
- eventName (String): The name of the event.
- listener (Function): The callback function.
Example
const Symbiont = require('symbiont')
const myPackage = new Symbiont()
myPackage.registerEventListener('onRequest', () => {
console.log('new request!')
})
Symbiont.on(eventName, listener)
Alias of registerEventListener.