public void ReactivateComponent(string componentName, string referenceId, IDictionary <string, JsonElement> args) { for (var i = 0; i < _active.Count; i++) { var component = _active[i]; if (component.ComponentName == componentName && component.ReferenceId == referenceId) { _active[i] = new ActiveComponent(componentName, referenceId, component.Component, args); Changed?.Invoke(this, EventArgs.Empty); break; } } }
private int RemoveActivations(Predicate <ActiveComponent> isActivation) { var removed = 0; var last = _active.Count - 1; // Complicated algorithm to still allow Blazor projections to happen, otherwise // we'll end up with some dead references if the element to be removed is not // at the tail. for (var i = last; i >= 0; i--) { var m = _active[i]; // Either we find the component already if (isActivation(m)) { // Then let's decide if we can just remove it or mark it as "deprecated" (still giving it a placeholder) if (last == i) { _active.RemoveAt(i); last--; } else { _active[i] = new ActiveComponent(m.ComponentName, m.ReferenceId); } removed++; } // or we find elements that have been marked, but can now be removed. else if (last == i && m.IsDeleted) { _active.RemoveAt(i); removed++; last--; } } return(removed); }