github.com/vugu/vugu@v0.3.6-0.20240430171613-3f6f402e014b/mod-check-common.go (about)

     1  package vugu
     2  
     3  // ModChecker interface is implemented by types that want to implement their own modification tracking.
     4  // The ModCheck method is passed a ModTracker (for use in checking child values for modification if needed),
     5  // and the prior data value stored corresponding to this value (will be nil on the first call).
     6  // ModCheck should return true if this instance is modified, as well as a new data value to be stored.
     7  // It is up to the specific implementation to decide what type to use for oldData and newData and how to
     8  // compare them.  In some cases it may be appropriate to return the value itself or a summarized version
     9  // of it.  But for types that use lots of memory and would otherwise take too much time to traverse, a
    10  // counter or other value can be used to indicate that some changed is occured, with the rest of the
    11  // application using mutator methods to increment this value upon change.
    12  type ModChecker interface {
    13  	ModCheck(mt *ModTracker, oldData interface{}) (isModified bool, newData interface{})
    14  }
    15  
    16  // NewModTracker creates an empty ModTracker, calls TrackNext on it, and returns it.
    17  func NewModTracker() *ModTracker {
    18  	var ret ModTracker
    19  	ret.TrackNext()
    20  	return &ret
    21  }
    22  
    23  type mtResult struct {
    24  	modified bool
    25  	data     interface{}
    26  }