Skip to content

Instantly share code, notes, and snippets.

@janl
Last active December 21, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janl/6320157 to your computer and use it in GitHub Desktop.
Save janl/6320157 to your computer and use it in GitHub Desktop.
diff --git a/lib/account_manager.js b/lib/account_manager.js
index a46aa93..c018b4b 100644
--- a/lib/account_manager.js
+++ b/lib/account_manager.js
@@ -17,7 +17,25 @@ exports.start = function (manager, callback) {
var feed = couchr.changes(user_db, {include_docs: true});
feed.on('change', function (change) {
- am.emit('change', change);
+ console.log('handle account change: %j', change);
+ var doc = JSON.parse(JSON.stringify(change.doc));
+ am.emit('change', doc);
+ console.log('emitted `change`');
+ if (!doc.hasOwnProperty('$processedAt')) {
+ am.emit('add', doc);
+ console.log('emitted `add`');
+ }
+ if (doc.type) {
+ var type = doc.type;
+ am.emit('change:' + type, doc);
+ console.log('emitted `change:' + type + '`');
+
+ if (!doc.hasOwnProperty('$processedAt')) {
+ am.emit('add:' + type, doc);
+ console.log('emitted `add:' + type + '`');
+ }
+ }
+ console.log('done handling account change %j', change);
});
am.stop = function (callback) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment