2018-01-09 18:38:17 -08:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2019-06-11 15:59:41 -07:00
|
|
|
import {ViewRef} from '../../linker/view_ref';
|
|
|
|
|
2019-03-20 15:26:48 +01:00
|
|
|
import {TNode} from './node';
|
2018-01-29 14:51:37 +01:00
|
|
|
import {LQueries} from './query';
|
2018-10-12 18:49:00 -07:00
|
|
|
import {RComment, RElement} from './renderer';
|
2018-10-11 13:13:57 -07:00
|
|
|
import {StylingContext} from './styling';
|
2019-03-20 15:26:48 +01:00
|
|
|
import {HOST, LView, NEXT, PARENT, QUERIES, T_HOST} from './view';
|
|
|
|
|
2018-10-12 15:02:54 -07:00
|
|
|
|
2019-02-23 11:14:35 -08:00
|
|
|
/**
|
|
|
|
* Special location which allows easy identification of type. If we have an array which was
|
|
|
|
* retrieved from the `LView` and that array has `true` at `TYPE` location, we know it is
|
|
|
|
* `LContainer`.
|
|
|
|
*/
|
|
|
|
export const TYPE = 1;
|
2018-06-07 22:42:32 -07:00
|
|
|
/**
|
|
|
|
* Below are constants for LContainer indices to help us look up LContainer members
|
|
|
|
* without having to remember the specific indices.
|
|
|
|
* Uglify will inline these when minifying so there shouldn't be a cost.
|
|
|
|
*/
|
2019-02-23 11:14:35 -08:00
|
|
|
export const ACTIVE_INDEX = 2;
|
2019-03-20 15:26:48 +01:00
|
|
|
// PARENT, NEXT, QUERIES and T_HOST are indices 3, 4, 5 and 6.
|
2018-11-21 21:14:06 -08:00
|
|
|
// As we already have these constants in LView, we don't need to re-create them.
|
2019-02-23 11:14:35 -08:00
|
|
|
export const NATIVE = 7;
|
2019-06-11 15:59:41 -07:00
|
|
|
export const VIEW_REFS = 8;
|
2019-04-29 21:17:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Size of LContainer's header. Represents the index after which all views in the
|
|
|
|
* container will be inserted. We need to keep a record of current views so we know
|
|
|
|
* which views are already in the DOM (and don't need to be re-added) and so we can
|
|
|
|
* remove views from the DOM when they are no longer required.
|
|
|
|
*/
|
2019-06-11 15:59:41 -07:00
|
|
|
export const CONTAINER_HEADER_OFFSET = 9;
|
2018-01-17 17:55:55 +01:00
|
|
|
|
2018-06-07 22:42:32 -07:00
|
|
|
/**
|
2018-10-12 18:49:00 -07:00
|
|
|
* The state associated with a container.
|
2018-06-07 22:42:32 -07:00
|
|
|
*
|
2018-11-21 21:14:06 -08:00
|
|
|
* This is an array so that its structure is closer to LView. This helps
|
2018-06-07 22:42:32 -07:00
|
|
|
* when traversing the view tree (which is a mix of containers and component
|
|
|
|
* views), so we can jump to viewOrContainer[NEXT] in the same way regardless
|
|
|
|
* of type.
|
|
|
|
*/
|
|
|
|
export interface LContainer extends Array<any> {
|
2019-02-23 09:45:55 -08:00
|
|
|
/**
|
|
|
|
* The host element of this LContainer.
|
|
|
|
*
|
|
|
|
* The host could be an LView if this container is on a component node.
|
|
|
|
* In that case, the component LView is its HOST.
|
|
|
|
*
|
|
|
|
* It could also be a styling context if this is a node with a style/class
|
|
|
|
* binding.
|
|
|
|
*/
|
|
|
|
readonly[HOST]: RElement|RComment|StylingContext|LView;
|
|
|
|
|
2019-02-23 11:14:35 -08:00
|
|
|
/**
|
|
|
|
* This is a type field which allows us to differentiate `LContainer` from `StylingContext` in an
|
|
|
|
* efficient way. The value is always set to `true`
|
|
|
|
*/
|
|
|
|
[TYPE]: true;
|
|
|
|
|
2018-01-09 18:38:17 -08:00
|
|
|
/**
|
|
|
|
* The next active index in the views array to read or write to. This helps us
|
|
|
|
* keep track of where we are in the views array.
|
2018-05-17 16:19:44 +02:00
|
|
|
* In the case the LContainer is created for a ViewContainerRef,
|
|
|
|
* it is set to null to identify this scenario, as indices are "absolute" in that case,
|
|
|
|
* i.e. provided directly by the user of the ViewContainerRef API.
|
2018-01-09 18:38:17 -08:00
|
|
|
*/
|
2018-10-11 13:13:57 -07:00
|
|
|
[ACTIVE_INDEX]: number;
|
2018-01-09 18:38:17 -08:00
|
|
|
|
|
|
|
/**
|
2018-06-07 22:42:32 -07:00
|
|
|
* Access to the parent view is necessary so we can propagate back
|
|
|
|
* up from inside a container to parent[NEXT].
|
2018-01-09 18:38:17 -08:00
|
|
|
*/
|
2019-01-28 14:45:31 -08:00
|
|
|
[PARENT]: LView;
|
2018-01-09 18:38:17 -08:00
|
|
|
|
|
|
|
/**
|
2018-06-07 22:42:32 -07:00
|
|
|
* This allows us to jump from a container to a sibling container or component
|
|
|
|
* view with the same parent, so we can remove listeners efficiently.
|
|
|
|
*/
|
2018-11-21 21:14:06 -08:00
|
|
|
[NEXT]: LView|LContainer|null;
|
2018-06-07 22:42:32 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries active for this container - all the views inserted to / removed from
|
|
|
|
* this container are reported to queries referenced here.
|
2018-01-09 18:38:17 -08:00
|
|
|
*/
|
2019-02-23 11:14:35 -08:00
|
|
|
[QUERIES]: LQueries|null; // TODO(misko): This is abuse of `LContainer` since we are storing
|
|
|
|
// `[QUERIES]` in it which are not needed for `LContainer` (only needed for Template)
|
|
|
|
|
|
|
|
/**
|
2019-03-20 15:26:48 +01:00
|
|
|
* Pointer to the `TNode` which represents the host of the container.
|
2019-02-23 11:14:35 -08:00
|
|
|
*/
|
2019-03-20 15:26:48 +01:00
|
|
|
[T_HOST]: TNode;
|
2018-01-09 18:38:17 -08:00
|
|
|
|
2018-10-11 13:13:57 -07:00
|
|
|
/** The comment element that serves as an anchor for this LContainer. */
|
2019-02-23 11:14:35 -08:00
|
|
|
readonly[NATIVE]:
|
|
|
|
RComment; // TODO(misko): remove as this value can be gotten by unwrapping `[HOST]`
|
2019-06-11 15:59:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of `ViewRef`s used by any `ViewContainerRef`s that point to this container.
|
|
|
|
*
|
|
|
|
* This is lazily initialized by `ViewContainerRef` when the first view is inserted.
|
|
|
|
*/
|
|
|
|
[VIEW_REFS]: ViewRef[]|null;
|
2018-01-09 18:38:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note: This hack is necessary so we don't erroneously get a circular dependency
|
|
|
|
// failure based on types.
|
|
|
|
export const unusedValueExportToPlacateAjd = 1;
|