Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reference property from inside implicit collection without dot notation #350

Closed
LeaVerou opened this issue Jun 15, 2018 · 5 comments
Labels

Comments

@LeaVerou
Copy link
Member

Testcase: https://codepen.io/leaverou/pen/GGMxGo?&editors=1100#0

@LeaVerou LeaVerou added the bug label Jun 15, 2018
@betaveros
Copy link
Contributor

Something very strange is happening in the codepen and I'm not sure it's the same issue that the issue title is describing any more. It looks like the two prop properties are displaying, in order, the last and the second prop in the supplied numbers JSON literal, and the [prop] outside is just displaying those two.

What is the intended behavior? Should [prop] output the props from the JSON or just the two props that exist in the HTML?

@betaveros
Copy link
Contributor

Hmm, I see the issue that referencing the property only shows a single value if I delete the mv-storage option from the mv-app tag, or if mv-storage="local" and it's a fresh load. Things seem to work as intended after saving to local storage and loading again. Things do not work with the explicitly specified JSON data in the mv-storage value as described above; some kind of reordering appears as noted in my last comment. Something pretty weird is happening.

@betaveros
Copy link
Contributor

Some debugging: Without any data to load from, Mavo.all.appName.root.liveData.data.numbers.prop is a Proxy on "11", but if there is data then it's null and Mavo.all.appName.root.liveData.data.numbers[Mavo.route]["prop"] is true.

@betaveros
Copy link
Contributor

With regards to the property only showing a single value when there's no mv-storage, I think it's ultimately an initialization order bug. As the root Group creates the ImplicitCollection, when it adds the second "numbers" node, ImplicitCollection.add creates the node and then pushes it to this.children. Unfortunately the calls to update parent data objects all occur during the creation of the node, so ImplicitCollection is told to update its data before it ever pushes the new node to this.children, and updates its data based on the out-of-date copy of this.children that only has one element. By the time it does push the new node to this.children, it's too late. An easy fix is to call this.liveData.update(); after this.children.push(item); in ImplicitCollection.add.

I have not yet diagnosed the issue that occurs with the mv-storage being set to the explicit JSON value.

@betaveros
Copy link
Contributor

betaveros commented Oct 27, 2018

Sigh, the bug is that in the mv-storage attribute

<div mv-app="appName" mv-storage='data:application/json,{
	"numbers": [{"prop": 1}, {"prop": 2}, {"prop": 3}]
	}'>

the JSON list is being parsed as a Mavo expression because it's in brackets. The comma operator just yields the last expression so, after parsing, you end up with the JSON

{
	"numbers": {"prop": 3}
}

The behavior is weird because the mv-storage result is evaluated once before the Mavo expression is parsed, loading 1 and 2 over the properties, and then once after, which only loads 3 over the first property and doesn't touch the 2 in the second.

I don't know what the best way to solve this issue is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants