DJDNS / go-deje

Golang library for DEJE Next, a protocol/technology for decentralized document hosting and concurrent editing.
GNU Lesser General Public License v2.1
8 stars 0 forks source link

SimpleClient struct for higher-level application needs #10

Closed MaddieM4 closed 10 years ago

MaddieM4 commented 10 years ago

Right now, the Client object is pretty low-level. Which is good, you want a low-level option for situations that require custom solutions. But when I was about to switch over to working on DJDNS, I realized that a lot of the code I would be writing would actually be general-purpose for any naive DEJE client.

With that in mind, I'd like to expose a simpler and higher-level interface, so that DJDNS doesn't have to dig too deep into DEJE, and the work there will be able to be used for any DEJE client app (and probably become the preferred interface).

// Automatically sets up an OnConnect handler to sync current state
type SimpleClient struct {
    Client
}

// Set the callback for when changes are applied to the document content
func (sc SimpleClient) SetPrimitiveCallback(c state.OnPrimitiveCallback) {
    ...
}

// Broadcast to the network: "What is the current tip event's hash?"
func (sc SimpleClient) RequestTip() {
    ...
}

// Broadcast to the network: "The current tip event has hash XXXX"
//
// Automatically does this when a tip request comes in, but you should
// also do it after creating new changes
func (sc SimpleClient) PublishTip(event_hash string) {
    ...
}

// Broadcast to the network: "Give me event XXXX and all its ancestors"
func (sc SimpleClient) RequestHistory(event_hash string) {
    ...
}

// Broadcast to the network: "Here is event XXXX and all its ancestors"
func (sc SimpleClient) PublishHistory(event_hash string) {
    ...
}

// Get exported value of document.
func (sc SimpleClient) Export() interface{} {
    ...
}

You can see how naive and simple this early protocol is - no, it won't stay this way forever. This is just a nice, comprehensible stepping stone towards the finished protocol. However, SImpleClient will still be present in some form for the finished protocol, just with the appropriate API changes.