Skip to content

v5.0.0

Choose a tag to compare

@github-actions github-actions released this 06 Dec 02:58
· 113 commits to main since this release
f387556

Added

  • Decision records ADR-1028 to ADR-1037 settle the design of the mutable and change-token data sources, the derived sources and Debounce, the consumer helpers and item-level diffs, on-demand polling refresh, change detection and backoff, metrics and traces, and the DI helper that registers providers (#95).
  • MutableCollectionDataSource<T>, which ICollectionDataSourceFactory.CreateMutable creates as an IMutableCollectionDataSource<T>, holds an immutable snapshot of a list your code pushes into from any thread: Replace, Update, Add, AddRange, Remove and Clear each swap it under the source's lock and signal once, so a batch of edits is one provider rebuild. A call that changes nothing, such as Remove of an absent item, signals nothing, and the source never disposes its items (#96, ADR-1028).
  • ChangeTokenCollectionDataSource<T>, which ICollectionDataSourceFactory.CreateChangeToken creates, loads its items from a function on the first read and reloads them each time its producer's IChangeToken signals, such as IConfiguration.GetReloadToken() or IFileProvider.Watch(...). A failed reload keeps the last items and goes to the optional handleException; without one, or when it throws, the source stops reloading (#96, ADR-1029).
  • Transform, SelectItems, WhereItems and ConcatSources, extension members on ICollectionDataSource<T> in CollectionDataSourceTransformExtensions, derive a live data source from any data source or provider: they reshape the whole collection, map or filter its items, or concatenate several sources. Each returns an IDisposableCollectionDataSource<T> that rebuilds an immutable snapshot once per signal of its source and owns its source unless owns is false, so disposing the last link of a chain disposes the whole chain (#97, ADR-1030).
  • Debounce, an extension member on ICollectionDataSource<T> in CollectionDataSourceDebounceExtensions, wraps any data source or provider in one that signals once after its source has been quiet for quietPeriod, timed on the TimeProvider it is given, so a burst of edits is one provider rebuild. When the quiet period ends it reads its source once and hands out that snapshot until the next burst settles, a read that throws keeps the last snapshot and signals nothing, a quiet period outside 1 to 4,294,967,294 milliseconds throws ArgumentOutOfRangeException, and it owns its source unless owns is false (#98, ADR-1031).
  • IRefreshableCollectionDataSource<T>, in NCode.LiveCollections.Abstractions, is a disposable data source whose RefreshAsync refreshes it at once, such as right after a write. PeriodicPollingCollectionDataSource<TItem, TState> implements it: a call waits for a refresh that is running, then runs one of its own, and never overlaps the timer's; a Changed result signals before the call returns; an exception from the refresh goes to the caller, never to the exception handler, and polling goes on; the caller's token cancels the wait and the refresh, and after disposal the call throws ObjectDisposedException (#101, ADR-1034).
  • RefreshCollectionResults.ChangedIfDifferent, in NCode.LiveCollections.PeriodicPolling, returns Unchanged when a poll's items equal the current ones in the same order, under the default or a given IEqualityComparer<TItem>, and Changed otherwise, so a refresh that returns the same items rebuilds nothing downstream (#101, ADR-1034).
  • AddCollectionProvider<TItem, TCollection> and AddKeyedCollectionProvider<TItem, TCollection>, extension members on IServiceCollection, register a collection provider in one call as a singleton that the given factory builds, optionally under a service key that the factory also gets, and add the library's services that are missing, as AddLiveCollections() does. Every call adds a registration and the last one wins a single resolution, the provider is registered as no other service type, and the container disposes it with Dispose() or DisposeAsync(), as the container itself is disposed (#104, ADR-1037).
  • WaitForChangeAsync, OnChange and WatchAsync let a consumer react to changes without ChangeToken.OnChange plumbing. WaitForChangeAsync completes on the next change of any data source, provider or ISupportChangeToken, and also when the source is disposed while it waits. OnChange calls a callback with the new collection on each change until its subscription is disposed, and keeps following a source that signals from several threads at once. WatchAsync yields the current collection and then the latest one after each change, for await foreach, without queueing intermediate collections. On a provider, OnChange and WatchAsync hand over the provider's own collection type (#99, ADR-1032, ADR-1040).
  • PeriodicPollingCollectionDataSourceOptions, in NCode.LiveCollections.Abstractions, holds a polling source's optional settings. Its MaxBackoffDelay makes a source whose exception handler returns back off after a failed timer refresh: the n-th failure in a row waits a random time from half to all of the smaller of MaxBackoffDelay and the refresh interval doubled n times, so the first wait is one to two intervals, and after the next refresh that succeeds the timer ticks again one interval later. It is null by default, which keeps the fixed period, and must be at least twice the refresh interval and at most 4,294,967,294 ms. RefreshAsync runs at once during a wait and neither counts as a failure nor resets it (#102, ADR-1036).

Changed

  • ./build/gate.ps1 runs the Markdown check that CI's Markdown checks job runs, node .template/check-markdown.mjs, through build/Assert-MarkdownLinks.ps1, which fails when Node.js isn't on PATH, and the dev container installs Node.js (#158).
  • AGENTS.md records that a breaking change ships in a new major version, with several breaking stories shipping together as one, and that a public method or constructor with overloads takes no optional parameter (#158).
  • Breaking: ICollectionDataSourceFactory gains CreateMutable, with and without items, and CreateChangeToken, so a class that implements it must add them; DefaultCollectionDataSourceFactory does (#96, ADR-1028, ADR-1029).
  • Package validation compares each package with the published 4.0.0 package.
  • Breaking: ICollectionDataSourceFactory.CreatePeriodicPolling returns IRefreshableCollectionDataSource<TItem>, so a class that implements the factory changes the method's return type, as DefaultCollectionDataSourceFactory does, and code built against an earlier version is recompiled (#101, ADR-1034).
  • Breaking: Disposing a provider or a built-in data source signals the change token it handed out once, after it has released everything else, so a consumer waiting on the token learns that the source is gone instead of waiting for its own cancellation token. A change callback that runs on that signal and reads Collection or calls GetChangeToken() gets ObjectDisposedException, which the source drops, and a subscription made with ChangeToken.OnChange ends without calling its consumer; a callback that must tell the disposal apart from a change catches that exception. StaticCollectionDataSource<T>'s token never signals, disposal included. ISupportChangeToken's docs and the custom data source samples show a source of your own cancelling its token before it disposes it (#162, ADR-1038).
  • Breaking: ICollectionDataSourceFactory.CreatePeriodicPolling has three overloads, none with an optional parameter: the four required parameters, those plus handleExceptionAsync, and those plus a PeriodicPollingCollectionDataSourceOptions. A class that implements the factory adds the new ones, as DefaultCollectionDataSourceFactory does (#102, ADR-1036).
  • Breaking: PeriodicPollingCollectionDataSource<TItem, TState> has four constructors, none with an optional parameter: the four required parameters, then handleExceptionAsync, then timeProvider, then a PeriodicPollingCollectionDataSourceOptions. A call that names timeProvider without a handler passes null for handleExceptionAsync (#102, ADR-1036).

Fixed

  • The packages' CompatibilitySuppressions.xml files are UTF-8 without a byte order mark, and docs/api-compatibility.md says to save a generated one that way (#155).
  • A provider, a composite, a derived source, a debounced source and a change-token data source keep following their sources when those signal from several threads at once; before, such a subscription could stop for good, so the collection stopped updating and never signalled again (#168, ADR-1039).
  • An exception from a provider's or a composite's rebuild is dropped also when a change token producer outside the library signalled the rebuild, such as an extra change token producer, as it is for the library's own sources, and never reaches that producer; the rebuild keeps the previous collection (#168, ADR-1039).