symbiont

1.0.0 • Public • Published

Symbiont

NPM Version NPM Downloads Linux Build Test Coverage

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.

Readme

Keywords

none

Package Sidebar

Install

npm i symbiont

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.15 kB

Total Files

4

Last publish

Collaborators

  • a-312