The Simplicity: Create an observable tree Herein I will illustrate how the operator is used and then walk through a working example. It has been implemented and released on Nuget as beta version. I have called this new operator TransformToTree. This means there is absolutely no need for recursion within the operator which has led to good performance. Part 1 and part 3 of this algorithm can be achieved with existing operators which left me to implement part 2 in a single iteration. The output is the cache of nodes filtered so that only nodes with no parent are included in the result.As each node in the cache changes look back into the cache to find the parent and add / remove from the parent accordingly.For each item in the flat list create a cache of nodes.The algorithm can be made easy as follows: My mind was melting trying to find a better solution, then I realised creating and maintaining a nested structure does not necessarily have to be so mind numbingly complex as I first suspected. The code was simple but alas had poor performance as each node had to create a filter from the original cache. I quickly got this solution working as I was able to implement it using a combination of the existing dynamic data filter and transform operators. My first solution was to create a node which applied a filter to find its children and in turn each child also applied a filter to find its children. To ensure accurate reflection of underling data.For every item there has to be a node which has references to both the parent and child nodes, and these have to be maintained as changes are received. For this to hold true for a recursive hierarchy is an extreme challenge. The contract of dynamic data guarantees any operator will reflect items which are added, updated or removed from its source collection. However the more I looked into the problem the bigger the challenge become and I started to doubt whether I could pull it off. I quickly identified the need for a new ‘convert a stream to a tree’ operator so I took the challenge to implement it. I immediately replied yes of course without weighing up in advance what the solution could be. This complacency was shaken when recently I was asked if it was possible to use Dynamic Data to convert a flat observable data stream to a fully hierarchical structure. It is so functionally rich I always assume that there is not a lot that it cannot do. For this post I assume familiarity with Dynamic Data or at least familiarity with some of my previous posts, so for those of you who are not already familiar with dynamic data see What is dynamic data? for a brief overview.ĭynamic data has evolved over several years where each new operator has been created to overcome a necessity for a practical problem which I have been working on.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |