internal static IDisposable SetupSearchModelEventsObserver(NodeSearchModel model, IEventController controller, ILibraryViewCustomization customization, int throttleTime = 200) { customization.SpecificationUpdated += (o, e) => controller.RaiseEvent("libraryDataUpdated"); var observer = new EventObserver <NodeSearchElement, IEnumerable <NodeSearchElement> >( elements => NotifySearchModelUpdate(customization, elements), CollectToList ).Throttle(TimeSpan.FromMilliseconds(throttleTime)); Action <NodeSearchElement> handler = (searchElement) => { var libraryViewController = (controller as LibraryViewController); if ((libraryViewController != null) && (libraryViewController.disableObserver)) { return; } observer.OnEvent(searchElement); }; Action <NodeSearchElement> onRemove = e => handler(null); //Set up the event callback model.EntryAdded += handler; model.EntryRemoved += onRemove; model.EntryUpdated += handler; //Set up the dispose event handler observer.Disposed += () => { model.EntryAdded -= handler; model.EntryRemoved -= onRemove; model.EntryUpdated -= handler; }; return(observer); }