mardi 16 janvier 2018

Recommended Pattern for Observing Changes in Tree Structure

I have a view-model with a tree structure that I wish to use with an NSOutlineView. NSTreeControllers and bindings don't play particularly nicely with animations for NSOutlineViews (See: Using NSTableView Animations with Bindings) which means that using an NSTreeController doesn't simplify code if I want to control animation. I would end up tracking items in the view and the view-model anyway.

I would like to observe updates to the view-model from the view-controller myself, but I am not aware if there is an established pattern that I could/should use.

Basically I want to react to changes in many possible tree-nodes at a single point. If any tree-nodes gain or lose children, I want to insert or remove an item in my NSOutlineView.

The methods of an NSOutlineView for a view-based implementation would suit this approach very well. insertItems(at:inParent:withAnimation:) does not take the items to insert, but queries the model for data. So, I need to get some sort of event for indexes added/removed from any node in the tree.

Can anyone suggest possible patterns with pros and cons please?

I writing for OSX using Swift 4. Thank you.

Aucun commentaire:

Enregistrer un commentaire