Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var record = input.records[0]
- var persistentMap = typeof(persistentMap) === 'undefined' ? {} : persistentMap;
- var valuesToSend = {};
- var timestamps = {};
- var outRecord = newWireRecord();
- //called with every property and its value
- function process(key,value) {
- if(key.endsWith("_timestamp")){
- //store timestamps in temporary map
- timestamps[key] = value;
- return;
- }
- var oldValue = persistentMap[key];
- if(oldValue != undefined && oldValue != value.getValue()){
- valuesToSend[key] = value;
- }
- persistentMap[key] = value.getValue();
- }
- function traverse(o,func) {
- for (var i in o) {
- func.apply(this,[i,o[i]]);
- if (o[i] !== null && typeof(o[i])=="object") {
- //going one step down in the object tree!!
- traverse(o[i],func);
- }
- }
- }
- traverse(record, process);
- if(Object.keys(valuesToSend).length > 0){
- traverse(valuesToSend, addToOutput);
- output.add(outRecord);
- }
- function addToOutput(key, value) {
- outRecord[key] = value;
- //retrieve previously stored timestamp if present
- if(timestamps[key+"_timestamp"] != undefined){
- outRecord[key+"_timestamp"]=timestamps[key+"_timestamp"];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement