Skip to content

Commit 7c11319

Browse files
committed
change API for backend
1 parent 1074c19 commit 7c11319

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ server.js
1010

1111
```js
1212

13-
// Add 'hook' and 'onQuery' functions to the store
14-
derby.use(require('sharedb-hooks'));
15-
or
16-
racer.use(require('sharedb-hooks'));
13+
// Add 'hook' and 'onQuery' functions to the backend
14+
require('sharedb-hooks')(backend);
1715

1816
// ...
1917
```
@@ -22,24 +20,24 @@ then you can use the function to hook model events, for example:
2220

2321
```js
2422

25-
store.hook('create', 'todos', function(docId, value, session, backend) {
26-
model = store.createModel();
23+
backend.hook('create', 'todos', function(docId, value, session, backend) {
24+
model = backend.createModel();
2725
model.fetch ('todos.'+docId, function(err){
2826
var time = +new Date();
2927
model.set('todos.'+docId+'.ctime', time);
3028
})
3129
});
3230

33-
store.hook('change', 'users.*.location', function(docId, value, op, session, backend){
34-
model = store.createModel()
31+
backend.hook('change', 'users.*.location', function(docId, value, op, session, backend){
32+
model = backend.createModel()
3533
console.log('User change location HOOK');
3634

3735
// ....
3836

3937
});
4038

41-
store.hook('del', 'todos', function(docId, value, session, backend) {
42-
model = store.createModel();
39+
backend.hook('del', 'todos', function(docId, value, session, backend) {
40+
model = backend.createModel();
4341

4442
// ....
4543

@@ -48,6 +46,6 @@ then you can use the function to hook model events, for example:
4846

4947
```
5048

51-
## MIT License 2015
49+
## MIT License 2016
5250

5351

index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11

2-
module.exports = function(racer) {
3-
racer.on('store', function(store) {
4-
store.hook = hook.bind(store);
5-
store.onQuery = onQuery.bind(store);
6-
});
2+
module.exports = function(backend) {
3+
backend.hook = hook.bind(backend);
4+
backend.onQuery = onQuery.bind(backend);
75
};
86

97
function onQuery(collectionName, cb) {
10-
var store = this;
11-
var emitter = store.backend || store.shareClient;
8+
var backend = this;
129

13-
emitter.use('query', function (shareRequest, next) {
10+
backend.use('query', function (shareRequest, next) {
1411

1512
var session = shareRequest.agent.connectSession;
1613

@@ -27,10 +24,9 @@ function onQuery(collectionName, cb) {
2724

2825

2926
function hook(method, pattern, fn) {
30-
var store = this;
31-
var emitter = store.backend || store.shareClient;
27+
var backend = this;
3228

33-
emitter.use('after submit', function (shareRequest, next) {
29+
backend.use('after submit', function (shareRequest, next) {
3430
var collectionName, firstDot, fullPath, matches, regExp, relPath, segments, op;
3531

3632
var opData = shareRequest.opData || shareRequest.op;

0 commit comments

Comments
 (0)