Closed mbutsykin closed 2 years ago
I considered implementing it like this, but I wanted to have an API that exposes clearly that the beginning of a sub-variation has been reached. Also, in this way, .next()
and .previous()
are "symmetric", in the sense that aNode.next().previous() === aNode
aNode.previous().next() === aNode
(assuming that aNode
has a parent and a child). With the implementation you propose, it would be possible to have aNode.previous().next()
returns something different from aNode
.
i see, sounds logical) but after you implemented "id" for nodes - imho there is no need in comparing instances directly.
for example here is my UI
you can navigate "back" and "forward" with arrows at the bottom
for current implementation
for "forward" you can do as simple as that:
const [current, setCurrent] = useState<Node>()
function handleNextClick() {
setCurrent(current.next());
}
for "back":
const [current, setCurrent] = useState<Node>()
function handlePrevClick() {
setCurrent(getPrevious(current));
}
function getPrevious(node) {
let previous = node.previous()
if (previous) {
return previous;
}
const parent = node.parentVariation().parentNode();
if (parent) {
return getPrevious(parent);
}
return undefined;
}
seems a bit overwhelmed =/ but i guess it's still fine, just wanted to have it somehow "consistent" your point is definitely valid and it's up to you of course)
btw, i appreciate your work a lot! i have an app for iOS (for iPhone & iPad) that's using your library a lot) can i somehow gift it for you? i can generate "promo code" (redeem in appstore) and send it to you somewhere
Thanks for your enthusiasm and your proposal. Unfortunately, I'm on the Android-side of the Force, thus I won't be able to test your app. ;-)
Maybe it's better to return "parent's" previous node for children variations?