Closed dottodot closed 9 years ago
Hello.
I think this is the problem:
.fetch({
socketSync: true
})
This is actually an old version of the sync
configuration. You can simply use a single sync
option taking a space delimited set of flags:
.fetch({
sync: 'socket'
})
I would suggest reading the syncing tutorial.
You might try explicitly setting the autowatch
configuration option on the server side blueprints.
Have you included the blueprints under api/blueprints
?
Odd, I've also tried
var lists = new App.Entities.ListCollection;
return lists.query({
where: {
team: team.id
}
}).fetch({
sync: 'socket'
}).then(function() {
lists.on('created', function(data) {
console.log(data);
});
});
and I already had autowatch on as I'd noticed it in your example app.
There is a sails option known as mirror
for the blueprints. It is as of yet undocumented but it is massively important if you want socket events to come back to the client they originate from.
I've made a gripe about it here.
Try setting that to true
.
It wasn't that either. I had added prefix in my blueprint of prefix: '/api'
and on my model was using `modelName: "api/list"``
This works fine for fetching saving etc, but not with socket events.
Ah ok. There is a configuration option dedicated to that.
You'll need to set your model name to list
and then configure the prefix
option globally:
Backbone.Sails.configure({
prefix: '/api'
})
List = Backbone.Sails.Model.extend({
modelName: 'list'
})
I have just ran the tests with this and is all working fine :)
Sorry had completely missed that, all working now.
Hopefully this will be the last of my getting start questions but I can't seem to get any socket events working. I've looked at your example app and can't see the difference that's stopping it working.
In the example below I would expect that once a new list item is saved the "created" event would fire on the lists collection, but nothing is happening.
The only thing I've noticed but not sure if it's related is undefined showing at the end of my socket request i.e.