Skip to content

Conversation

@andreialecu
Copy link
Contributor

Static function that allows adding values or functions to the domains of all collection instances.

Replaces #315

Static function that allows adding values or functions to the domains of all collection instances.

Replaces deployd#315
@andreialecu
Copy link
Contributor Author

You have access to this.collection and this.domain from inside any extensions defined using this method.

Usage example:

app.js

var Collection = require('deployd/lib/resources/collection');
var deployd = require('deployd');

Collection.extendDomain("getColName", function(){
  return this.collection.name;
});

Collection.extendDomain("hasChanges", function(){
  var domain = this.domain;
  if (_.find(_.keys(domain.data), function(key) {
    return domain.changed(key);
  })) {
    return true;
  }
  return false;
});

// configure database etc.
var server = deployd({
    port: process.env.PORT || 1337,
    env: process.env.ENV || 'development',
    db: {
        connectionString: process.env.MONGO_URI
    }
});

// start the server
server.listen();

// debug
server.on('listening', function () {
    console.log("Server is listening on port: " + (process.env.PORT || 1337));
});

// Deployd requires this
server.on('error', function (err) {
    console.error(err);
    process.nextTick(function () { // Give the server a chance to return an error
        process.exit();
    });
});

You can then use those defined functions in your event scripts, example:

On POST

   emit(getColName() + ":post", this);

@ericfong
Copy link
Contributor

WOW. Great Feature!!!
But seems need to wait for 592 being rebased first?

@andreialecu
Copy link
Contributor Author

Yeah, it has a bit of dependency on #592. I can decouple if needed, but I also have another PR I need to send after these three which is related to AfterCommit as well.

So let's merge #592 first, that's easier.

@ericfong
Copy link
Contributor

ericfong commented Jul 2, 2015

Thanks for your contribution!
Landed as 450b8ad

@ericfong ericfong closed this Jul 2, 2015
andreialecu added a commit to andreialecu/deployd that referenced this pull request Jul 10, 2015
PR deployd#593 Collection.ExtendDomain wouldn't work with Collection.AfterCommit and UserCollection.Login events.

Fixed it for consistency.
@andreialecu andreialecu deleted the feature-extenddomain2 branch November 3, 2017 12:39
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

Successfully merging this pull request may close these issues.

2 participants