@@ -25,13 +25,17 @@ export const BINDING: unique symbol = /* @__PURE__ */ Symbol('BINDING');
2525 * For example, `inputBinding('value', () => 123)` creates an input binding.
2626 */
2727export interface Binding {
28+ readonly [ BINDING ] : unknown ;
29+ }
30+
31+ export interface BindingInternal extends Binding {
2832 readonly [ BINDING ] : {
2933 readonly kind : string ;
3034 readonly requiredVars : number ;
3135 } ;
3236
3337 /** Target index (in a view's registry) to which to apply the binding. */
34- readonly targetIdx ?: number ;
38+ targetIdx ?: number ;
3539
3640 /** Callback that will be invoked during creation. */
3741 create ?( ) : void ;
@@ -52,8 +56,8 @@ export interface DirectiveWithBindings<T> {
5256}
5357
5458// These are constant between all the bindings so we can reuse the objects.
55- const INPUT_BINDING_METADATA : Binding [ typeof BINDING ] = { kind : 'input' , requiredVars : 1 } ;
56- const OUTPUT_BINDING_METADATA : Binding [ typeof BINDING ] = { kind : 'output' , requiredVars : 0 } ;
59+ const INPUT_BINDING_METADATA : BindingInternal [ typeof BINDING ] = { kind : 'input' , requiredVars : 1 } ;
60+ const OUTPUT_BINDING_METADATA : BindingInternal [ typeof BINDING ] = { kind : 'output' , requiredVars : 0 } ;
5761
5862// TODO(pk): this is a sketch of an input binding instruction that still needs some cleanups
5963// - take an index of a directive on TNode (as matched), review all the index mappings that we need to do
@@ -111,9 +115,9 @@ function inputBindingUpdate(targetDirectiveIdx: number, publicName: string, valu
111115export function inputBinding ( publicName : string , value : ( ) => unknown ) : Binding {
112116 // Note: ideally we would use a class here, but it seems like they
113117 // don't get tree shaken when constructed by a function like this.
114- const binding : Binding = {
118+ const binding : BindingInternal = {
115119 [ BINDING ] : INPUT_BINDING_METADATA ,
116- update : ( ) => inputBindingUpdate ( binding . targetIdx ! , publicName , value ( ) ) ,
120+ update : ( ) => inputBindingUpdate ( ( binding as BindingInternal ) . targetIdx ! , publicName , value ( ) ) ,
117121 } ;
118122
119123 return binding ;
@@ -143,7 +147,7 @@ export function inputBinding(publicName: string, value: () => unknown): Binding
143147export function outputBinding < T > ( eventName : string , listener : ( event : T ) => unknown ) : Binding {
144148 // Note: ideally we would use a class here, but it seems like they
145149 // don't get tree shaken when constructed by a function like this.
146- const binding : Binding = {
150+ const binding : BindingInternal = {
147151 [ BINDING ] : OUTPUT_BINDING_METADATA ,
148152 create : ( ) => {
149153 const lView = getLView < { } | null > ( ) ;
@@ -178,8 +182,10 @@ export function outputBinding<T>(eventName: string, listener: (event: T) => unkn
178182 * ```
179183 */
180184export function twoWayBinding ( publicName : string , value : WritableSignal < unknown > ) : Binding {
181- const input = inputBinding ( publicName , value ) ;
182- const output = outputBinding ( publicName + 'Change' , ( eventValue ) => value . set ( eventValue ) ) ;
185+ const input = inputBinding ( publicName , value ) as BindingInternal ;
186+ const output = outputBinding ( publicName + 'Change' , ( eventValue ) =>
187+ value . set ( eventValue ) ,
188+ ) as BindingInternal ;
183189
184190 // We take advantage of inputs only having a `create` block and outputs only having an `update`
185191 // block by passing them through directly instead of creating dedicated functions here. This
@@ -188,16 +194,17 @@ export function twoWayBinding(publicName: string, value: WritableSignal<unknown>
188194 ngDevMode && assertNotDefined ( input . create , 'Unexpected `create` callback in inputBinding' ) ;
189195 ngDevMode && assertNotDefined ( output . update , 'Unexpected `update` callback in outputBinding' ) ;
190196
191- return {
197+ const binding : BindingInternal = {
192198 [ BINDING ] : {
193199 kind : 'twoWay' ,
194200 requiredVars : input [ BINDING ] . requiredVars + output [ BINDING ] . requiredVars ,
195201 } ,
196202 set targetIdx ( idx : number ) {
197- ( input as Writable < Binding > ) . targetIdx = idx ;
198- ( output as Writable < Binding > ) . targetIdx = idx ;
203+ ( input as Writable < BindingInternal > ) . targetIdx = idx ;
204+ ( output as Writable < BindingInternal > ) . targetIdx = idx ;
199205 } ,
200206 create : output . create ,
201207 update : input . update ,
202208 } ;
209+ return binding ;
203210}
0 commit comments