Conversation
The range() syntax currently only allows for one range per Observed<vector<T>>. Which is a huge usability problem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix multi ranges - PR changelog
Summary
Observed<T>now lets multiple consumers subscribe to the same container without stepping on each other. Previously,RangeEventContextwas a producer-side singleton on theObserved, so twoNui::range(vec)subscribers shared one diff state and eachconsume-and-resetraced the other: only the first subscriber to render saw the update.This PR moves
RangeEventContextto be per-consumer, owned by eachBasicObservedRenderer, and has the producer broadcast change events to all live readers.Example:
Breaking changes
ObservedContainer::rangeContext()(both overloads) removed — the range event context is now an implementation detail of range rendering, not a property of the observed value.ObservedContainerconstructors takingRangeEventContext&&(4 overloads) removed.These were unused outside the test suite; if you somehow held one, replace with the default constructor.
Because of that I consider this change not major version increasing, because its likely 0 impact.
Behavior changes
Nui::range(observed)subscribers over the sameObserved<vector|deque|string|set|list>now all stay in sync across mutations. Previously the second-and-later subscribers would silently fall behind.Observed<set>andObserved<list>automatically opt their attached reader contexts intodisableOptimizations=true, since their non-random-access iteration model can't replay the optimized diff path.New API
ObservedContainer::attachReaderContext(std::shared_ptr<RangeEventContext> const&): called by range renderers during attachment.ObservedContainer::readerContextCount(): raw size of the reader vector (debug/test helper).RangeEventContext::setDisableOptimizations(bool): replaces the removed boolean constructor.Tests
MultiSubscriber_*tests covering every mutating op (push/pop front+back, emplace, insert ×4 overloads, erase ×2, resize ×3, indexed-assign, iterator-deref-assign, swap, assign, full reassignment, clear+repopulate).SubscriberLifetime_Detach,SubscriberLifetime_DiesMidBroadcast,FiveSubscribers_RandomMutations,InteractionAcrossSubscribers,OperatorAssignBetweenContainers,Map_Set_Deque_MultiSubscriber,MoveAssignedObservedHasNoSubscribers,RepeatedIndexedAssignAtSamePosition.Test mock fixes
replaceWithnow actually replacesself's entry in the parent'schildren/childNodesarrays (was previously redirectingself's sharedReferenceType, which only worked for the first replace at any DOM position; subsequent replaces became invisible to the parent).replaceWith's no-parent fallback (used for rootsetBody) also rebindsdocument.bodyto the new value whenselfis the current body, so chained body replacements within a single test no longer leavedocument.bodypointing through a stale reference chain.Dependencies
interval-treeto the latest pinned commit.Test results
405 passing, 0 disabled