Git Product home page Git Product logo

dynamicdata.snippets's Introduction

Dynamic Data Snippets

People are always asking me for documents or explanations of dynamic data. However as an open source developer and active family man who works in a high pressure environment, the maintenance and development of my open source projects leaves me with no time to even consider documents.

Thinking about it, why do people always ask for documents. We are developers and we can write and analyse code better than we can produce documents (well most of us anyway). That is why I have created this project, with the aim to:

  • Regard this project as a '101 Samples project'
  • Ensure all examples are unit tested
  • Respond to queries from the community by adding new examples to the project

Support And Contact

The dynamic data chat room is a sub channel the Reactive Inc slack channel. It is an invite only forum so if you want an invite send me a message @ [email protected]. If you would like me to produce an example to help with a particular problem, feel free to contact me on slack to discuss it further.

Links to examples

All these examples have working unit tests which allows for debugging and experimentation

Topic Link Description
AutoRefresh AutoRefreshForPropertyChanges.cs How to force cache operators to recalulate when using mutable objects
Aggregation Aggregations.cs Dynamically aggregrate items in a data source
Creation ChangeSetCreation.cs Create list and cache using first class observables
Filtering StaticFilter.cs Filter a data source using a static predicate
DynamicFilter.cs Create and apply an observable predicate
ExternalSourceFilter.cs Create an observable predicate from another data source
PropertyFilter.cs Filter on a property which implements INotifyPropertyChanged
Grouping CustomTotalRows.cs Illustrate how grouping can be used for custom aggregation
XamarinFormsGrouping.cs Bespoke grouping with Xamarin Forms
GroupAndMonitorPropertyChanges.cs Group on the first letter of a property and update grouping when the property changes
Inspect Collection InspectCollection.cs Produce an observable based on the contents of the datasource
InspectCollectionWithPropertyChanges.cs Produce an observable based on the contents of the data source, which also fires when a specified property changes
InspectCollectionWithObservable.cs Produce an observable based on the contents of the data source, whose values are supplied by an observable on each item in the collection
MonitorSelectedItems.cs Monitor a collection of items which have an IsSelected property and produce observables based on selection
Sorting ChangeComparer.cs How to dynamically sort a collection using an observable comparer
CustomBinding.cs Customise binding behaviour for a sorted data source
Switch SwitchDataSource.cs Toggle between different data sources
Transform FlattenNestedObservableCollection.cs Flatten nested observable collections into an observable data source
Testing ViewModel.cs Illustrates how to test a view model when using dynamic data

Real world examples of Dynamic Data

I have created several Dynamic Data in action projects which illustrates the usage of dynamic data. I encourage people who want to see these real world examples to take a look at the following projects to see the capabilities of Dynamic Data.

Include are:

Dynamic Trader which is an example of how Dynamic Data can handle fast moving high throughput trading data with. It illustrates some of the core operators of dynamic data and how a single data source can be shared and shaped in various ways. It also includes an example of how it can be integrated with ReactiveUI.

Dynamic Trader

TailBlazer is a popular file tail utility which is an example of Rx and Dynamic Data and I consider to be a celebration of reactive programming. It is an advanced example of how to achieve high performance and how to lean on Rx and Dynamic Data to produce a slick and response user interface.

Tail Blazer

DynamicData Samplz where I started to do some visual examples but abandoned the project because I decided that the snippets project would be a better means of providing quick to produce examples. However there are still several good examples so well worth taking a look.

Samplz

dynamicdata.snippets's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dynamicdata.snippets's Issues

Working with 2 dependent ObservableCaches

Scenario: Tagging Items
2 caches: SourceCache, SourceCache
When item changes, it needs to go thru the list of tags to determine which one applies to it.
Similarly, when tag changes, retagging needs to occur.

First not so reactive attempt:

var disposable = tagsCache.Connect().Flatten().Subscribe(change =>
{
Tag tag = change.Current;

_itemCache.Edit(u => {
    if (change.Reason == ChangeReason.Remove)
    {
        foreach (Item item in _itemCache.Items.Where(b => b.Tags.Contains(tag)))
        {
            item.Tags.Remove(tag);
            u.AddOrUpdate(item);
        }
    }
    else
    {
        foreach (Item item in _itemCache.Items)
        {
            Tag existingTag = item.Tags.FirstOrDefault(t => t.Id == tag.Id);
            if (existingTag != null)
            {
                item.Tags.Remove(existingTag);
                u.AddOrUpdate(item);
            }

            bool applies = tag.Applies(item);
            if (applies)
            {
                item.Tags.Add(tag);
                u.AddOrUpdate(item);
            }
        }
    }
});

});

var disposable2 = _itemCache.Connect().WhereReasonsAre(ChangeReason.Add, ChangeReason.Update).Flatten().Subscribe(change =>
{
Item item = change.Current;

instance.Tags.Connect().Flatten().Select(i => i.Current).Subscribe(tag =>
{
    if (!item.Tags.Contains(tag) && tag.Applies(item))
    {
        item.Tags.Add(tag);
    }
});

});

AutoRefresh can't work with a data source defined by interface

I am creating an UI Builder for Blazor and in order to update Blazor when changes occur to the backing ViewModel. In particular, I would like to use the property 'Position' changes within the ComponentViewModel base class. The Position property is updated via a separate Drag/Drop service.

I have an interface for ComponentViewModel called IComponentViewModel which is how I've defined my backing DD SourceList.

private SourceList<IComponentViewModel> _componentViewModelSourceList = new SourceList<IComponentViewModel>();
private ReadOnlyObservableCollection<IComponentViewModel>? _childComponents; 

public CompositeDisposable? Disposables { get; set; }
public IObservable<Position> NewPosition { get; }

Within the constructor I am binding the SourceList to a ReadOnlyObservableCollection 'ChildComponents' as follows, which works great!

            Disposables = new CompositeDisposable();

            Disposables.Add(_componentViewModelSourceList
                .Connect() 
                .ObserveOn(RxApp.MainThreadScheduler) 
                .Bind(out _childComponents)
                .DisposeMany()
                .Subscribe());

Also within the constructor I am attempting to AutoRefresh on changes to the 'Position' property within IComponentViewModel as follows...

var NewPosition = _componentViewModelSourceList.Connect()

             // Subscribe to changes on Position property.
             .AutoRefresh(x => x.Position)
             .Select(); 

however I receive the following error.

CS0311: The type '...IComponentViewModel' cannot be used as a type parameter 'TObject' in the generic method 'IObservableListEx.AutoRefresh<TObject, TProperty> ...'

If I change the SourceList to be the ComponentViewModel then the error goes away, however I would prefer (if possible) to keep it as IComponentViewModel.

Is there some way to add an operator to cast the IObservablable ChangeSet so that I can apply the AutoRefresh with the interface approach.

Thank you in advance.

Refresh clears ListBox selection

Hi, I'm trying to decouple my VMs from WPF libraries and DynamicData seems to be a great way to do that. I've managed to figure out most of what I was doing before using your snippets and examples, but I've hit something I don't know how to solve.

I had two observable collections, one with all the items and another with the items selected in that collection (bound using an attached behaviour on ListView, which worked fine before). I also have a search text filter for these items, but I want to keep the selected items in the list even if they don't match the search text, so my filter method takes both of those things into account.

I have used .AutoRefreshOnObservable(_ => ...) to listen to changes to the search text using this.WhenValueChanged(...) and the selected items observable using .ToObservable(), which is updating the filter correctly, but is also deselecting all my items when it refreshes.

I found two stackoverflow questions which seemed relevant to my issue:

  • Clearing on sort which you already responded to, but isn't the accepted answer (it seems like I want a move rather than remove+insert to keep the item in the selection list)
  • Clearing on add which you also responded to, but resetThreshold: int.MaxValue didn't work for me.

I'd really like to be able to continue using this way of presenting my data to the View, but I can't if the collection clearing on changes is unavoidable, so any assistance would be appreciated, thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.