Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change collection.** strange callback arguments #3

Open
ruimgoncalves opened this issue Dec 3, 2014 · 4 comments
Open

change collection.** strange callback arguments #3

ruimgoncalves opened this issue Dec 3, 2014 · 4 comments

Comments

@ruimgoncalves
Copy link

Hi

If I call the change hook like this

  store.hook('change', 'managment.**', function(docId, doc, session, backend) {
  });

the arguments returned to the callback function are wrong. docId is assigned with the OT and I cant get the docId.

I used this workaround

  store.hook('change', 'managment.*.**', function(docId, doc, session, backend) {
  });
@vinnitu
Copy link

vinnitu commented Oct 14, 2015

I get derby-examples/directory app and try to apply

store.hook('create', 'people', ....

But where can I get store?

---- sever.js ----

require('derby-starter').run(__dirname, {port: 8004});

@minicuper
Copy link
Contributor

Derby-starter doesn't provide API to get store. It's just for simple projects. Use generator-derby instead.

@vinnitu
Copy link

vinnitu commented Oct 14, 2015

Ok, done. Here server.js

var async = require('async');
var derby = require('derby');

var http  = require('http');
var chalk = require('chalk');

var publicDir = process.cwd() + '/public';

derby.run(function(){
  require('coffee-script/register');

  require('./server/config');

  var apps = [
    require('./apps/app')
    // <end of app list> - don't remove this comment
  ];

  var express = require('./server/express');
  var store = require('./server/store')(derby, publicDir);

  var error = require('./server/error');

  express(store, apps, error, publicDir, function(expressApp, upgrade){
    var server = http.createServer(expressApp);

    server.on('upgrade', upgrade);

    async.each(apps, bundleApp, function(){
      server.listen(process.env.PORT, function() {
        console.log('%d listening. Go to: http://localhost:%d/',
            process.pid, process.env.PORT);
      });
    });

    function bundleApp (app, cb) {
      app.writeScripts(store, publicDir, {extensions: ['.coffee']}, function(err){
        if (err) {
          console.log("Bundle don't created:", chalk.red(app.name), ', error:', err);
        } else {
          console.log('Bundle created:', chalk.blue(app.name));
        }
        cb();
      });
    }

  });
});

Here I see store, how do you propose use it?
Maybe I need create module like hook.js

module.exports = function(store) {
   require('derby-hook')(store);

   store.hook('create', 'people', function(docId, value, session, backend) {
      model = store.createModel();
      model.fetch ('people.'+docId, function(err){        
        model.set('people.'+docId+'.uuid', 'HERE-MY-UUID-FOR-EXAMPLE');
      })
    });
  } 

and try to use store in server.js

...
  var store = require('./server/store')(derby, publicDir);
  require('./hook')(store); // <---------- Is it right?
...

It's Ok?

@minicuper
Copy link
Contributor

I think it's OK. We use it the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants