apply-diff-from-any.js 732 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*jshint indent:2, laxcomma:true, laxbreak:true*/
  2. var util = require('util')
  3. , diff = require('..')
  4. , data = require('./practice-data')
  5. ;
  6. var cycle = -1
  7. , i
  8. , len = data.length
  9. , prior = {}
  10. , comparand
  11. , records
  12. , ch
  13. ;
  14. var applyEachChange = function (ch) {
  15. diff.applyChange(prior, comparand, ch);
  16. };
  17. while (++cycle < 10) {
  18. i = -1;
  19. while (++i < len) {
  20. comparand = data[i];
  21. // get the difference...
  22. records = diff(prior, comparand);
  23. // round-trip serialize to prune the underlying types...
  24. var serialized = JSON.stringify(records);
  25. var desierialized = JSON.parse(serialized);
  26. if (desierialized) {
  27. desierialized.forEach(applyEachChange);
  28. prior = comparand;
  29. }
  30. }
  31. }