Eve icon indicating copy to clipboard operation
Eve copied to clipboard

Error: Unable to set multiple values on scalar index for key

Open btheado opened this issue 8 years ago • 1 comments

When I run this code and click on "promote 1" or "promote 2", then I see "Uncaught Error: Unable to set multiple values on scalar index for key" error in the console.

If I disable the "Nest the items" section, then the "promote 1" and "promote 2" buttons work as expected (i.e. their title is swapped with the zero title).

Or if their is a branch of the tree with just a single child, then promoting that child works (i.e. only have 0 and 1 in the tree and click "promote 1" or have 0,1,2, and 3 in the tree and click "promote 3". All other promotes fail with the aforementioned error).

So their seems to be an issue when parent-div += child-div inserts 2 siblings and then a change is made.

Create some test items

commit
  [#item idx: 0 title: "0"]
  [#item idx: 1 title: "1"]
  [#item idx: 2 title: "2"]
  //[#item idx: 3 title: "3"]
  //[#item idx: 4 title: "4"]
  //[#item idx: 5 title: "5"]
  //[#item idx: 6 title: "6"]

Make the items into a binary tree by inserting a parent index. Zero is the root; 1 and 2 are the children of 0; 3 and 4 children of 1; etc.

search
	item = [#item idx]
bind
	item.parent := floor[value: (idx - 1) / 2]

Swap item tree position with its parent (i.e. promote it)

search @event @session @browser
  [#click element: [#div #promote pidx]]
  item = [#item idx: pidx]
  parent = [#item idx: item.parent]
  i2 = parent.idx
commit @browser
  [#div children: [#div text: "promote click match for sidx " + pidx]]
commit
  parent.idx := item.idx
  item.idx := i2

Display the items

search
	[#item idx title parent]
bind @browser
  [#div idx text: "{{idx}}, t:{{title}}, p:{{parent}}" 
     style: [padding-left: "10px"]
     sort: idx]

Nest the items

search @browser @session
  child = [#item idx parent]
  child-div = [#div idx]
  parent-div = [#div idx: child.parent]
bind @browser
  parent-div.children += child-div

Add buttons for promoting an item up the hierarchy

search
  [#item idx parent]
  [#item idx: parent]  // Only those items whose parent exists
bind @browser
  [#div children:
    [#div #promote text: "promote " + idx pidx: idx]]

btheado avatar Nov 06 '16 20:11 btheado

Hey @btheado

That error message (which is in desperate need of improvement) means that you have multiple children assigned to the same parent. It blows up since that's invalid DOM.

However, in this case the error is faulty -- your code is doing everything as it should and is never actually assigning multiple parents to the same child. Unfortunately, a fix for one edge case seems to have broken another, and the renderer is just not doing the right thing here. I'll look into it.

joshuafcole avatar Nov 06 '16 21:11 joshuafcole