Exemple #1
0
        public virtual void Deactivate()
        {
            if (children != null)
            {
                for (var i = 0; i < childrenCount; i++)
                {
                    children[i].RemoveSubscriber(this);
                    children[i] = null;
                }

                childrenCount = 0;
                ArrayPool <AtomBase> .Return(ref children);
            }

            if (subscribers != null)
            {
                for (var i = 0; i < subscribersCount; i++)
                {
                    subscribers[i].Obsolete();
                }
            }

            if (options.TryReset(AtomOptions.Active))
            {
                AtomRegistry.OnInactivate(this);
            }

            state = AtomState.Obsolete;
        }
Exemple #2
0
        public void Actualize(bool force = false)
        {
            if (state == AtomState.Pulling)
            {
                throw new CyclicAtomDependencyException(this);
            }

            if (!force && state == AtomState.Actual)
            {
                return;
            }

            if (options.Has(AtomOptions.Disposed))
            {
                Debug.LogError($"Actualization of disposed atom ({this}) can lead to memory leak");
            }

            var parent = Stack;

            Stack = this;

            if (options.TrySet(AtomOptions.Active))
            {
                AtomRegistry.OnActivate(this);
            }

            if (!force && state == AtomState.Checking)
            {
                for (var i = 0; i < childrenCount; i++)
                {
                    if (state != AtomState.Checking)
                    {
                        break;
                    }

                    children[i].Actualize();
                }

                if (state == AtomState.Checking)
                {
                    state = AtomState.Actual;
                }
            }

            if (force || state != AtomState.Actual)
            {
                for (var i = 0; i < childrenCount; i++)
                {
                    children[i].RemoveSubscriber(this);
                    children[i] = null;
                }

                childrenCount = 0;

                Evaluate();
            }

            Stack = parent;
        }