コード例 #1
0
ファイル: AtomTests.cs プロジェクト: Mefodei/UniMob
        public void ThrowException() => TestZone.Run(tick =>
        {
            var source    = Atom.Value(0);
            var exception = new Exception();

            var middle = Atom.Computed(() =>
            {
                if (source.Value == 0)
                {
                    throw exception;
                }

                return(source.Value + 1);
            });

            var stack = new Stack <Exception>();

            var reaction = new ReactionAtom(
                reaction: () => middle.Get(),
                exceptionHandler: ex => stack.Push(ex));

            reaction.Get();

            Assert.AreEqual(1, stack.Count);
            Assert.AreEqual(exception, stack.Peek());
            Assert.Throws <Exception>(() => middle.Get());

            source.Value = 1;
            tick(0);

            Assert.AreEqual(2, middle.Value);
        });
コード例 #2
0
        void IView.SetSource(IViewState newSource)
        {
            using (Atom.NoWatch)
            {
                if (ReferenceEquals(_source.Value, newSource))
                {
                    return;
                }
            }

            if (!(newSource is TState nextState))
            {
                var expected = typeof(TState).Name;
                var actual   = newSource.GetType().Name;
                Debug.LogError($"Wrong model type at '{name}': expected={expected}, actual={actual}");
                return;
            }

            _renderScope.Link(this);

            if (_renderAtom == null)
            {
                _renderAtom = new ReactionAtom(DoRender, OnRenderFailed);
            }

            _hasSource    = true;
            _source.Value = nextState;

            if (!_renderAtom.IsActive)
            {
                _renderAtom.Get();
            }
        }
コード例 #3
0
        public void ThrowException()
        {
            var source    = Atom.Value(0);
            var exception = new Exception();

            var middle = Atom.Computed(() =>
            {
                if (source.Value == 0)
                {
                    throw exception;
                }

                return(source.Value + 1);
            });

            var stack = new Stack <Exception>();

            var reaction = new ReactionAtom(
                debugName: null,
                reaction: () => middle.Get(),
                exceptionHandler: ex => stack.Push(ex));

            reaction.Activate();

            Assert.AreEqual(1, stack.Count);
            Assert.AreEqual(exception, stack.Peek());
            Assert.Throws <Exception>(() => middle.Get());

            source.Value = 1;
            AtomScheduler.Sync();

            Assert.AreEqual(2, middle.Value);
        }
コード例 #4
0
        protected override void Awake()
        {
            base.Awake();

            canvasGroup = GetComponent <CanvasGroup>();

            _interactableReaction = new ReactionAtom("Navigator View Interactable Render", () =>
            {
                //
                canvasGroup.interactable = State.Interactable;
            });
        }