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.
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
Move to your Symbiose project 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/
.
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'
}
- controllerName (String): The name of the controller. Should be unique in your package.
- controller (Object): Controller object used to route views.
const Symbiont = require('symbiont')
const path = require('path')
const myPackage = new Symbiont()
const getController = (filename) => {
const filepath = path.resolve(__dirname, 'controller', filename)
const Controller = require(filepath)
return new Controller()
}
myPackage.registerController('home', getController('home.js'))
module.exports = myPackage
- eventName (String): The name of the event.
- listener (Function): The callback function.
const Symbiont = require('symbiont')
const myPackage = new Symbiont()
myPackage.registerEventListener('onRequest', () => {
console.log('new request!')
})
module.exports = myPackage
Alias of registerEventListener.