-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Socket IO not syncing "thing" in default app #2491
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
Comments
ProblemI have researched this issue and found reason why this doesn't work. In thing.events.js file // Register the event emitter to the model events
for(var e in events) {
let event = events[e];
Thing.schema.post(e, emitEvent(event));
} As you can see inside export default mongoose.model('Thing', ThingSchema); SolutionProblem solved when I applied hooks before model created: 'use strict';
import mongoose from 'mongoose';
var ThingSchema = new mongoose.Schema({
name: String,
info: String,
active: Boolean
});
require('./thing.events').applyHooks(ThingSchema);
export default mongoose.model('Thing', ThingSchema); And thing.events.js was modified to export /**
* Thing model events
*/
'use strict';
import {EventEmitter} from 'events';
var ThingEvents = new EventEmitter();
// Set max event listeners (0 == unlimited)
ThingEvents.setMaxListeners(0);
// Model events
var events = {
save: 'save',
remove: 'remove'
};
function emitEvent(event) {
return function(doc) {
ThingEvents.emit(`${event}:${doc._id}`, doc);
ThingEvents.emit(event, doc);
};
}
export function applyHooks(schema) {
// Register the event emitter to the model events
for(var e in events) {
let event = events[e];
schema.post(e, emitEvent(event));
}
}
export default ThingEvents; |
I might be wrong in reasons but this solution works. |
Nice work, Ernisto, thanks! I was able to replicate your solution and it fixes the issue on my heroku deployment. I think you're correct about |
Thank you! I haven't tried older versions. I thought something was broken in |
Closing as duplicate of #2479 |
"Things" in the main view are not syncing automatically when created or deleted, a full page refresh is required to see the updates. I observed this behavior on both OSX 10.12 and on heroku using default settings for the generator at v4.1.2. Just a default build of the generator deployed to heroku should replicate this bug as far as I can tell.
I am not seeing any errors on either the client side or the server side, any suggestions on where to start tracking down this bug?
The text was updated successfully, but these errors were encountered: