Example #1
0
        /// <summary>
        /// Must be called whenever a node value is changed externally, for example when a property node's backing field changes its value.
        /// </summary>
        public void WasChanged(object source)
        {
            if (!Enabled)
            {
                return;
            }

            ReactiveManager.GetNode(source).NotifyChildren();
            (source as IListener)?.Notify();
        }
        /// <summary>
        /// Indicate that the given variable was read. May cause other objects to become dependend on the given variable.
        /// </summary>
        public void WasRead(object source)
        {
            if (!Enabled)
            {
                return;
            }

            if (DependentsEvaluating.Count != 0)
            {
                var weakDependent = DependentsEvaluating.Peek().Dependency;
                ReactiveManager.GetNode(source).Add(weakDependent);
            }
        }
Example #3
0
        /// <summary>
        /// Must be called whenever a node value is changed externally, for example when a property node's backing field changes its value.
        /// </summary>
        public void WasChanged(object source)
        {
            if (!Enabled)
            {
                return;
            }

            ReactiveManager.GetNode(source).NotifyChildren(notifyList);
            foreach (IListener toNotify in notifyList)
            {
                toNotify.Notify();
            }
            notifyList.Clear();
            (source as IListener)?.Notify();
        }
        static void WasChangedForChild(Dependency childEdge)
        {
            var child = childEdge.Value;

            if (child == null)
            {
                return;
            }

            var childNode = ReactiveManager.GetNode(child);

            if (childNode.notificationsHad == childEdge.NotificationsHad)             //Determines if the edge is still up-to-date.
            {
                childNode.WasNotified();
                child.Notify();
                childNode.NotifyChildren();
            }
        }
Example #5
0
        static void WasChangedForChild(ref Chain <IListener> result, IDependency childEdge)
        {
            var child = childEdge.Value;

            if (child == null)
            {
                return;
            }

            var childNode = ReactiveManager.GetNode(child);

            if (childNode.notificationsHad == childEdge.NotificationsHad) //Determines if the edge is still up-to-date.
            {
                childNode.WasNotified();
                result = new Chain <IListener>(child, result);
                childNode.NotifyChildren(ref result);
            }
        }
Example #6
0
        /// <summary>
        /// Evaluation of reactive nodes must pass through this method.
        /// </summary>
        public T Evaluate <T>(IListener dependent, Func <T> func)
        {
            if (!Enabled)
            {
                return(func());
            }

            WasRead(dependent);

            var node = ReactiveManager.GetNode(dependent);
            var dependentReference = node.GetDependency(dependent);

            DependentsEvaluating.Push(dependentReference);
            var result = func();

            DependentsEvaluating.Pop();
            return(result);
        }