Repository navigation
Releases
Releases · NCodeGroup/LiveCollections
v5.1.0
Added
CollectionDiff.Computereturns the items one collection adds to and removes from another as aCollectionDiff<T>, whoseAddedandRemovedcount duplicates and ignore order, under the default or a givenIEqualityComparer<T>.WatchDiffsAsync, an extension member onICollectionDataSource<T>, yields the current items as added and then the items each change added and removed, forawait foreach, and skips a change that adds and removes nothing, such as a reorder (#100, ADR-1033).- Providers and polling sources record metrics and traces on the meter and activity source
NCode.LiveCollections, whose namesLiveCollectionsTelemetry.MeterNameandLiveCollectionsTelemetry.ActivitySourceNamehold. The histogramncode.livecollections.provider.rebuild.durationmeasures each build of a provider's collection in seconds, witherror.typewhen the build throws, andncode.livecollections.polling.refresh.durationmeasures each refresh of a polling source, with itsncode.livecollections.polling.refresh.trigger(timeroron_demand), itsncode.livecollections.polling.refresh.outcome(changed,unchangedorfailed) anderror.typewhen it fails; the spansncode.livecollections.provider.rebuildandncode.livecollections.polling.refreshmirror them. They record to theIMeterFactorythatDefaultCollectionProviderFactory(IMeterFactory)andDefaultCollectionDataSourceFactory(TimeProvider, IMeterFactory)take, which the container picks when the host registers one, or to the one that theMeterFactoryproperty ofCollectionProviderOptionsorPeriodicPollingCollectionDataSourceOptionsnames, and record nothing without one; docs/metrics.md lists each, and the collect metrics and traces guide shows how to turn them on (#103, ADR-1035).
Changed
- Package validation compares each package with the published 5.0.0 package.
- The samples in the readmes and on the documentation site subscribe with
OnChange, which keeps following a source that signals from several threads at once, instead ofChangeToken.OnChange, which can stop following it (#177, ADR-1039). - The documentation site builds with NCodeGroup/docs v0.19.0, which installs its packages with pnpm, and
node build/site.mjstells someone without a toolchain clone to runpnpm install --frozen-lockfilein it (#174). - Updated from project-template v0.175.0 to v0.181.0: agent workflow commands, prompts, skills and agents, the template's scripts and decision records. A maintainer's word in a session authorizes protected paths in a filter run (ADR-0094), and a web frontend uses TypeScript, React and MUI and a documentation site Astro Starlight (ADR-0095).
./build/dod.ps1checks the Markdown links in a Markdown stage, as CI's Markdown checks job does, when Node.js is onPATH, so./build/gate.ps1runs no Markdown link stage of its own and no longer fails without Node.js, andAGENTS.mdsays to put Node.js onPATHfirst, withnvs use 26where nvs manages it (#160).- The NuGet descriptions and readmes of both packages name what each offers.
NCode.LiveCollectionsnames every data source, static, observable, mutable, change-token, composite and periodic polling, theTransform,SelectItems,WhereItems,ConcatSourcesandDebouncesources derived from another, the consumer helpers, the collection diffs, and metrics and traces.NCode.LiveCollections.Abstractionsnames the data source contracts, the factory contracts and the options, theMeterFactoryoptions for metrics and traces included (#166). AGENTS.mdrecords that epic #94's breaking stories shipped together as 5.0.0, and that a story that only adds carries aRelease:line with the next minor version once the major before it has shipped, and none while a new major waits for its last breaking story (#164).
v5.0.0
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>, whichICollectionDataSourceFactory.CreateMutablecreates as anIMutableCollectionDataSource<T>, holds an immutable snapshot of a list your code pushes into from any thread:Replace,Update,Add,AddRange,RemoveandCleareach 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 asRemoveof an absent item, signals nothing, and the source never disposes its items (#96, ADR-1028).ChangeTokenCollectionDataSource<T>, whichICollectionDataSourceFactory.CreateChangeTokencreates, loads its items from a function on the first read and reloads them each time its producer'sIChangeTokensignals, such asIConfiguration.GetReloadToken()orIFileProvider.Watch(...). A failed reload keeps the last items and goes to the optionalhandleException; without one, or when it throws, the source stops reloading (#96, ADR-1029).Transform,SelectItems,WhereItemsandConcatSources, extension members onICollectionDataSource<T>inCollectionDataSourceTransformExtensions, 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 anIDisposableCollectionDataSource<T>that rebuilds an immutable snapshot once per signal of its source and owns its source unlessownsisfalse, so disposing the last link of a chain disposes the whole chain (#97, ADR-1030).Debounce, an extension member onICollectionDataSource<T>inCollectionDataSourceDebounceExtensions, wraps any data source or provider in one that signals once after its source has been quiet forquietPeriod, timed on theTimeProviderit 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 throwsArgumentOutOfRangeException, and it owns its source unlessownsisfalse(#98, ADR-1031).IRefreshableCollectionDataSource<T>, inNCode.LiveCollections.Abstractions, is a disposable data source whoseRefreshAsyncrefreshes 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; aChangedresult 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 throwsObjectDisposedException(#101, ADR-1034).RefreshCollectionResults.ChangedIfDifferent, inNCode.LiveCollections.PeriodicPolling, returnsUnchangedwhen a poll's items equal the current ones in the same order, under the default or a givenIEqualityComparer<TItem>, andChangedotherwise, so a refresh that returns the same items rebuilds nothing downstream (#101, ADR-1034).AddCollectionProvider<TItem, TCollection>andAddKeyedCollectionProvider<TItem, TCollection>, extension members onIServiceCollection, 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, asAddLiveCollections()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 withDispose()orDisposeAsync(), as the container itself is disposed (#104, ADR-1037).WaitForChangeAsync,OnChangeandWatchAsynclet a consumer react to changes withoutChangeToken.OnChangeplumbing.WaitForChangeAsynccompletes on the next change of any data source, provider orISupportChangeToken, and also when the source is disposed while it waits.OnChangecalls 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.WatchAsyncyields the current collection and then the latest one after each change, forawait foreach, without queueing intermediate collections. On a provider,OnChangeandWatchAsynchand over the provider's own collection type (#99, ADR-1032, ADR-1040).PeriodicPollingCollectionDataSourceOptions, inNCode.LiveCollections.Abstractions, holds a polling source's optional settings. ItsMaxBackoffDelaymakes 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 ofMaxBackoffDelayand 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 isnullby default, which keeps the fixed period, and must be at least twice the refresh interval and at most 4,294,967,294 ms.RefreshAsyncruns at once during a wait and neither counts as a failure nor resets it (#102, ADR-1036).
Changed
./build/gate.ps1runs the Markdown check that CI's Markdown checks job runs,node .template/check-markdown.mjs, throughbuild/Assert-MarkdownLinks.ps1, which fails when Node.js isn't onPATH, and the dev container installs Node.js (#158).AGENTS.mdrecords 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:
ICollectionDataSourceFactorygainsCreateMutable, with and without items, andCreateChangeToken, so a class that implements it must add them;DefaultCollectionDataSourceFactorydoes (#96, ADR-1028, ADR-1029). - Package validation compares each package with the published 4.0.0 package.
- Breaking:
ICollectionDataSourceFactory.CreatePeriodicPollingreturnsIRefreshableCollectionDataSource<TItem>, so a class that implements the factory changes the method's return type, asDefaultCollectionDataSourceFactorydoes, 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
Collectionor callsGetChangeToken()getsObjectDisposedException, which the source drops, and a subscription made withChangeToken.OnChangeends 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 ...
v4.0.0
Added
CollectionProviderOptionsandCompositeCollectionDataSourceOptions<T>hold the optional settings of a provider and a composite:AdditionalChangeTokenProducers, which make it rebuild on a signal besides its data sources', such as a configuration reload, and the composite'sCombineFunc.ICollectionProviderFactory.Create,ICollectionDataSourceFactory.CreateCompositeand theCollectionProvider<TItem, TCollection>constructors each have an overload that takes them last, afterowns, so these options no longer need a class derived fromBaseCollectionProvideror a composite built withnew. A later setting is a new property of an options type (#117, ADR-1024).
Changed
- Breaking:
ICollectionProvider<TItem, TCollection>is anIDisposableCollectionDataSource<TItem>, so every provider, whatever its collection type,ImmutableArray<T>and other struct collections included, passes straight to another provider or a composite as a data source. A class that implementsICollectionProvider<TItem, TCollection>itself must addICollectionDataSource<TItem>.Collection, returning the same items as itsCollection;BaseCollectionProvideralready does. An owning outer provider disposes an inner provider like any other source it owns: passowns: false, or give the outer providerCreateComposite([inner], owns: false), to keep the inner provider's lifetime your own (#116, ADR-1023). - Breaking:
ICollectionProviderFactoryandICollectionDataSourceFactorygain the overloads ofCreateandCreateCompositewithoutownsand with options, so a class that implements either interface must add them. The methods and constructors that had an optionalownsparameter take it as a plain parameter, beside an overload without it that passes the same default, so a caller's code compiles and runs as before (#117, ADR-1024). - Breaking: every built-in source hands out a snapshot that never changes after it is returned and is safe to read from any thread, as
ICollectionDataSource<T>.Collectionpromises.ObservableCollectionDataSource<T>.Collectionreturns an immutable copy of the items, taken on each change before the change token signals, instead of theObservableCollection<T>, which its caller keeps to edit it or read it live.CompositeCollectionDataSource<T>enumerates whatCombineFuncreturns once per build into an immutable copy, instead of handing out a query that reads its sources again on each enumeration, and a provider over several sources hands its collection factory an immutable concatenation of their items, so a factory that returns its items as given,items => items, hands out a snapshot too (#118, ADR-1025). - Breaking:
CollectionProvider<TItem, TCollection>,DefaultCollectionDataSourceFactoryandDefaultCollectionProviderFactoryare sealed. A class derived fromCollectionProviderderives fromBaseCollectionProvider<TItem, TCollection>instead and overridesCreateCollection, and one derived from a default factory implementsICollectionDataSourceFactoryorICollectionProviderFactory(#120, ADR-1026). - Breaking:
NullChangeToken.Singletonis typedIChangeToken, andNullChangeTokenhas no public constructor, soSingletonis its one instance: replacenew NullChangeToken()withNullChangeToken.Singleton(#120, ADR-1026). - Updated from project-template v0.173.0 to v0.175.0: agent workflow commands, prompts, skills and agents, the template's scripts and decision records. Every command and prompt, except
execute-step, and the planner, reviewer and orchestrator agents file what a run taught as issues: problems with the template's shipped text go to the repository the newtemplate-feedbackline ofAGENTS.md's Landing section names, and lessons about this project go wherefollow-upssends them (ADR-0092); a plan's follow-up whose files are in another repository is filed there (ADR-0093); and the update names a package'sDescriptionorPackageTagsonly when the build lost it (ADR-0158). - Breaking:
ownshas one meaning and one default: whether a provider or a composite disposes the data sources it is given, and every overload or constructor without it passestrue. A provider over several sources,CreateCompositeandnew CompositeCollectionDataSource<T>(...), whoseOwnsdefaults totrue, dispose their sources by default, as a provider over one source does; passowns: falsefor sources the DI container or the caller still uses.BaseCollectionProvider's constructors takeownsthrough overloads instead of an optional parameter, so a derived class that callsbase(dataSources)owns them. The change departs from the template's ADR-0136 deprecate-then-remove rule and ships in 4.0.0 with the other breaking changes of epic #105 (#121, ADR-1027). - Breaking: A static or observable source disposes its items only when
disposeItemsistrue.disposeItemsreplaces theownsparameter of their constructors,CreateStaticandCreateObservable, and defaults tofalse, so wrapping a caller'sObservableCollection<T>never disposes the caller's items; passdisposeItems: truewhere the source owns them (#121, ADR-1027).
Removed
- Breaking:
AsDataSource()and itsCollectionProviderExtensionsclass are removed: pass the provider itself where a data source is wanted. The change departs from the template's ADR-0136 deprecate-then-remove rule, as ADR-1002 and ADR-1022 did, and ships in 4.0.0 with the other breaking changes of epic #105 (#116, ADR-1023). - Breaking:
INullChangeTokenand its registration byAddLiveCollections()are removed: useIChangeToken, andNullChangeToken.Singletonwhere a token that never signals is wanted, instead of resolving one from the container. The change departs from the template's ADR-0136 deprecate-then-remove rule and ships in 4.0.0 with the other breaking changes of epic #105 (#120, ADR-1026).
v3.0.1
Fixed
- Disposing a provider or a data source from a UI or other context-bound thread no longer resumes its continuations on that thread: every
awaitin the libraries usesConfigureAwait(false), and the build enforces it with CA2007 (#119).
v3.0.0
Changed
- Breaking: Providers and the built-in data sources are both
IDisposableandIAsyncDisposable, so a provider in a DI container that is disposed synchronously, such as withusing var serviceProvider = services.BuildServiceProvider();, no longer throws.ICollectionProvider<TItem, TCollection>gainsIDisposable, so a class that implements it must addDispose();BaseCollectionProvidergainsDispose()and a virtualDisposeCore(), so a subclass that overridesDisposeAsyncCore()must also overrideDisposeCore(), or its own resources are released byDisposeAsync()only.IAsyncDisposableCollectionDataSource<T>is removed, andIDisposableCollectionDataSource<T>is bothIDisposableandIAsyncDisposable:CreateStatic,CreateCompositeandCreatePeriodicPollingreturn it, asCreateObservabledoes, so register a created source withservices.AddSingleton<ICollectionDataSource<T>>(dataSource).Dispose()never waits: the polling source cancels its loop and returns, and an owned source that is onlyIAsyncDisposableis disposed byDisposeAsync()alone, sinceDispose()disposes everything else and then throwsInvalidOperationExceptionfor it.DisposeAsync()disposes what it did before (#115, ADR-1022). The change departs from the template's ADR-0136 deprecate-then-remove rule, as ADR-1002 did, so the release is 3.0.0.
v2.0.10
Changed
- A provider over several data sources subscribes to each of them directly instead of through an internal composite, so a signal swaps the provider's change token once, and the providers, the composite, the observable source and the polling source share one internal implementation of the change-signalling pattern (#114, ADR-1021).
v2.0.9
Fixed
- The
Collectionproperty of aCompositeCollectionDataSource<T>no longer returnsnullwhen the composite is disposed on another thread during the read, and a provider or composite whoseCreateCollectionorCombineFuncdisposes it during the first build no longer caches the built collection:CollectionthrowsObjectDisposedException, as documented (#113, ADR-1020).
v2.0.8
Fixed
- An exception thrown by a consumer's change callback, such as a provider's
CreateCollection, a composite'sCombineFuncor a callback registered on a change token, no longer reaches the code that edited anObservableCollection<T>or the source that signalled a composite or a provider: the source drops it and every other consumer still receives the change (#112, ADR-1019).
v2.0.7
Fixed
- Breaking: An owning static or observable data source disposes each item that implements
IDisposableat run time, whatever the item typeTis declared as: items typed asobject, as an interface withoutIDisposableor as a struct are disposed, and items that don't implement it are skipped.StaticCollectionDataSource<T>is marked disposed whether or not it owns its items, and itsCollectionthrowsObjectDisposedExceptionafterwards, as the other sources' do (#111, ADR-1018).
v2.0.6
Fixed
- Disposing a polling source no longer passes a cancellation to the exception handler when the refresh cancels through a token linked to the one it receives: any
OperationCanceledExceptionthe refresh throws while polling is being stopped ends polling quietly, while one thrown at any other time, such as anHttpClienttimeout, still reaches the handler (#110).