Nifty SHAs of Code

A day in the life of a bug fix

Pete Bacon Darwin

Ye Olde Days

(Closed Source proprietary API)

Frustration!

Open Source

to the rescue!

(Comic by Nina Paley / CC By-SA 3.0)

AngularJS

  • more than 1200 contributors

    • almost 400 providing significant code
  • 6000+ issues and 5500+ PRs
  • almost 7000 commits

Open Source + GitHub

By Nevit Dilmen (Own work) [CC BY-SA 3.0]

But...

  • 900+ outstanding issues

  • 300+ outstanding PRs

Makes us sad :-(

AngularJS

Development Process

  • Single Track Commit History
    • Auto generate changelog
    • Quickly identify commits
  • Building and Testing
    • Enforce coding guidelines
    • Require comprehensive tests
  • Inline documentation
    • Auto generate docs

Contributor Guidelines

Six Golden Steps

  1. Identify the bug

  2. Post an issue

  3. Fix the problem

  4. Submit a pull request

  5. Deal with feedback

  6. Bask in the glory of being a super hero contributor

1 Identify the bug

  • Search for known issues on Github
  • What is the environment?
    • Version of Angular
    • Make and version of browser
    • Any error messages
    • 3rd party libraries
  • Steps to reproduce the bug
  •  

Post an Issue

  • Identify the crux of the problem
  • Create a runnable demo - on Plunker or equivalent
  • Create an issue on Github
  • Bonus Points:
    • Create a failing unit test

Awesome Example

ngOptions incorrectly evaluates label for $$hashKey when watching labels

https://github.com/angular/angular.js/issues/11930

1.3.x ngCookies service overwrites/duplicates cookies set outside of ngCookies

https://github.com/angular/angular.js/issues/11490

Fix the Problem

  • Fork repo on Github
  • Set up development environment
  • Write a failing test
  • Identify a solution that passes the checks and tests
  • Update docs if necessary

Setup your Dev Environment

  • npm install -g grunt
  • git clone https://github.com/petebacondarwin/angular.js
  • npm install
  • grunt package
  • git checkout -b issue-11930
  • grunt autotest

Write a failing test

it('should not watch array properties that start with $ or $$', function() {
  createSelect({
    'ng-options': 'value as createLabel(value) for value in array',
    'ng-model': 'selected'
  });
  scope.createLabel = jasmine.createSpy()
                        .andCallFake(function(value) { return value; });
  scope.array = ['a', 'b', 'c'];
  scope.array.$$private = 'do not watch';
  scope.array.$property = 'do not watch';
  scope.selected = 'b';
  scope.$digest();

  expect(scope.createLabel).toHaveBeenCalledWith('a');
  expect(scope.createLabel).toHaveBeenCalledWith('b');
  expect(scope.createLabel).toHaveBeenCalledWith('c');
  expect(scope.createLabel).not.toHaveBeenCalledWith('do not watch');
});

Find a solution

Object.keys(values).forEach(function getWatchable(key) {
  
  if (key.charAt(0) === '$') return;

  var locals = getLocals(values[key], key);
  var selectValue = getTrackByValueFn(values[key], locals);
  watchedArray.push(selectValue);

  // Only need to watch the displayFn if there is a specific label expression
  if (match[2] || match[1]) {
    var label = displayFn(scope, locals);
    watchedArray.push(label);
  }

  // Only need to watch the disableWhenFn if there is a specific disable expression
  if (match[4]) {
    var disableWhen = disableWhenFn(scope, locals);
    watchedArray.push(disableWhen);
  }
});

 

Run all the tests and checks

  grunt test

 

This is equivalent to

  grunt ci-checks
  grunt package
  grunt test:unit
  grunt test:e2e

Submit the fix

Commit Messages

fix(ngOptions): do not watch properties starting with $

Expressions that compute labels and track by values for ngOptions were being called for properties, that start with $ even though those properties were being ignored as options.

Closes #11930

Create a Pull Request

Get Feedback

  • Subscribe to notifications for the issue and PR

  • Add new commits (no need to squash or force push)

Enjoy the merge!

  • Sit back and basque in contribution glory

  • Watch out for related regressions appearing in issues

Nifty SHAs of Code

By Pete Bacon Darwin

Nifty SHAs of Code

  • 2,724