define('ember-data-relationship-tracker/index', ['exports', 'lodash/isEqual'], function (exports, _isEqual) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = Ember.Mixin.create({
    init: function init() {
      this._super();
      this._relationshipTracker = Object.create(null);
    },
    watchRelationship: function watchRelationship(field, fn) {
      var entry = this._relationshipTracker[field];
      if (!entry) {
        entry = this._relationshipTracker[field] = Object.create(null);
      }
      var changed = changedKey(this);
      if (!(changed in entry)) {
        entry[changed] = currentState(this, field);
      }
      fn();
      this.propertyDidChange('hasDirtyRelationships');
    },


    hasDirtyRelationships: Ember.computed('changed', function () {
      var _this = this;

      var changed = changedKey(this);
      return Object.keys(this._relationshipTracker).some(function (field) {
        var entry = _this._relationshipTracker[field];
        return changed in entry && !(0, _isEqual.default)(entry[changed], currentState(_this, field));
      });
    }),

    hasDirtyFields: Ember.computed.or('hasDirtyAttributes', 'hasDirtyRelationships'),

    rollbackRelationships: function rollbackRelationships() {
      var _this2 = this;

      var changed = changedKey(this);
      var tracker = this._relationshipTracker;
      Object.keys(tracker).forEach(function (field) {
        if (!tracker[field] || !(changed in tracker[field])) {
          return;
        }
        _this2.set(field, tracker[field][changed]);
      });
      this.propertyDidChange('hasDirtyRelationships');
    }
  });


  function currentState(model, field) {
    var config = Ember.get(model.constructor, 'relationshipsByName').get(field);
    if (config.kind === 'hasMany') {
      var reference = model.hasMany(field);
      return reference.value().toArray();
    } else {
      var _reference = model.belongsTo(field);
      return _reference.value();
    }
  }

  function changedKey(model) {
    var changed = model.get('changed');
    if (changed) {
      return changed.getTime();
    } else {
      return -1;
    }
  }
});