public void RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
        {
            // A component might be in the render queue already before getting disposed by an
            // earlier entry in the render queue. In that case, rendering is a no-op.
            if (_componentWasDisposed)
            {
                return;
            }

            // Swap the old and new tree builders
            (CurrentRenderTree, _renderTreeBuilderPrevious) = (_renderTreeBuilderPrevious, CurrentRenderTree);

            CurrentRenderTree.Clear();
            renderFragment(CurrentRenderTree);

            var diff = RenderTreeDiffBuilder.ComputeDiff(
                _renderer,
                batchBuilder,
                ComponentId,
                _renderTreeBuilderPrevious.GetFrames(),
                CurrentRenderTree.GetFrames());

            batchBuilder.UpdatedComponentDiffs.Append(diff);
            batchBuilder.InvalidateParameterViews();
        }
Beispiel #2
0
        public bool TryDisposeInBatch(RenderBatchBuilder batchBuilder, out Exception exception)
        {
            _componentWasDisposed = true;
            exception             = null;

            try
            {
                if (Component is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // We don't expect these things to throw.
            RenderTreeDiffBuilder.DisposeFrames(batchBuilder, CurrentRenderTree.GetFrames());

            if (_hasAnyCascadingParameterSubscriptions)
            {
                RemoveCascadingParameterSubscriptions();
            }

            DisposeBuffers();

            return(exception == null);
        }
Beispiel #3
0
        private void CleanupComponentStateResources(RenderBatchBuilder batchBuilder)
        {
            // We don't expect these things to throw.
            RenderTreeDiffBuilder.DisposeFrames(batchBuilder, CurrentRenderTree.GetFrames());

            if (_hasAnyCascadingParameterSubscriptions)
            {
                RemoveCascadingParameterSubscriptions();
            }

            DisposeBuffers();
        }
        public void DisposeInBatch(RenderBatchBuilder batchBuilder)
        {
            _componentWasDisposed = true;

            // TODO: Handle components throwing during dispose. Shouldn't break the whole render batch.
            if (Component is IDisposable disposable)
            {
                disposable.Dispose();
            }

            RenderTreeDiffBuilder.DisposeFrames(batchBuilder, CurrrentRenderTree.GetFrames());

            if (_hasAnyCascadingParameterSubscriptions)
            {
                RemoveCascadingParameterSubscriptions();
            }
        }
Beispiel #5
0
        public void RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, out Exception?renderFragmentException)
        {
            renderFragmentException = null;

            // A component might be in the render queue already before getting disposed by an
            // earlier entry in the render queue. In that case, rendering is a no-op.
            if (_componentWasDisposed)
            {
                return;
            }

            _nextRenderTree.Clear();

            try
            {
                renderFragment(_nextRenderTree);
            }
            catch (Exception ex)
            {
                // If an exception occurs in the render fragment delegate, we won't process the diff in any way, so child components,
                // event handlers, etc., will all be left untouched as if this component didn't re-render at all. The Renderer will
                // then forcibly clear the descendant subtree by rendering an empty fragment for this component.
                renderFragmentException = ex;
                return;
            }

            // We don't want to make errors from this be recoverable, because there's no legitimate reason for them to happen
            _nextRenderTree.AssertTreeIsValid(Component);

            // Swap the old and new tree builders
            (CurrentRenderTree, _nextRenderTree) = (_nextRenderTree, CurrentRenderTree);

            var diff = RenderTreeDiffBuilder.ComputeDiff(
                _renderer,
                batchBuilder,
                ComponentId,
                _nextRenderTree.GetFrames(),
                CurrentRenderTree.GetFrames());

            batchBuilder.UpdatedComponentDiffs.Append(diff);
            batchBuilder.InvalidateParameterViews();
        }
Beispiel #6
0
        public bool TryDisposeInBatch(RenderBatchBuilder batchBuilder, [NotNullWhen(false)] out Exception?exception)
        {
            _componentWasDisposed = true;
            exception             = null;

            try
            {
                if (Component is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            CleanupComponentStateResources(batchBuilder);

            return(exception == null);
        }
 public ParameterViewLifetime(RenderBatchBuilder owner)
 {
     _owner = owner;
     _stamp = owner.ParameterViewValidityStamp;
 }