Edit lifecycle

In-depth details on developing your applications using FreeCONF and understanding the sequence of callbacks when editing node structures.

This is an in-depth, advanced description about how Node implementations handle edits.

When initiating an edit on your application you might want to call custom functions to create data structures at the beginning of the edit, at the end or at some point along the way. You might also want to implement custom locking. This document will go thru your options using FreeCONF library.

type Node interface {

    // Hook before an edit is made. opportunity to reject potential edit or create locks
    BeginEdit(r NodeRequest) error

    // Called to navigate and process edits
    Child(r ChildRequest) (child Node, err error)
    Next(r ListRequest) (next Node, key []val.Value, err error)
    Field(r FieldRequest, hnd *ValueHandle) error


    // Hook after an edit is made. opportunity to trigger persistance, finalize edit
    // or free locks
    EndEdit(r NodeRequest) error
}

Edit: Delete a node

[Root]
    [Parent]
        [Target]    <-- Delete Target
            [Child]
                [Child-Child]
NodeBeginEditEnd Edit
Root3. EditRoot=false,New=false,Delete=false6. EditRoot=false,New=false,Delete=false
Parent2. EditRoot=false,New=false,Delete=false5. EditRoot=false,New=false,Delete=false
Target1. EditRoot=true,New=false,Delete=true4. EditRoot=true,New=false,Delete=true

NOTES:

  1. The [Child] and [Child-Child] nodes never get called when their parent is deleted
  2. Every single ancester node of [Target] would be called on every edit no matter how deep the tree was. This would mean you could implement a single global write lock on a [Root] for any write edit if that is what you needed. Or a single write to database of entire tree on any edit.

Edit:Create a new node thru a target node

[Root]
    [Parent]
        [Target]    <-- New Child-Child request passed to Target
            [Child]
                [Child-Child]
NodeBeginEditEnd Edit
Root3. EditRoot=false,New=false,Delete=false10. EditRoot=false,New=false,Delete=false
Parent2. EditRoot=false,New=false,Delete=false9. EditRoot=false,New=false,Delete=false
Target1. EditRoot=true,New=false,Delete=false8. EditRoot=true,New=false,Delete=false
Child4. EditRoot=true,New=false,Delete=false7. EditRoot=true,New=false,Delete=false
Child-Child5. EditRoot=true,New=true,Delete=false6. EditRoot=true,New=true,Delete=false

Edit: Edit leaf on a node

[Root]
    [Parent]
        [Target]    <-- Edit leaf property on Target
            [Child]
                [Child-Child]
NodeBeginEditEnd Edit
Root3. EditRoot=false,New=false,Delete=false6. EditRoot=false,New=false,Delete=false
Parent2. EditRoot=false,New=false,Delete=false5. EditRoot=false,New=false,Delete=false
Target1. EditRoot=true,New=false,Delete=false4. EditRoot=true,New=false,Delete=false