-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
Subscribe to the same service with different queries. #134
Comments
I managed to get this to work for a simple memory store with simple queries, but should be possible to implement with other stores. |
I think that depends on your implementation. How does it look like at the moment? I see a couple of different ways to make that happen. You could track which parameters the client is listening for and then create some client side logic that keeps the proper list in sync. Or add your own socket events for each parameter combination. You could also add SocketIO rooms although it wouldn't happen in the service but the SocketIO configuration instead. Maybe something like: app.configure(feathers.socketio(function(io) {
var query = { complete: true };
// Create a room for that query (room name is the JSON of `query`)
var room = io.of(JSON.stringify(query));
var todoService = app.service('todos');
// A handler when a Todo has been changed
var todoChanged = function(todo) {
// now find all Todos
todoService.find({ query: query }, function(error, todos) {
// emit a `todos.find` event with the new data
room.emit('todos.find', todos);
});
};
// Listen to all changed
todoService.on('updated', todoChanged);
todoService.on('patched', todoChanged);
todoService.on('created', todoChanged);
todoService.on('removed', todoChanged);
})); |
Hi Daff Thanks for reply Here is my WIP of the LiveQuery service adapter, please bare in mind that this is a ongoing WIP and did not clean the code thus having some comments and console.log in Portuguese. I suppose there is a better way to do this, but my intent was to make an adapter to easily implement any store. For now I'm using memory-store but should be easily ported to support mongo. Now the idea is to add pagination support, and support multiple livequeries per client. I'm using nodemon with coffescript support to run this package. Please be free to use the code in any way you want, and I'll appreciate if you can give me some pointers. Thanks |
You should be able to simply use Those are just a couple ideas off the top of my head. Many ways to skin a cat. Going to close this for now as I don't see us implementing automatic event triggers based on query params. That would start to get crazy. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
Hi
Is it possible to implement a service that keeps its client synced based on its query?
For example, Client A connects to todos collection and asks for completed collections list, Client B connects to the same todos collections but asks for the uncompleted list.
When client B changes one uncompleted item to completed, it should be removed from clients B collection and added to client A.
This should be valid for any query supported by the service.
Is this simple to implement?
Can you give me some pointers to do this?
Thanks.
The text was updated successfully, but these errors were encountered: