-
Notifications
You must be signed in to change notification settings - Fork 45
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
Bug in ~key? #71
Comments
Nope. The two things of In general,
╰─➤ yarn install
The program 'yarn' is currently not installed. You can install it by typing:
sudo apt install cmdtest
zsh: command not found: yarn
╰─➤ apt show cmdtest 1 ↵
Package: cmdtest
Version: 0.22-1
Priority: optional
Section: universe/python
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Lars Wirzenius <liw@liw.fi>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 78.8 kB
Depends: python (>= 2.7), python (<< 2.8), python-cliapp, python-ttystatus, python-markdown
Homepage: http://liw.fi/cmdtest/
Download-Size: 18.8 kB
APT-Sources: http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
Description: blackbox testing of Unix command line programs Uh, do you actually use cmdtest? o.O |
From looking at the code though that you posted above, div ~key:(string_of_int counter.value) [] That alone would be fine since EDIT: Think of Oh, and yes, if using a key it will also efficiently re-order nodes as well. |
This and this explain the use of keys. Basically if you have:
and you swap them to
it is guaranteed that the DOM nodes will be swapped underneath and their attributes will not be reassigned. This is required when doing e.g. CSS transitions or "unmanaged inputs" in React. Is there an equivalent feature in bs-tea? |
Also, if this:
changes to:
It's guaranteed that the |
Ah, this is actually a bit like "lazy" in Elm. "key" in all frameworks I know work like I described above. This is important if some attribute is externally modified to make sure that the nodes are moved instead of reused. |
Now that I think, |
It looks like you do reapply attributes if the key remains the same. The only difference to make this match with the behavior of key in pretty much every framework I know is to diff the children as well. Here's a test case. If you run it you'll see that the
|
Actually the same thing will happen in this case as well. The issue you were running in to was changing a part of the children without updating the key as well.
To guarantee a swap you use I'm thinking maybe it is good to split these functions into 3 parts instead of 2... it keeps growing... >.>
Lazy exists as well, though it does not function like key. Key is more like a mapping key (more functional terminology than web terminology) in that if it matches it skips further testing. Lazy prevents the VDOM from even being created at all if it's own key matches the past, each have their own non-overlapping purposes for various efficiency reasons.
Yeah that's why I think I need a third element. I'm thinking
In a sense, but using lazy involves making a closure, which is more efficient in some cases and less efficient in other cases...
Nah, all good. :-)
Nice! I've done quite a load of changes since my last personal benchmarking so this is good to see that it still remains faster than Elm. It should always be faster than React just because React cannot make immutable assumptions about the VDom that Elm and we can. :-) I'm worried about that partial update test, that should be something that runs really really well... I'll need to look in to that... Memory allocation is high because of all the list usage. If I were to switch to using array's instead of lists it would require typing Do you have a repo of these benchmarks that I could run? |
I think
Elm uses lists as well and in Elm they have a more complicated representation than what BuckleScript produces AFAIK. Maybe there's some other reason?
Yep: https://github.com/utkarshkukreti/js-framework-benchmark/tree/bucklescript-tea Note that the numbers can't really be compared right now because this benchmark is for keyed nodes. Non keyed nodes are apparently usually faster as they can reuse more nodes than keyed ones. |
Except As well as
Bucklescript may be doing some excess allocations, rather I think the allocations may be smaller but potentially more, which may not be bad anyway since they are all statically shaped (which is fantastic for javascript JIT'ing reasons).
Yeah key'ing is good for certain reasons, but it is harmful in others. Subbed to it. :-) |
Yeah that makes sense. One key (pun!) difference is that HTML's
Yes, it's essential to prevent this though. The current "~key" feature in bs-tea is probably pretty unique though -- I haven't seen it before. |
Honestly I want it to be unique per page when possible anyway, in a later 'side-design' I want it to allow moving a key'd element anywhere around on a page instead of just among side-siblings. :-) So
Heh, it was a feature I needed in my work project... ^.^; Also, wouldn't I don't actually have much experience in javascript frameworks so this design is really far more black-boxed then most, I come from the server and systems development world rather than the javascript-horror world... ^.^; /me so SO badly wants webassembly to take over! |
I'm not sure what |
Yep, key does that here too currently, though I think that functionality should be moved to |
Hi!
Is
~key:_
supposed to work the same askey
in React/Value andkeyed
in Elm? If yes, I have created a test case where some nodes' values are not updated even if the model changes. Here's the code:and repo: https://github.com/utkarshkukreti/bs-tea-key-bug (just run
yarn install && yarn start
and then open the link webpack prints).If you press "+", you'll see the correctly incremented value logged to the console but the text display of the counter does not update! If I remove
~key
it updates fine.The text was updated successfully, but these errors were encountered: