| 
									
										
										
										
											2018-02-01 12:13:23 -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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  | import {bindingUpdated, bindingUpdated2, bindingUpdated4, updateBinding, getBinding, getCreationMode, bindingUpdated3, getBindingRoot, getTView,} from './instructions'; | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Bindings for pure functions are stored after regular bindings. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |  * |--------consts--------|----------------vars----------------|------ hostVars (dir1) ------| | 
					
						
							|  |  |  |  * --------------------------------------------------------------------------------------------- | 
					
						
							|  |  |  |  * | nodes / refs / pipes | bindings | pure function bindings  | host bindings  | host slots | | 
					
						
							|  |  |  |  * --------------------------------------------------------------------------------------------- | 
					
						
							|  |  |  |  *                        ^                                    ^ | 
					
						
							|  |  |  |  *             TView.bindingStartIndex            TView.hostBindingStartIndex | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |  * Pure function instructions are given an offset from the binding root. Adding the offset to the | 
					
						
							|  |  |  |  * binding root gives the first index where the bindings are stored. In component views, the binding | 
					
						
							|  |  |  |  * root is the bindingStartIndex. In host bindings, the binding root is the hostBindingStartIndex + | 
					
						
							|  |  |  |  * any hostVars in directives evaluated before it. | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * If the value hasn't been saved, calls the pure function to store and return the | 
					
						
							|  |  |  |  * value. If it has been saved, returns the saved value. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * @param pureFn Function that returns a value | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * @returns value | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  | export function pureFunction0<T>(slotOffset: number, pureFn: () => T, thisArg?: any): T { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   return getCreationMode() ? | 
					
						
							|  |  |  |       updateBinding(bindingIndex, thisArg ? pureFn.call(thisArg) : pureFn()) : | 
					
						
							|  |  |  |       getBinding(bindingIndex); | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of the provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if the value has not changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn Function that returns an updated value | 
					
						
							| 
									
										
										
										
											2018-02-13 10:24:41 -08:00
										 |  |  |  * @param exp Updated expression value | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  | export function pureFunction1( | 
					
						
							|  |  |  |     slotOffset: number, pureFn: (v: any) => any, exp: any, thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   return bindingUpdated(bindingIndex, exp) ? | 
					
						
							|  |  |  |       updateBinding(bindingIndex + 1, thisArg ? pureFn.call(thisArg, exp) : pureFn(exp)) : | 
					
						
							|  |  |  |       getBinding(bindingIndex + 1); | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of any provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if no values have changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * @param exp1 | 
					
						
							|  |  |  |  * @param exp2 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  | export function pureFunction2( | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |     slotOffset: number, pureFn: (v1: any, v2: any) => any, exp1: any, exp2: any, | 
					
						
							|  |  |  |     thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   return bindingUpdated2(bindingIndex, exp1, exp2) ? | 
					
						
							|  |  |  |       updateBinding( | 
					
						
							|  |  |  |           bindingIndex + 2, thisArg ? pureFn.call(thisArg, exp1, exp2) : pureFn(exp1, exp2)) : | 
					
						
							|  |  |  |       getBinding(bindingIndex + 2); | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of any provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if no values have changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * @param exp1 | 
					
						
							|  |  |  |  * @param exp2 | 
					
						
							|  |  |  |  * @param exp3 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  | export function pureFunction3( | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |     slotOffset: number, pureFn: (v1: any, v2: any, v3: any) => any, exp1: any, exp2: any, exp3: any, | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |     thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   return bindingUpdated3(bindingIndex, exp1, exp2, exp3) ? | 
					
						
							|  |  |  |       updateBinding( | 
					
						
							|  |  |  |           bindingIndex + 3, | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |           thisArg ? pureFn.call(thisArg, exp1, exp2, exp3) : pureFn(exp1, exp2, exp3)) : | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |       getBinding(bindingIndex + 3); | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of any provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if no values have changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * @param exp1 | 
					
						
							|  |  |  |  * @param exp2 | 
					
						
							|  |  |  |  * @param exp3 | 
					
						
							|  |  |  |  * @param exp4 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  | export function pureFunction4( | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |     slotOffset: number, pureFn: (v1: any, v2: any, v3: any, v4: any) => any, exp1: any, exp2: any, | 
					
						
							|  |  |  |     exp3: any, exp4: any, thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   return bindingUpdated4(bindingIndex, exp1, exp2, exp3, exp4) ? | 
					
						
							|  |  |  |       updateBinding( | 
					
						
							|  |  |  |           bindingIndex + 4, | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |           thisArg ? pureFn.call(thisArg, exp1, exp2, exp3, exp4) : pureFn(exp1, exp2, exp3, exp4)) : | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |       getBinding(bindingIndex + 4); | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of any provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if no values have changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * @param exp1 | 
					
						
							|  |  |  |  * @param exp2 | 
					
						
							|  |  |  |  * @param exp3 | 
					
						
							|  |  |  |  * @param exp4 | 
					
						
							|  |  |  |  * @param exp5 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  | export function pureFunction5( | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |     slotOffset: number, pureFn: (v1: any, v2: any, v3: any, v4: any, v5: any) => any, exp1: any, | 
					
						
							|  |  |  |     exp2: any, exp3: any, exp4: any, exp5: any, thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   const different = bindingUpdated4(bindingIndex, exp1, exp2, exp3, exp4); | 
					
						
							|  |  |  |   return bindingUpdated(bindingIndex + 4, exp5) || different ? | 
					
						
							|  |  |  |       updateBinding( | 
					
						
							|  |  |  |           bindingIndex + 5, thisArg ? pureFn.call(thisArg, exp1, exp2, exp3, exp4, exp5) : | 
					
						
							|  |  |  |                                       pureFn(exp1, exp2, exp3, exp4, exp5)) : | 
					
						
							|  |  |  |       getBinding(bindingIndex + 5); | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of any provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if no values have changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * @param exp1 | 
					
						
							|  |  |  |  * @param exp2 | 
					
						
							|  |  |  |  * @param exp3 | 
					
						
							|  |  |  |  * @param exp4 | 
					
						
							|  |  |  |  * @param exp5 | 
					
						
							|  |  |  |  * @param exp6 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  | export function pureFunction6( | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |     slotOffset: number, pureFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any) => any, | 
					
						
							|  |  |  |     exp1: any, exp2: any, exp3: any, exp4: any, exp5: any, exp6: any, thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   const different = bindingUpdated4(bindingIndex, exp1, exp2, exp3, exp4); | 
					
						
							|  |  |  |   return bindingUpdated2(bindingIndex + 4, exp5, exp6) || different ? | 
					
						
							|  |  |  |       updateBinding( | 
					
						
							|  |  |  |           bindingIndex + 6, thisArg ? pureFn.call(thisArg, exp1, exp2, exp3, exp4, exp5, exp6) : | 
					
						
							|  |  |  |                                       pureFn(exp1, exp2, exp3, exp4, exp5, exp6)) : | 
					
						
							|  |  |  |       getBinding(bindingIndex + 6); | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of any provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if no values have changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * @param exp1 | 
					
						
							|  |  |  |  * @param exp2 | 
					
						
							|  |  |  |  * @param exp3 | 
					
						
							|  |  |  |  * @param exp4 | 
					
						
							|  |  |  |  * @param exp5 | 
					
						
							|  |  |  |  * @param exp6 | 
					
						
							|  |  |  |  * @param exp7 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  | export function pureFunction7( | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |     slotOffset: number, | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |     pureFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any, v7: any) => any, exp1: any, | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |     exp2: any, exp3: any, exp4: any, exp5: any, exp6: any, exp7: any, thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   let different = bindingUpdated4(bindingIndex, exp1, exp2, exp3, exp4); | 
					
						
							|  |  |  |   return bindingUpdated3(bindingIndex + 4, exp5, exp6, exp7) || different ? | 
					
						
							|  |  |  |       updateBinding( | 
					
						
							|  |  |  |           bindingIndex + 7, thisArg ? | 
					
						
							|  |  |  |               pureFn.call(thisArg, exp1, exp2, exp3, exp4, exp5, exp6, exp7) : | 
					
						
							|  |  |  |               pureFn(exp1, exp2, exp3, exp4, exp5, exp6, exp7)) : | 
					
						
							|  |  |  |       getBinding(bindingIndex + 7); | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of any provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if no values have changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  * @param exp1 | 
					
						
							|  |  |  |  * @param exp2 | 
					
						
							|  |  |  |  * @param exp3 | 
					
						
							|  |  |  |  * @param exp4 | 
					
						
							|  |  |  |  * @param exp5 | 
					
						
							|  |  |  |  * @param exp6 | 
					
						
							|  |  |  |  * @param exp7 | 
					
						
							|  |  |  |  * @param exp8 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  | export function pureFunction8( | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |     slotOffset: number, | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |     pureFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any, v7: any, v8: any) => any, | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |     exp1: any, exp2: any, exp3: any, exp4: any, exp5: any, exp6: any, exp7: any, exp8: any, | 
					
						
							|  |  |  |     thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   const bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   const different = bindingUpdated4(bindingIndex, exp1, exp2, exp3, exp4); | 
					
						
							|  |  |  |   return bindingUpdated4(bindingIndex + 4, exp5, exp6, exp7, exp8) || different ? | 
					
						
							|  |  |  |       updateBinding( | 
					
						
							|  |  |  |           bindingIndex + 8, thisArg ? | 
					
						
							|  |  |  |               pureFn.call(thisArg, exp1, exp2, exp3, exp4, exp5, exp6, exp7, exp8) : | 
					
						
							|  |  |  |               pureFn(exp1, exp2, exp3, exp4, exp5, exp6, exp7, exp8)) : | 
					
						
							|  |  |  |       getBinding(bindingIndex + 8); | 
					
						
							| 
									
										
										
										
											2018-02-13 10:24:41 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * pureFunction instruction that can support any number of bindings. | 
					
						
							| 
									
										
										
										
											2018-02-13 10:24:41 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-02-14 13:37:54 -08:00
										 |  |  |  * If the value of any provided exp has changed, calls the pure function to return | 
					
						
							|  |  |  |  * an updated value. Or if no values have changed, returns cached value. | 
					
						
							| 
									
										
										
										
											2018-02-13 10:24:41 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |  * @param slotOffset the offset from binding root to the reserved slot | 
					
						
							| 
									
										
										
										
											2018-02-13 18:56:52 -08:00
										 |  |  |  * @param pureFn A pure function that takes binding values and builds an object or array | 
					
						
							| 
									
										
										
										
											2018-02-13 10:24:41 -08:00
										 |  |  |  * containing those values. | 
					
						
							| 
									
										
										
										
											2018-05-13 18:24:12 +02:00
										 |  |  |  * @param exps An array of binding values | 
					
						
							|  |  |  |  * @param thisArg Optional calling context of pureFn | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |  * @returns Updated or cached value | 
					
						
							| 
									
										
										
										
											2018-02-13 10:24:41 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  | export function pureFunctionV( | 
					
						
							|  |  |  |     slotOffset: number, pureFn: (...v: any[]) => any, exps: any[], thisArg?: any): any { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |   // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings
 | 
					
						
							| 
									
										
										
										
											2018-08-20 13:03:03 -07:00
										 |  |  |   let bindingIndex = getBindingRoot() + slotOffset; | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |   let different = false; | 
					
						
							| 
									
										
										
										
											2018-02-13 10:24:41 -08:00
										 |  |  |   for (let i = 0; i < exps.length; i++) { | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |     bindingUpdated(bindingIndex++, exps[i]) && (different = true); | 
					
						
							| 
									
										
										
										
											2018-02-13 10:24:41 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-08-15 16:32:08 -07:00
										 |  |  |   return different ? updateBinding(bindingIndex, pureFn.apply(thisArg, exps)) : | 
					
						
							|  |  |  |                      getBinding(bindingIndex); | 
					
						
							| 
									
										
										
										
											2018-02-01 12:13:23 -08:00
										 |  |  | } |