New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bookshelf-signals

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bookshelf-signals

A Bookshelf plugin that translates all models and collection events to a single hub

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

bookshelf-signals

The Bookshelf plugin that translates bookshelf events to a central hub. By default that hub is a bookshelf instance itself. That's useful if you want to subscribe to an event but don't want to modify model or collection initializer.

Sample code:

Signals = require 'bookshelf-signals'
db = bookshelf(knex)
db.plugin Signals()

class User extend db.Model
  tabeName: 'users'

db.on 'saved', User, ->
  console.log 'user was saved!'

Plugin

db.plugin Signals(hub)

Argument passed to plugin is a hub to that all bookshelf events will be translated. It should at least implement methods trigger and triggerThen. If undefined then events will be translated to bookshelf instance and required methods will be added to it.

Default implementation

Default hub implementation has a behaviour different from EventEmitter. Its methods on, addListener, once, off, removeListener, removeAllListeners accepts class or model/collection name as a second parameter and performs events filtration according to it.

Methods:

  • on(String event, [(Class|String) cls], Function handler)

    Subscribe to event with optional filtration by source class.

  • addListener - alias for on

  • removeListener(String event, [(Class|String) cls], Function handler)

    Unsubscribe from event. If class/name was used for subscription you have to use the same class/name to unsubscribe.

  • off - alias for removeListener

  • once(String event, [(Class|String) cls], handler)

    Subscribe to first event of that type and source class, if filtered.

  • removeAllListeners([String event], [(Class|String) cls])

    Unsubscribe all listeners for that event and source class.

Keywords

FAQs

Package last updated on 11 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc