Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        public void RegisterObserver(DomObserver observer, DomNode target, DomScope scope, DomObserverEventScope events)
        {
            var list = GetItemsForScope(events);

            list.Add(new ScopedDomObserverTarget(observer, target, scope));
        }
Exemplo n.º 5
0
 private IEnumerable <IObserver <DomEvent> > GetObservers(DomObserverEventScope s, DomNode node)
 {
     return(_observers.GetObservers(node, s));
 }