Skip to content

Commit 8d2e5e6

Browse files
alxhubatscott
authored andcommitted
refactor(core): remove experimental renderComponent function (angular#46605)
This commit removes the experimental `renderComponent` operation, which implemented an alternative, lighter-weight bootstrapping option. This experiment is being discontinued as the path towards it being a supported production API was not clear. In particular, it lacked a clear roadmap for supporting Angular's change detection, particularly when consuming existing components. PR Close angular#46605
1 parent 1434ba9 commit 8d2e5e6

File tree

3 files changed

+5
-75
lines changed

3 files changed

+5
-75
lines changed

packages/core/src/core_render3_private_export.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export {
6363
NgModuleType as ɵNgModuleType,
6464
NO_CHANGE as ɵNO_CHANGE,
6565
PipeDef as ɵPipeDef,
66-
renderComponent as ɵrenderComponent,
6766
RenderFlags as ɵRenderFlags,
6867
setClassMetadata as ɵsetClassMetadata,
6968
setLocaleId as ɵsetLocaleId,

packages/core/src/render3/component.ts

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,23 @@
99
// We are temporarily importing the existing viewEngine from core so we can be sure we are
1010
// correctly implementing its interfaces for backwards compatibility.
1111
import {Injector} from '../di/injector';
12-
import {Type} from '../interface/type';
1312
import {Sanitizer} from '../sanitization/sanitizer';
1413
import {assertDefined, assertIndexInRange} from '../util/assert';
1514

16-
import {assertComponentType} from './assert';
17-
import {getComponentDef} from './definition';
1815
import {diPublicInInjector, getOrCreateNodeInjectorForNode} from './di';
1916
import {throwProviderNotFoundError} from './errors_di';
2017
import {registerPostOrderHooks} from './hooks';
21-
import {addToViewTree, CLEAN_PROMISE, createLView, createTView, getOrCreateTComponentView, getOrCreateTNode, initTNodeFlags, instantiateRootComponent, invokeHostBindingsInCreationMode, locateHostElement, markAsComponentHost, refreshView, registerHostBindingOpCodes, renderView} from './instructions/shared';
22-
import {ComponentDef, ComponentType, RenderFlags} from './interfaces/definition';
18+
import {addToViewTree, CLEAN_PROMISE, createLView, getOrCreateTComponentView, getOrCreateTNode, initTNodeFlags, instantiateRootComponent, invokeHostBindingsInCreationMode, markAsComponentHost, registerHostBindingOpCodes} from './instructions/shared';
19+
import {ComponentDef, RenderFlags} from './interfaces/definition';
2320
import {TElementNode, TNodeType} from './interfaces/node';
2421
import {PlayerHandler} from './interfaces/player';
2522
import {Renderer, RendererFactory} from './interfaces/renderer';
2623
import {RElement} from './interfaces/renderer_dom';
27-
import {CONTEXT, HEADER_OFFSET, LView, LViewFlags, RootContext, RootContextFlags, TVIEW, TViewType} from './interfaces/view';
24+
import {CONTEXT, HEADER_OFFSET, LView, LViewFlags, RootContext, RootContextFlags, TVIEW} from './interfaces/view';
2825
import {writeDirectClass, writeDirectStyle} from './node_manipulation';
29-
import {enterView, getCurrentTNode, getLView, leaveView, setSelectedIndex} from './state';
26+
import {getCurrentTNode, getLView, setSelectedIndex} from './state';
3027
import {computeStaticStyling} from './styling/static_styling';
3128
import {setUpAttributes} from './util/attrs_utils';
32-
import {publishDefaultGlobalUtils} from './util/global_utils';
3329
import {defaultScheduler} from './util/misc_utils';
3430
import {getRootContext} from './util/view_traversal_utils';
3531

@@ -94,70 +90,6 @@ export const NULL_INJECTOR: Injector = {
9490
}
9591
};
9692

97-
/**
98-
* Bootstraps a Component into an existing host element and returns an instance
99-
* of the component.
100-
*
101-
* Use this function to bootstrap a component into the DOM tree. Each invocation
102-
* of this function will create a separate tree of components, injectors and
103-
* change detection cycles and lifetimes. To dynamically insert a new component
104-
* into an existing tree such that it shares the same injection, change detection
105-
* and object lifetime, use {@link ViewContainer#createComponent}.
106-
*
107-
* @param componentType Component to bootstrap
108-
* @param options Optional parameters which control bootstrapping
109-
*/
110-
export function renderComponent<T>(
111-
componentType: ComponentType<T>|
112-
Type<T>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */
113-
,
114-
opts: CreateComponentOptions = {}): T {
115-
ngDevMode && publishDefaultGlobalUtils();
116-
ngDevMode && assertComponentType(componentType);
117-
118-
const rendererFactory = opts.rendererFactory!;
119-
const sanitizer = opts.sanitizer || null;
120-
const componentDef = getComponentDef<T>(componentType)!;
121-
if (componentDef.type != componentType) (componentDef as {type: Type<any>}).type = componentType;
122-
123-
// The first index of the first selector is the tag name.
124-
const componentTag = componentDef.selectors![0]![0] as string;
125-
const hostRenderer = rendererFactory.createRenderer(null, null);
126-
const hostRNode =
127-
locateHostElement(hostRenderer, opts.host || componentTag, componentDef.encapsulation);
128-
const rootFlags = componentDef.onPush ? LViewFlags.Dirty | LViewFlags.IsRoot :
129-
LViewFlags.CheckAlways | LViewFlags.IsRoot;
130-
const rootContext = createRootContext(opts.scheduler, opts.playerHandler);
131-
132-
const renderer = rendererFactory.createRenderer(hostRNode, componentDef);
133-
const rootTView = createTView(TViewType.Root, null, null, 1, 0, null, null, null, null, null);
134-
const rootView: LView = createLView(
135-
null, rootTView, rootContext, rootFlags, null, null, rendererFactory, renderer, null,
136-
opts.injector || null, null);
137-
138-
enterView(rootView);
139-
let component: T;
140-
141-
try {
142-
if (rendererFactory.begin) rendererFactory.begin();
143-
const componentView = createRootComponentView(
144-
hostRNode, componentDef, rootView, rendererFactory, renderer, sanitizer);
145-
component = createRootComponent(
146-
componentView, componentDef, rootView, rootContext, opts.hostFeatures || null);
147-
148-
// create mode pass
149-
renderView(rootTView, rootView, null);
150-
// update mode pass
151-
refreshView(rootTView, rootView, null, null);
152-
153-
} finally {
154-
leaveView();
155-
if (rendererFactory.end) rendererFactory.end();
156-
}
157-
158-
return component;
159-
}
160-
16193
/**
16294
* Creates the root component view and the root component node.
16395
*

packages/core/src/render3/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {LifecycleHooksFeature, renderComponent, whenRendered} from './component';
8+
import {LifecycleHooksFeature, whenRendered} from './component';
99
import {ɵɵdefineComponent, ɵɵdefineDirective, ɵɵdefineNgModule, ɵɵdefinePipe, ɵɵsetComponentScope, ɵɵsetNgModuleScope} from './definition';
1010
import {ɵɵCopyDefinitionFeature} from './features/copy_definition_feature';
1111
import {ɵɵInheritDefinitionFeature} from './features/inherit_definition_feature';
@@ -196,7 +196,6 @@ export {
196196
getRenderedText,
197197
LifecycleHooksFeature,
198198
PipeDef,
199-
renderComponent,
200199
whenRendered,
201200
ɵɵComponentDeclaration,
202201
ɵɵCopyDefinitionFeature,

0 commit comments

Comments
 (0)