data
data copied to clipboard
Additional event hooks
In order to promote the event-driven use of this framework, it would be nice to have finer-grained event hooks.
Suppose I'm making a system whereby graph updates are pushed from the server to the client, how would I be able to listen for additions/removals/changes to the graph?
One possibility would be to merge() them in with the dirty flag set, but this would not reflect the fact that the server (the authority over clean/dirty) has pushed them to the client and that they are therefore clean. This means that it would be difficult to detect the addition of clean nodes to the graph. Is this something that could be hacked together with the concept of conflicting nodes?
I really like the graph-oriented nature of this data framework and look forward to seeing 0.3!
Hi!
Good points. The addition of a realtime (push) mode is on the list for 0.3 (0.4 at the latest). We're going to introduce swappable transport modes (Websockets, if available with a fallback AJAX polling when not available). We already detect conflicts based on _rev properties when sending node updates to the server. We'd do the same in the opposite direction.
If you'd like to help out, you could suggest possible API's for the realtime scenario, complete with possible events. (as code snippets). I'd love to get some examples we can then discuss. Looking forward. :)
I'm currently hacking on this. The API I have in mind looks like this:
graph.watch("task_updates", {"type|=": "/type/task", "project": "/project/foo"}, function(err, nodes) {
// Update the UI appropriately as nodes arrive
});
This registers a listener on the server that watches for node updates of "/type/task" nodes related to a particular project, specified as a regular query object. If another client saves a node related to this project all other watching clients are notified immediately.
Thoughts?
The first parameter is a unique name for the watcher. You can use it to unbind your registration.
graph.unwatch('task_updates')
Also when you call watch
a second time using the same watcher name, it gets replaced with the new one.
You can check progress of 0.3.0 at https://github.com/michael/data/tree/realtime.
I'm working on putting together an alternate server that uses DNode instead of now.js. The reason for this is that cloud9 doesn't yet support binary modules such as node-proxy. You can keep abreast of this work in my fork.
Actually, I think we don't really need RMI at all. Maybe we should consider using Socket.IO directly, keeping dependencies to a minimum and reducing overhead. Nowjs was just the easiest way to get started. :)
What do you think?
Shifted to 0.5.0