mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? - Previously when creating pointers within a CHASM tree, the pointed-to component had to already exist within the tree, as the pointer was resolved immediately. This was cumbersome in some common cases like setting up an initial tree of CHASM components (such as setting up a scheduler tree), where ideally, all components would be created and linked up within the first transaction. - A new field type, `fieldTypeDeferredPointer`, has been introduced. This field stores the pointer value directly, and resolves the value to the path of the component within the tree during `CloseTransaction` (or fails if the pointer is dangling). ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [x] added new unit test(s) - [ ] added new functional test(s)
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package chasm
|
|
|
|
type fieldInternal struct {
|
|
// These 2 fields are used when node is not set yet (i.e., node==nil).
|
|
// Don't access them directly outside of this file. Use corresponding getters instead.
|
|
ft fieldType
|
|
v any // Component | Data | Pointer
|
|
|
|
// Pointer to the corresponding tree node. Can be nil for the just created fields.
|
|
node *Node
|
|
}
|
|
|
|
func newFieldInternalWithValue(ft fieldType, v any) fieldInternal {
|
|
return fieldInternal{
|
|
ft: ft,
|
|
v: v,
|
|
}
|
|
}
|
|
|
|
func newFieldInternalWithNode(node *Node) fieldInternal {
|
|
return fieldInternal{
|
|
node: node,
|
|
}
|
|
}
|
|
|
|
func (fi fieldInternal) isEmpty() bool {
|
|
return fi.v == nil && fi.node == nil
|
|
}
|
|
|
|
func (fi fieldInternal) value() any {
|
|
// Deferred pointers are special-cased, since their serialized nodes are
|
|
// initialized as regular persistable pointers.
|
|
//
|
|
// Deferred pointers may have a non-nil node after syncSubComponents, but before
|
|
// resolution.
|
|
if fi.node == nil || fi.ft == fieldTypeDeferredPointer {
|
|
return fi.v
|
|
}
|
|
return fi.node.value
|
|
}
|
|
|
|
func (fi fieldInternal) fieldType() fieldType {
|
|
// Deferred pointers are special-cased, since their serialized nodes are
|
|
// initialized as regular persistable pointers.
|
|
//
|
|
// Deferred pointers may have a non-nil node after syncSubComponents, but before
|
|
// resolution.
|
|
if fi.node == nil || fi.ft == fieldTypeDeferredPointer {
|
|
return fi.ft
|
|
}
|
|
return fi.node.fieldType()
|
|
}
|