Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(Attributes): added support for attributes observing deregistration #5609

Closed

Conversation

caiotoon
Copy link
Contributor

@caiotoon caiotoon commented Jan 3, 2014

In order to make the behavior compatible with $rootScope.$watch() and $rootScope.$on methods, and
make it possible to deregister an attribute observer, Attributes.$observe method now returns a
deregistration function instead of the observer itself.

BREAKING CHANGE: calling attr.$observe no longer returns the observer function, but a
deregistration function instead.

To migrate the code follow the example below:

Before:

directive('directiveName', function() {
  return {
    link: function(scope, elm, attr) {
      var observer = attr.$observe('someAttr', function(value) {
        console.log(value);
      });
    }
  };
});

After:

directive('directiveName', function() {
  return {
    link: function(scope, elm, attr) {
      var observer = function(value) {
        console.log(value);
      };

      attr.$observe('someAttr', observer);
    }
  };
});

In order to make the behavior compatible with $rootScope.$watch and $rootScope.$on methods, and
make it possible to deregister an attribute observer, Attributes.$observe method now returns a
deregistration function instead of the observer itself.

BREAKING CHANGE: calling attr.$observe no longer returns the observer function, but a
    deregistration function instead.

    To migrate the code follow the example below:

    Before:

    directive('directiveName', function() {
      return {
        link: function(scope, elm, attr) {
          var observer = attr.$observe('someAttr', function(value) {
            console.log(value);
          });
        }
      };
    });

    After:

    directive('directiveName', function() {
      return {
        link: function(scope, elm, attr) {
          var observer = function(value) {
            console.log(value);
          };

          attr.$observe('someAttr', observer);
        }
      };
    });
@IgorMinar
Copy link
Contributor

I'm sorry, but I wasn't able to verify your CLA signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let me know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@IgorMinar
Copy link
Contributor

otherwise this looks good to me, but since it requires a breaking change I'm going to triage it for 1.3

@caiotoon
Copy link
Contributor Author

caiotoon commented Jan 3, 2014

Hi Igor. Just signed it again, but I think I have some problem with the CLA signature, as you can see in this PR. Can you help me with this CLA signature? I'll try mailing it anyway.

@IlanFrumer
Copy link

+1

@ProLoser
Copy link
Contributor

ProLoser commented Feb 2, 2014

+1 Yeah the old behavior makes 0 sense to me.

@caiotoon caiotoon added cla: no and removed cla: yes labels Feb 19, 2014
@booleanbetrayal
Copy link
Contributor

+1

1 similar comment
@Antonio-Laguna
Copy link

👍

@IgorMinar
Copy link
Contributor

the problem is that you signed CLA with caio at caiotoon.com and your commits are authored with opensource at caiotoon.com. Because of this difference, the robot is not able to verify your CLA signature.

@IgorMinar IgorMinar self-assigned this Mar 18, 2014
IgorMinar pushed a commit to IgorMinar/angular.js that referenced this pull request Mar 18, 2014
In order to make the behavior compatible with $rootScope.$watch and $rootScope.$on methods, and
make it possible to deregister an attribute observer, Attributes.$observe method now returns a
deregistration function instead of the observer itself.

BREAKING CHANGE: calling attr.$observe no longer returns the observer function, but a
    deregistration function instead.

    To migrate the code follow the example below:

    Before:

    directive('directiveName', function() {
      return {
        link: function(scope, elm, attr) {
          var observer = attr.$observe('someAttr', function(value) {
            console.log(value);
          });
        }
      };
    });

    After:

    directive('directiveName', function() {
      return {
        link: function(scope, elm, attr) {
          var observer = function(value) {
            console.log(value);
          };

          attr.$observe('someAttr', observer);
        }
      };
    });

Closes angular#5609
@IgorMinar IgorMinar closed this in 299b220 Mar 18, 2014
@IgorMinar
Copy link
Contributor

I merged this one, but please update your commit email signature or sign CLA with the other email.

@caiotoon
Copy link
Contributor Author

Thank you @IgorMinar

Yes, I've signed with both e-mails. The last time I did with opensource at caiotoon.com it was through printing, scanning and emailing it, because online you couldn't check it. Do you think there might be a problem for having signed with both emails?

@caiotoon caiotoon deleted the attributes-observe-unregister branch March 18, 2014 21:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants