public IEnumerable <IObserver <DomEvent> > GetObservers(DomNode node, DomObserverEventScope scope) { var answer = scope.AncestorsAndSelf.SelectMany( s => _items.GetValueOrDefault(s, Array.Empty <DomObserverTarget>()) ); // TODO Should have a heuristic for freeing DomObserverTargets when they are // disposed or their lists become empty return(answer.Where(a => a.AppliesTo(node)).Select(a => a.Observer)); }
private IList <DomObserverTarget> GetItemsForScope(DomObserverEventScope scope) { IList <DomObserverTarget> list; if (!_items.TryGetValue(scope, out list)) { // CopyOnWriteList for observers because it is possible new observers could be added in callbacks _items[scope] = list = new CopyOnWriteList <DomObserverTarget>(); } return(list); }
internal void AttributeValueChanged(DomAttribute attr, DomElement element, string oldValue) { DomAttributeEvent evt = null; foreach (var o in GetObservers(DomObserverEventScope.SpecificAttribute(attr.Name), element)) { if (evt == null) { evt = new DomAttributeEvent(element, attr.Name, oldValue); } o.OnNext(evt); } }
public void RegisterObserver(DomObserver observer, DomNode target, DomScope scope, DomObserverEventScope events) { var list = GetItemsForScope(events); list.Add(new ScopedDomObserverTarget(observer, target, scope)); }
private IEnumerable <IObserver <DomEvent> > GetObservers(DomObserverEventScope s, DomNode node) { return(_observers.GetObservers(node, s)); }