Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

possibly a need for a target? #3

Open
wants to merge 1 commit into from

2 participants

@joshuairl

No description provided.

@olalonde
Owner

Hey, thanks Joshua. Yes we definitely need to have a target. I will look at your pull request, sounds good. I will also write a blog post shortly describing this module and where I want to go with it. Cheers!

@joshuairl

Awesome Ola, excited to read.
Ttyl~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 28, 2012
  1. added a 'target' option

    Joshua Rountree authored
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 4 deletions.
  1. +9 −3 index.js
  2. +17 −1 test/index.js
View
12 index.js
@@ -1,4 +1,4 @@
-var Notification = function (actor, verb, object) {
+var Notification = function (actor, verb, object, target) {
if (!actor || !verb) {
throw new Error('Actor and Verb parameters are mandatory');
}
@@ -6,6 +6,7 @@ var Notification = function (actor, verb, object) {
this.actor = actor;
this.verb = verb;
this.object = object;
+ this.target = target;
this.time = new Date();
};
@@ -13,16 +14,21 @@ var Notif = function() {
this._handlers = [];
};
-Notif.prototype.send = function (actor, verb, object, cb) {
+Notif.prototype.send = function (actor, verb, object, target, cb) {
if (typeof object === 'function') {
cb = object;
object = null;
}
+ console.log(arguments);
+ if(typeof target === 'function') {
+ cb = target;
+ target = null;
+ }
if (typeof cb !== 'function') {
cb = function () {};
}
- var notification = new Notification(actor, verb, object);
+ var notification = new Notification(actor, verb, object,target);
this._executeHandlers(notification, cb);
};
View
18 test/index.js
@@ -1,11 +1,22 @@
var notif = require('../');
var oli = {
+ objectType:'user',
username: 'olalonde'
},
bobby = {
+ objectType: 'user',
username: 'bobby'
- };
+ },
+ project = {
+ objectType:'project',
+ myName:'My Project'
+ }
+ ,
+ picture = {
+ objectType:'photo',
+ name:'Nuts and Bolts'
+ }
notif.register(function (n, cb) {
console.log(n.actor.username + ' ' + n.verb + ' ' + ((n.object && n.object.username) ? n.object.username : ''));
@@ -17,6 +28,10 @@ notif.register({ only: ['registered', 'deleted account'] }, function (n, cb) {
console.log('Send an email because ' + n.actor.username + ' ' + n.verb);
});
+notif.register({only: ['uploaded']}, function (n, cb) {
+ console.log(n.actor.username + ' ' + n.verb + ' a ' + n.object.objectType + ' to ' + n.target.myName);
+});
+
notif.register({ except: ['deleted account'] }, function (n, cb) {
console.log(n.verb + ' === good news!');
});
@@ -24,3 +39,4 @@ notif.register({ except: ['deleted account'] }, function (n, cb) {
notif.send(bobby, 'registered');
notif.send(bobby, 'followed', oli);
notif.send(bobby, 'deleted account');
+notif.send(bobby, 'uploaded', picture, project);
Something went wrong with that request. Please try again.