Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Jun 5, 2023
1 parent 3b10404 commit ff614be
Showing 1 changed file with 1 addition and 32 deletions.
33 changes: 1 addition & 32 deletions d2js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"oss.terrastruct.com/d2/d2ast"
"oss.terrastruct.com/d2/d2compiler"
"oss.terrastruct.com/d2/d2format"
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2oracle"
"oss.terrastruct.com/d2/d2parser"
"oss.terrastruct.com/d2/d2target"
Expand Down Expand Up @@ -45,38 +44,8 @@ func jsGetObjOrder(this js.Value, args []js.Value) interface{} {
return string(str)
}

var order []string

queue := []string{""}
for len(queue) > 0 {
curr := queue[0]
queue = queue[1:]
var obj *d2graph.Object
if curr == "" {
obj = g.Root
} else {
mk, err := d2parser.ParseMapKey(curr)
if err != nil {
ret := jsObjOrder{Error: err.Error()}
str, _ := json.Marshal(ret)
return string(str)
}
var ok bool
obj, ok = g.Root.HasChild(d2graph.Key(mk.Key))
if !ok {
ret := jsObjOrder{Error: "not found"}
str, _ := json.Marshal(ret)
return string(str)
}
}
order = append(order, obj.AbsID())
for _, ch := range obj.ChildrenArray {
queue = append(queue, ch.AbsID())
}
}

resp := jsObjOrder{
Order: order,
Order: d2oracle.GetObjOrder(g),
}

str, _ := json.Marshal(resp)
Expand Down

0 comments on commit ff614be

Please sign in to comment.