-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge hierarchy package into transform package (#156)
- Loading branch information
Showing
7 changed files
with
236 additions
and
239 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package transform | ||
|
||
import ( | ||
"github.com/yohamta/donburi" | ||
) | ||
|
||
type hierarchyChildrenData struct { | ||
Children []*donburi.Entry | ||
} | ||
|
||
var hierarchyChildrenComponent = donburi.NewComponentType[hierarchyChildrenData]() | ||
|
||
// getHierarchyChildren returns children of the entry. | ||
func getHierarchyChildren(entry *donburi.Entry) ([]*donburi.Entry, bool) { | ||
if cd, ok := getHierarchyChildrenData(entry); ok { | ||
return cd.Children, true | ||
} | ||
return nil, false | ||
} | ||
|
||
// hasHierarchyChildren returns true if the entry has children. | ||
func hasHierarchyChildren(entry *donburi.Entry) bool { | ||
return entry.HasComponent(hierarchyChildrenComponent) | ||
} | ||
|
||
func getHierarchyChildrenData(entry *donburi.Entry) (*hierarchyChildrenData, bool) { | ||
if hasHierarchyChildren(entry) { | ||
c := donburi.Get[hierarchyChildrenData](entry, hierarchyChildrenComponent) | ||
return c, true | ||
} | ||
return nil, false | ||
} |
Oops, something went wrong.