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

:each breaks after object state change but works fine with arrays #12

Closed
garuse opened this issue Jan 6, 2024 · 6 comments
Closed

:each breaks after object state change but works fine with arrays #12

garuse opened this issue Jan 6, 2024 · 6 comments

Comments

@garuse
Copy link

garuse commented Jan 6, 2024

Updates of object values is breaking :each but works with array updates (flems.io playground example http://tinyurl.com/25skdzrj):

<div id="container">
<div>
    State obj: <div :text="JSON.stringify(obj)"></div>
    Each obj: <div :each="o in obj" :text="o"></div> <!-- this breaks -->
  </div>
  <div>
    Direct obj access:
    <div :text="obj.a"></div>
    <div :text="obj.b"></div>
  </div>
<hr/>
 <div>
    State arr: <div :text="JSON.stringify(arr)"></div>
    Each arr: <br/><div :each="o in arr" :text="o"></div>
  </div>
  <div>
    Direct arr access:
    <div :text="arr[0]"></div>
    <div :text="arr[1]"></div>
  </div>
</div>

<script type="module">
  import sprae from 'https://cdn.jsdelivr.net/npm/sprae/sprae.js'
  const state = sprae(container, {obj: {a:'vala', b:'valb'}, arr: [1,2], JSON: JSON})
  state.obj.a = 'newvala' // :each not working after this
  state.arr[0] = 42
</script>

The result is:

State obj:
{"a":"newvala","b":"valb"}
Each obj:
Direct obj access:
newvala
valb
------------------------------------
State arr:
[42,2]
Each arr:
42
2
Direct arr access:
42
2

and I expected:

State obj:
{"a":"newvala","b":"valb"}
Each obj:
newvala
valb
Direct obj access:
newvala
valb
------------------------------------
State arr:
[42,2]
Each arr:
42
2
Direct arr access:
42
2

Because of this I am still using petite-vue but I would have preferred sprae instead.
I really appreciate your work, especially the latest performance improvements!
Thank you!

@dy
Copy link
Owner

dy commented Jan 6, 2024

Thanks for the report. Will have a look

@dy
Copy link
Owner

dy commented Jan 6, 2024

Thanks for the report! Fixed in 8.1.0.
Note though: it's more efficient to iterate over arrays than objects, for big amounts of data.
Also: if you add new props to object, they won't be caught up. Lmk if that's something needed.

@dy dy closed this as completed Jan 6, 2024
@garuse
Copy link
Author

garuse commented Jan 6, 2024

Also: if you add new props to object, they won't be caught up. Lmk if that's something needed.

Indeed that will fit my use case and will be consistent with other frameworks.
Thank you for the quick fix!

@dy
Copy link
Owner

dy commented Jan 6, 2024

Ok, added in 8.1.1.

@garuse
Copy link
Author

garuse commented Jan 6, 2024 via email

@dy
Copy link
Owner

dy commented Jan 6, 2024

You're welcome, try and lmk.
There's one opportunity of overall perf improvement by reducing API, so possibly major release will be a bit terser but more performant.

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

No branches or pull requests

2 participants