feat(ivy): add property instruction (#29513)

- Adds `property` instruction
- Does _NOT_ add compiler changes to accommodate `property` instruction, that will be a follow up PR.
- Updates `select` instruction to set the selected index in state.
- Adds dev mode assertions around the selected index state.

Related #29527

PR Close #29513
This commit is contained in:
Ben Lesh
2019-03-26 14:57:36 -07:00
committed by Miško Hevery
parent 1e5a818719
commit e4c1c88cbc
3 changed files with 185 additions and 7 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {assertDefined} from '../util/assert';
import {assertDefined, assertGreaterThan} from '../util/assert';
import {assertLViewOrUndefined} from './assert';
import {executeHooks} from './hooks';
@ -340,3 +340,28 @@ export function leaveView(newView: LView): void {
}
enterView(newView, null);
}
let _selectedIndex = -1;
/**
* Gets the most recent index passed to {@link select}
*
* Used with {@link property} instruction (and more in the future) to identify the index in the
* current `LView` to act on.
*/
export function getSelectedIndex() {
ngDevMode &&
assertGreaterThan(
_selectedIndex, -1, 'select() should be called prior to retrieving the selected index');
return _selectedIndex;
}
/**
* Sets the most recent index passed to {@link select}
*
* Used with {@link property} instruction (and more in the future) to identify the index in the
* current `LView` to act on.
*/
export function setSelectedIndex(index: number) {
_selectedIndex = index;
}