Closed cameralibre closed 3 years ago
I've opened a PR with one example of how you could do it. The simplest way, I think, is to replace your object with one where the keys are sorted by default.
So for a keyframe object I grabbed the array of its keys, and sorted this with a helper function.
Then, I reduce the array, which lets us compile it into an object, but this time the keys are sorted.
Then I just replace the targets[id]
object with this new, sorted one.
I've commented the new work, but am happy to talk of it more!
Thanks! I went through it nice and slow to make sure I got it all - javascript.info was useful as usual :)
Sort the order of an object's entries (or at least the order in which they are logged)
Context:
Problem
When I add 0% and 100% keyframes, it creates a new key:value pair, and therefore is logged after existing keyframes.
Before (everything nicely in order):
After adding 0% & 100% keyframes:
Having keyframes listed out-of-order still works as valid CSS but it's not nice for humans trying to debug or alter the animations.
The relevant code: https://github.com/ssbc/visual-docs/blob/3e4a9d6b6f4dff1219abf57915fda594ab91886d/js/convert-anime-to-css.js#L76-L100
Is there some way to sort how Object entries are logged? Or would I have to recreate every entry again, in the correct order, i.e.
This seems a bit over-the-top though...