开发者社区> 镜像站> NPM> sharedb-hooks
sharedb-hooks
ShareDb hooks
Last updated a year ago by zag2art .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sharedb-hooks 
SYNC missed versions from official npm registry.

sharedb-hooks

The way to hook db-interactions on the server

Usage

First you should require the package and init it:

server.js

  
  // Add 'hook' and 'onQuery' functions to the backend 
  require('sharedb-hooks')(backend);
  
  // ...

then you can use the function to hook model events, for example:

  
  backend.hook('create', 'todos', function(docId, value, session, backend) {
    model = backend.createModel();
    model.fetch ('todos.'+docId, function(err){
      var time = +new Date();
      model.set('todos.'+docId+'.ctime', time);
    })
  });
  
  backend.hook('change', 'users.*.location', function(docId, value, op, session, backend){
    model = backend.createModel()
    console.log('User change location HOOK');
    
    // ....
    
  });
  
  backend.hook('del', 'todos', function(docId, value, session, backend) {
    model = backend.createModel();
    
    // ....
    
  });
  
  

MIT License 2016

Current Tags

  • 4.0.0                                ...           latest (a year ago)

9 Versions

  • 4.0.0                                ...           a year ago
  • 3.0.5                                ...           2 years ago
  • 3.0.4                                ...           3 years ago
  • 3.0.3                                ...           3 years ago
  • 3.0.2                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Today 0
This Week 1
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (1)
Dev Dependencies (0)
None