EGreg / Platform-history

The Qbix Platform for powering Social Applications
http://qbix.com/platform
GNU Affero General Public License v3.0
21 stars 5 forks source link

Local Streams #24

Open EGreg opened 10 years ago

EGreg commented 10 years ago

Make a branch for this feature and only merge it in once it's completely tested, maybe even with a test suite.

Right now, there is no way to have the app create streams offline, or post messages to streams when offline. That means all our apps require internet access. Furthermore, it would be nice to have events for "optimistic" feedback and sync.

(It would also be nice to have "undo" and "Streams/read" messages, but that will be a separate issue.)

Streams.create can return a Streams.Stream with stream.local = true . If we don't use it, then it will be garbage collected later. We should have onSaved event (Streams.Stream.prototype.onSaved and Streams.Stream.onSaved(type)) which fires whenever the stream has been successfully saved on the server.

Until then, you can stream.post( ) messages, set/get/clear attributes, and set .pendingFields to be saved later. All these things would trigger the usual local events, but wouldn't sync to any other devices or users.

There should be a method for setting .pendingFields, called stream.field(name [, value]), and if a pending field changes, an event fires called onPendingFieldChanged There should also be an event called Streams.Message.onPost(type, mtype) which fires when a message attempts to be posted, and gets the Q.Promise returned from the getter Message.post