CharlesHolbrow / synk

support syncing data with browser
0 stars 0 forks source link

Simplify object Creation, Modification, Deletion interface #7

Closed CharlesHolbrow closed 7 years ago

CharlesHolbrow commented 7 years ago

right now to create a new object

n := &eternal.Note{SubKey: "eternal:main"}

err := synkConn.NewObjectID(n)
if err != nil {
    fmt.Println("Error getting ID:", err)
    return
}

msg := synk.NewObj{Object: n}

rConn := synkConn.Pool.Get()
synk.HandleMessage(msg, rConn)
rConn.Close()

We could change the NewObj to a method that just creates a new object. This could probably be simplified to

n := &eternal.Note{SubKey:"eternal:main"}
conn := synkConn.Pool.Get()
defer conn.Close()
synk.NewObject(obj) // If needed this would call: n.ID := synk.NewID(n.TypeKey())

(see #6 for how to generate object IDs)

For now, I would like to still keep the option to pass objects as messages. It would be nice to do all our processing in a separate thread from the thread were we talk to redis.

CharlesHolbrow commented 7 years ago

This involves two changes:

func NewObject(obj, rConn) err // Actually Create the Object in redis
func NewObjectMessage(obj), NewObjectMsg // send NewObjectMsg to "HandleMessage""

I do not think that the following actually need to be exported

MsgModObj
MsgAddObj
MsgRemObj
CharlesHolbrow commented 7 years ago

closed by 131c778