private Component Mount(string elementRef, bool replace, bool enableLayouts) { if (Element != null) { throw new InvalidOperationException("Component is already mounted."); } _replaceElement = replace; if (enableLayouts && !string.IsNullOrEmpty(Layout)) { var layoutComponent = RazorComponent.Instantiate(Layout, Context); layoutComponent.BodyComponent = this; layoutComponent.MountAsPage(elementRef); return(layoutComponent); } else { Element = new DOMElement(elementRef); // Render after Init/InitAsync have run synchronously, plus again after // InitAsync's task completes (where applicable) Init(); var initAsyncTask = InitAsync(); Render(); _firstRenderCompletedTask = initAsyncTask?.ContinueWith(_ => { Render(); }); return(this); } }
private Component Mount(string elementRef, bool replace, bool enableLayouts) { if (Element != null) { throw new InvalidOperationException("Component is already mounted."); } _replaceElement = replace; if (enableLayouts && !string.IsNullOrEmpty(Layout)) { var layoutComponent = RazorComponent.Instantiate(Layout, Context); layoutComponent.BodyComponent = this; layoutComponent.MountAsPage(elementRef); return(layoutComponent); } else { Element = new DOMElement(elementRef); // Render after Init/InitAsync have run synchronously, plus again after // InitAsync's task completes (where applicable) Init(); var url = Context.Url; if (url[url.Length - 1] == '/') { url = url.Substring(0, url.Length - 1); } var segments = url.Split(new char[] { '/' }); var idSegments = segments[segments.Length - 1]; int num; Task initAsyncTask; if (idSegments.Length > 0 && int.TryParse(idSegments, out num)) { initAsyncTask = InitAsync(num); } else { initAsyncTask = InitAsync(); } Render(); _firstRenderCompletedTask = initAsyncTask?.ContinueWith(_ => { Render(); }); return(this); } }
internal Component InstantiateAndRegisterChildComponent(int vdomItemIndex) { var vdomItem = builder.Items[vdomItemIndex]; if (vdomItem.ItemType != VDomItemType.Component) { throw new ArgumentException($"vdom item at index {vdomItemIndex} does not represent a child component."); } Component childComponent; if (vdomItem.ComponentInstance != null) { childComponent = vdomItem.ComponentInstance; } else { childComponent = RazorComponent.Instantiate(vdomItem.ComponentName, Context); childComponent.ReceiveParameters(builder.ReadAttributes(vdomItemIndex)); } RegisterChild(childComponent); return(childComponent); }