File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed
Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,12 @@ function createHandler<T extends Object>(delayedObject: () => T): ProxyHandler<T
77 const handler : ProxyHandler < T > = { } ;
88 const install = ( name : keyof ProxyHandler < T > ) => {
99 handler [ name ] = ( ...args : any [ ] ) => {
10- args [ 0 ] = delayedObject ( ) ;
10+ const instance = args [ 0 ] = delayedObject ( ) ;
1111 const method = Reflect [ name ] ;
12- return ( method as any ) ( ...args ) ;
12+ const result = ( method as any ) ( ...args ) ;
13+ return typeof result === 'function'
14+ ? result . bind ( instance )
15+ : result ;
1316 } ;
1417 } ;
1518 reflectMethods . forEach ( install ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import ClassB from './fixtures/value/b';
1212import LazyCClass from './fixtures/lazy/lazy_c' ;
1313import LazyBClass from './fixtures/lazy/lazy_b' ;
1414import LazyAClass from './fixtures/lazy/lazy_a' ;
15+ import LazyDClass from './fixtures/lazy/lazy_d' ;
1516
1617const ctx = { } ;
1718const container = new Container ( 'default' ) ;
@@ -282,10 +283,13 @@ describe('container#lazy', () => {
282283 const instance = container . get ( LazyAClass ) ;
283284 expect ( instance ) . toBeInstanceOf ( LazyAClass ) ;
284285 container . set ( { type : LazyBClass } ) ;
286+ container . set ( { type : LazyDClass } ) ;
285287 expect ( instance . lazyB ) . toBeDefined ( ) ;
286288 expect ( instance . lazyB ) . toBeInstanceOf ( LazyBClass ) ;
287289 expect ( instance . lazyB === instance . lazyB ) . toBeTruthy ( ) ;
288290 expect ( instance . lazyB . name ) . toBe ( 'lazyBClass' ) ;
291+ expect ( instance . lazyB . testLazyD ( ) ) . toBe ( 'a,b' ) ;
292+
289293 container . set ( { type : LazyCClass } ) ;
290294 const instanceb = container . get ( LazyBClass ) ;
291295 expect ( instanceb . lazyC ) . toBeDefined ( ) ;
Original file line number Diff line number Diff line change 11import LazyC from './lazy_c' ;
2+ import LazyD from './lazy_d' ;
23import { Inject , Injectable } from '../../../src' ;
34
45@Injectable ( )
56export default class LazyBClass {
67 @Inject ( { lazy : true } )
78 lazyC ! : LazyC ;
9+
10+ @Inject ( { lazy : true } )
11+ lazyD ! : LazyD ;
12+
813 public name = 'lazyBClass' ;
9- }
14+
15+ testLazyD ( ) {
16+ this . lazyD . set ( 'a' , 'b' ) ;
17+ return this . lazyD . doSomething ( ) ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ import { Injectable } from '../../../src' ;
2+
3+ @Injectable ( )
4+ export default class LazyDClass extends Map {
5+ doSomething ( ) {
6+ return Array . from ( this . entries ( ) ) . join ( ',' ) ;
7+ }
8+ }
You can’t perform that action at this time.
0 commit comments