taffy-test.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <title>taffy test</title>
  6. <script src="./taffy.js"></script>
  7. <script>
  8. // recursive object compare, for future use
  9. Object.prototype.equals = function (x) {
  10. var p;
  11. for(p in this) {
  12. if(typeof(x[p])=='undefined') {return false;}
  13. }
  14. for(p in this) {
  15. if (this[p]) {
  16. switch(typeof(this[p])) {
  17. case 'object':
  18. if (! this[p].equals(x[p])) { return false; }
  19. break;
  20. case 'function':
  21. if (typeof(x[p])=='undefined' ||
  22. (p != 'equals' && this[p].toString() != x[p].toString())
  23. ){ return false; }
  24. break;
  25. default:
  26. if (this[p] != x[p]) { return false; }
  27. }
  28. }
  29. else {
  30. if (x[p]){ return false; }
  31. }
  32. }
  33. for(p in x) {
  34. if(typeof(this[p])=='undefined') {return false;}
  35. }
  36. return true;
  37. };
  38. var key_name, data_val, friends_table, taffy_map;
  39. friends_table = TAFFY([
  40. {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active"},
  41. {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"},
  42. {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active"},
  43. {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"}
  44. ]);
  45. taffy_map = {
  46. t_by_city : friends_table({city:"Seattle, WA"}),
  47. t_by_id : friends_table({id:1}),
  48. t_by_id_f : friends_table({id:'1'}),
  49. t_by_name : friends_table({first:'John',last:'Smith'}),
  50. kelly_by_id : friends_table({id:2}).first(),
  51. kelly_last_name : friends_table({id:2}).first().last,
  52. id_list : friends_table().select('id'),
  53. city_list : friends_table().distinct('city'),
  54. };
  55. for ( key_name in taffy_map ){
  56. if ( taffy_map.hasOwnProperty(key_name) ){
  57. data_val = taffy_map[key_name];
  58. console.warn(key_name, data_val);
  59. if ( data_val.hasOwnProperty('get') ){
  60. console.warn(JSON.stringify(data_val.get()));
  61. }
  62. console.warn('----------------');
  63. }
  64. }
  65. </script>
  66. </head>
  67. <body>
  68. <div>
  69. Please open your javascript console to see test results
  70. </div>
  71. </body>
  72. </html>