Skip to content

feature(collection): Add Collection.extendDomain() - #593

Closed
andreialecu wants to merge 1 commit into
deployd:masterfrom
andreialecu:feature-extenddomain2
Closed

feature(collection): Add Collection.extendDomain()#593
andreialecu wants to merge 1 commit into
deployd:masterfrom
andreialecu:feature-extenddomain2

Conversation

@andreialecu

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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

Usage example:

app.js

varCollection=require('deployd/lib/resources/collection');vardeployd=require('deployd');Collection.extendDomain("getColName",function(){returnthis.collection.name;});Collection.extendDomain("hasChanges",function(){vardomain=this.domain;if(_.find(_.keys(domain.data),function(key){returndomain.changed(key);})){returntrue;}returnfalse;});// configure database etc.varserver=deployd({port: process.env.PORT||1337,env: process.env.ENV||'development',db: {connectionString: process.env.MONGO_URI}});// start the serverserver.listen();// debugserver.on('listening',function(){console.log("Server is listening on port: "+(process.env.PORT||1337));});// Deployd requires thisserver.on('error',function(err){console.error(err);process.nextTick(function(){// Give the server a chance to return an errorprocess.exit();});});

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

On POST

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

@ericfong

Copy link
Copy Markdown
Contributor

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

@andreialecu

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

Thanks for your contribution!
Landed as 450b8ad

@ericfongericfong 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 freeto 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

@andreialecu@ericfong