LView
and friends is private API and should never leak to the external world.ViewRef
and friends should not be implemented in terms of private API such as LView
. (ViewRef
is a public user rather than private user and hence should use public API)*Ref
APIs from ViewEngine wrap underlying concepts such as Element
, Component
and View
in a way so that they can be run from WebWorker. That original goal did not seem to pan out and now they provide more complexity than value. Our current thinking is that they should be deprecated long term.
The issues with current API is:
We do need replacement APIs for these concepts. For DOM Element
it should just be Element
. For Component
it should just be Component
(see markDirty()
as an example). The question is what to do with View
, ContainerRef
, and EmbededeViewFactory
?
The solution is to treat the View
, ContainerRef
, and EmbeddedViewFactory
as opaque tokens and provide methods for manipulation. In this way it can be:
Element
s)
interface View<T extends{} = {}> {
__ng_brand__: 'Angular opaque reference representing a View. DO NOT READ/MANIPULATE!';
}
interface ViewContainer {
__ng_brand__: 'Angular opaque reference representing a ViewContainer. DO NOT READ/MANIPULATE!';
}
interface EmbeddedViewFactory<T extends{}> {
(context: T): View<T>;
}
The point of these methods is to get a hold of a ViewContainer
or EmbeddedViewFactory
. Just like markDirty()
which takes a component
these methods take DOM Node
to keep the number of mental concepts in the system low, as developers already know about the DOM and no new concepts need to be introduced.
function getEmbeddedViewFactory<T extends{}>(
containerComment: RComment
): EmbeddedViewFactory<T>|null;
function getViewContainer(
containerNative: RElement|RComment
): ViewContainer|null {
New View
s can be created using EmbeddedViewFactory
const node = ...; // Retrieve the comment node for `<ng-template>`
const myViewFactory: EmbeddedViewFactory<MyContext> = getEmbeddedViewFactory(node);
const myContext: MyContext = {....};
const myView: View = myViewFactory(myContext);
Views can be inserted and removed into the view-container using these APIs:
const node = ...; // Retrieve a node which will act as anchor
const myViewContainer: ViewContainer = getViewContainer(node);
ViewContainerInsertBefore(myViewContainer, myView);
The goal of the new APIs is to introduce as few new concepts as possible, and keep the code base tree-shakable, and easy to evolve.
Additional list of APIs:
function viewContainerInsertBefore(
viewContainer: ViewContainer,
view: View,
insertBeforeView?: View | null
): void
function viewContainerIndexOf(
viewContainer: ViewContainer,
view: View
): number;
function viewContainerRemove(
viewContainer: ViewContainer,
view: View,
shouldDestroy: boolean
): void;
function viewContainerLength(
viewContainer: ViewContainer
): number;
function viewContainerGetAt(
viewContainer: ViewContainer,
index: number
): View|null;
View
interface and friends to api/view_interface.ts
view.ts
into view.ts
and api/view.ts
where View
is only imported in api/view.ts
api/*
is not yet made public (don't export it at top level).ViewRef
and friends only import from api/*
.api/*
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing