Skip to content

Commit

Permalink
fix(directives): check if lifecycle hook exists and invoke it only wh…
Browse files Browse the repository at this point in the history
…en truthy
  • Loading branch information
Hotell committed Dec 25, 2015
1 parent 8686b80 commit 4f0f1db
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function Directive(
}
if ( Type[ REQUIRE_METADATA_KEY ] ) {

ddoInternal.require = ddoInternal.require.concat( _buildRequireFromInjectedDirectives(Type) );
ddoInternal.require = ddoInternal.require.concat( _buildRequireFromInjectedDirectives( Type ) );

}

Expand Down Expand Up @@ -139,7 +139,7 @@ export function Component(
}
if ( Type[ REQUIRE_METADATA_KEY ] ) {

ddoInternal.require = ddoInternal.require.concat( _buildRequireFromInjectedDirectives(Type) );
ddoInternal.require = ddoInternal.require.concat( _buildRequireFromInjectedDirectives( Type ) );

}
if ( template ) {
Expand Down Expand Up @@ -230,7 +230,7 @@ function _decorateDirectiveType( Type, selector, legacy, ddoCreator: Function )

function _postLinkFactory( Type: any, isDirective: boolean ): ng.IDirectiveLinkFn {

const requireMetadataArr: RequireMetadata[] = Type[REQUIRE_METADATA_KEY] || [];
const requireMetadataArr: RequireMetadata[] = Type[ REQUIRE_METADATA_KEY ] || [];
//console.log( requireMetadata );

return _postLink;
Expand All @@ -250,33 +250,36 @@ function _postLinkFactory( Type: any, isDirective: boolean ): ng.IDirectiveLinkF

if ( requiredCtrls.length > 0 ) {

//console.log( ownCtrl );
if ( _checkLifecycle(
afterContentInitMethod,
ownCtrl,
true,
requiredCtrls
) ) {

_checkLifecycle(
afterContentInitMethod,
ownCtrl,
true,
requiredCtrls
);
requireMetadataArr.forEach( ( reqMetadata, idx )=> {

requireMetadataArr.forEach( ( reqMetadata, idx )=> {
ownCtrl[ reqMetadata.name ] = requiredCtrls[ idx ];

ownCtrl[ reqMetadata.name ] = requiredCtrls[ idx ];
} );

} );
ownCtrl[ afterContentInitMethod ]( requiredCtrls );

ownCtrl[ afterContentInitMethod ]( requiredCtrls );
}

} else {

_checkLifecycle(
afterContentInitMethod,
ownCtrl,
isDirective,
requiredCtrls
);
if ( _checkLifecycle(
afterContentInitMethod,
ownCtrl,
isDirective,
requiredCtrls
) ) {

ownCtrl[ afterContentInitMethod ]( requiredCtrls );

}

ownCtrl[ afterContentInitMethod ]( requiredCtrls );

}

Expand Down

0 comments on commit 4f0f1db

Please sign in to comment.