SHARE
TWEET

onchange

a guest Feb 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var record = input.records[0]
  2.  
  3. var persistentMap = typeof(persistentMap) === 'undefined' ? {} : persistentMap;
  4. var valuesToSend = {};
  5. var timestamps = {};
  6. var outRecord = newWireRecord();
  7.  
  8. //called with every property and its value
  9. function process(key,value) {
  10.     if(key.endsWith("_timestamp")){
  11.       //store timestamps in temporary map
  12.       timestamps[key] = value;
  13.       return;
  14.     }
  15.     var oldValue = persistentMap[key];
  16.     if(oldValue != undefined && oldValue != value.getValue()){
  17.       valuesToSend[key] = value;
  18.     }
  19.     persistentMap[key] = value.getValue();
  20. }
  21.  
  22. function traverse(o,func) {
  23.     for (var i in o) {
  24.         func.apply(this,[i,o[i]]);
  25.         if (o[i] !== null && typeof(o[i])=="object") {
  26.             //going one step down in the object tree!!
  27.             traverse(o[i],func);
  28.         }
  29.     }
  30. }
  31.  
  32. traverse(record, process);
  33.  
  34. if(Object.keys(valuesToSend).length > 0){
  35.   traverse(valuesToSend, addToOutput);
  36.   output.add(outRecord);
  37. }
  38.  
  39. function addToOutput(key, value) {
  40.   outRecord[key] = value;
  41.   //retrieve previously stored timestamp if present
  42.   if(timestamps[key+"_timestamp"] != undefined){
  43.     outRecord[key+"_timestamp"]=timestamps[key+"_timestamp"];
  44.   }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top