예제 #1
0
        /// <summary>
        /// Queues a mutation record for the corresponding observers.
        /// </summary>
        /// <param name="document">The document to use.</param>
        /// <param name="record">The record to enqueue.</param>
        public static void QueueMutation(this Document document, MutationRecord record)
        {
            var observers = document.Mutations.Observers.ToArray();

            if (observers.Length > 0)
            {
                var nodes = record.Target.GetInclusiveAncestors();

                for (var i = 0; i < observers.Length; i++)
                {
                    var observer           = observers[i];
                    var clearPreviousValue = default(Boolean?);

                    foreach (var node in nodes)
                    {
                        var options = observer.ResolveOptions(node);

                        if (options.IsInvalid)
                        {
                            continue;
                        }
                        else if (node != record.Target && !options.IsObservingSubtree)
                        {
                            continue;
                        }
                        else if (record.IsAttribute && !options.IsObservingAttributes)
                        {
                            continue;
                        }
                        else if (record.IsAttribute && options.AttributeFilters != null && (!options.AttributeFilters.Contains(record.AttributeName) || record.AttributeNamespace != null))
                        {
                            continue;
                        }
                        else if (record.IsCharacterData && !options.IsObservingCharacterData)
                        {
                            continue;
                        }
                        else if (record.IsChildList && !options.IsObservingChildNodes)
                        {
                            continue;
                        }

                        if (!clearPreviousValue.HasValue || clearPreviousValue.Value)
                        {
                            clearPreviousValue = (record.IsAttribute && !options.IsExaminingOldAttributeValue) ||
                                                 (record.IsCharacterData && !options.IsExaminingOldCharacterData);
                        }
                    }

                    if (clearPreviousValue != null)
                    {
                        observer.Enqueue(record.Copy(clearPreviousValue.Value));
                    }
                }

                document.PerformMicrotaskCheckpoint();
            }
        }
예제 #2
0
 public void AddChildMutation(MutationRecord mutation, int childIndex)
 {
     if (childIndex == 1)
     {
         Child1MutationRecord.Add(mutation);
     }
     else if (childIndex == 2)
     {
         Child2MutationRecord.Add(mutation);
     }
     else
     {
         throw new Exception("Invalid child index provided.");
     }
 }
예제 #3
0
 public void Enqueue(MutationRecord record)
 {
     //TODO
     //1. Let interested observers be an initially empty set of MutationObserver objects optionally paired with a string.
     //2. Let nodes be the inclusive ancestors of target.
     //3. Then, for each node in nodes, and then for each registered observer (with registered observer's options as options) in node's list of registered observers:
     //3.1 If node is not target and options's subtree is false, continue.
     //3.2 If type is "attributes" and options's attributes is not true, continue.
     //3.3 If type is "attributes", options's attributeFilter is present, and either options's attributeFilter does not contain name or namespace is non-null, continue.
     //3.4 If type is "characterData" and options's characterData is not true, continue.
     //3.5 If type is "childList" and options's childList is false, continue.
     //3.6 If registered observer's observer is not in interested observers, append registered observer's observer to interested observers.
     //3.7 If either type is "attributes" and options's attributeOldValue is true, or type is "characterData" and options's characterDataOldValue is true, set the paired string of registered observer's observer in interested observers to oldValue.
     //4. Then, for each observer in interested observers:
     //4.1 Let record be a new MutationRecord object with its type set to type and target set to target.
     //4.2 If name and namespace are given, set record's attributeName to name, and record's attributeNamespace to namespace.
     //4.3 If addedNodes is given, set record's addedNodes to addedNodes.
     //4.4 If removedNodes is given, set record's removedNodes to removedNodes,
     //4.5 If previousSibling is given, set record's previousSibling to previousSibling.
     //4.6 If nextSibling is given, set record's nextSibling to nextSibling.
     //4.7 If observer has a paired string, set record's oldValue to observer's paired string.
     //4.8 Append record to observer's record queue.
     //5. Queue a mutation observer compound microtask.
 }