{"size": 1143, "ext": "js", "max_stars_repo_path": "observe.js", "max_stars_repo_name": "FGRibreau/xobject-observe", "max_stars_repo_stars_event_min_datetime": "2016-08-10T13:37:16.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-30T05:27:16.000Z", "max_issues_repo_path": "observe.js", "max_issues_repo_name": "FGRibreau/xobject-observe", "max_issues_repo_issues_event_min_datetime": "2016-09-07T15:24:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-11T04:41:19.000Z", "max_forks_repo_path": "observe.js", "max_forks_repo_name": "FGRibreau/xobject-observe", "max_forks_repo_forks_event_min_datetime": "2016-08-12T09:54:43.000Z", "max_forks_repo_forks_event_max_datetime": "2016-12-19T12:46:36.000Z"}
{"max_stars_count": 37, "max_issues_count": 32, "max_forks_count": 3, "avg_line_length": 23.8125, "max_line_length": 112, "alphanum_fraction": 0.678040245}
'use strict';
// https://gist.github.com/eligrey/384583

// global configuration
const config = {
  METHODS: ['es6proxy', 'dirtyChecking'],
  DIRTYCHECK_DELAY: 1000
};

function find(arr, predicate) { // cross-browser helper
  for (let i = 0, iM = arr.length; i < iM; i++) {
    if (predicate(arr[i], i, arr)) {
      return arr[i];
    }
  }
  return null;
}

// (object, (prop, oldValue, newValue))
function observe(object, listener) {
  // find a compatible method
  const compatibleMethodName = find(config.METHODS, (methodName) => observe.methods[methodName].isCompatible());
  if (!compatibleMethodName) {
    throw new Error('No detection method compatible with your browser');
  }

  return observe.methods[compatibleMethodName].method(object, listener);
}

const watched = {};

observe.methods = {
  es6proxy: require('./methods/es6proxy')(config, watched),
  dirtyChecking: require('./methods/dirtyChecking')(config, watched)
};

// expose global configuration
observe.config = config;

observe.stop = (obj) => {
  if(typeof watched[obj] === 'function'){
    watched[obj]();
    delete watched[obj];
  }
}

module.exports = observe;
