Skip to content

Commit

Permalink
feat(core/directives): apply fixes/changes from latest angular1.x $co…
Browse files Browse the repository at this point in the history
…mpile
  • Loading branch information
Hotell committed Jun 25, 2016
1 parent bf8409f commit 7fd66c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/core/directives/binding/binding_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,22 @@ export function _createDirectiveBindings(

function _createOneWayBinding( propName: string, attrName: string, exp: string, isImmutable: boolean = false ): Function {

// if ( !exp ) {
// if ( !Object.hasOwnProperty.call( ngAttrs, attrName ) ) {
// if ( optional ) return;
// ngAttrs[ attrName ] = void 0;
// }
// if ( optional && !ngAttrs[ attrName ] ) return;
if ( !exp ) return;

// const parentGet = $parse( ngAttrs[ attrName ] );
const parentGet = $parse( exp );
const initialValue = ctrl[propName] = parentGet(scope);

ctrl[ propName ] = parentGet( scope );
initialChanges[ propName ] = ChangeDetectionUtil.simpleChange( ChangeDetectionUtil.uninitialized, ctrl[ propName ] );

return scope.$watch( parentGet, function parentValueWatchAction( newParentValue ) {
const oldValue = ctrl[ propName ];
recordChanges( propName, newParentValue, oldValue );
ctrl[ propName ] = isImmutable ? angular.copy(newParentValue) : newParentValue;
return scope.$watch( parentGet, function parentValueWatchAction( newValue, oldValue ) {
// https://github.com/angular/angular.js/commit/d9448dcb9f901ceb04deda1d5f3d5aac8442a718
// https://github.com/angular/angular.js/commit/304796471292f9805b9cf77e51aacc9cfbb09921
if ( oldValue === newValue ) {
if ( oldValue === initialValue ) return;
oldValue = initialValue;
}
recordChanges( propName, newValue, oldValue );
ctrl[ propName ] = isImmutable ? angular.copy(newValue) : newValue;
}, parentGet.literal );

}
Expand Down Expand Up @@ -191,8 +189,9 @@ export function _createDirectiveBindings(
// The observer function will be invoked once during the next $digest following compilation.
// The observer is then invoked whenever the interpolated value changes.

const _disposeObserver = ngAttrs.$observe( attrName, function ( value ) {
if ( isString( value ) ) {
const _disposeObserver = ngAttrs.$observe( attrName, function ( value: string|boolean ) {
// https://github.com/angular/angular.js/commit/499e1b2adf27f32d671123f8dceadb3df2ad84a9
if ( isString( value ) || isBoolean( value ) ) {
const oldValue = ctrl[ propName ];
recordChanges( propName, value, oldValue );
ctrl[ propName ] = value;
Expand Down
2 changes: 2 additions & 0 deletions src/core/directives/controller/controller_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export function directiveControllerFactory<T extends DirectiveCtrl,U extends Typ
ddo.ngAfterViewInitBound = instance.ngAfterViewInit.bind(instance);
}*/

// https://github.com/angular/angular.js/commit/0ad2b70862d49ecc4355a16d767c0ca9358ecc3e
// onChanges is called before onInit
if ( isFunction( instance.ngOnChanges ) ) {
instance.ngOnChanges( initialChanges );
}
Expand Down

0 comments on commit 7fd66c5

Please sign in to comment.