text: var indexOf=function(e){return typeof Array.prototype.indexOf=="function"?indexOf=Array.prototype.indexOf:indexOf=function(e){var t=-1,n=-1;for(t=0;t<this.length;t++)if(this[t]===e){n=t;break}return n},indexOf.call(this,e)},DataMapper=function(e){var t=this;return t.channelMaps=e,t.mapData=function(e,n){n.action=="created"?t.mapCreated(e,n.data):n.action=="updated"?t.mapUpdated(e,n.data):n.action=="deleted"&&t.mapDelete(e,n.data)},t.mapCreated=function(e,n){var r=t._findMapping(n._type),i=t._findByIdAndType(e,n.id,n._type);if(i.length>0)return e;var s=[];r!=null&&(s=t._findByIdAndType(e,n[r.via],r.parent_type));if(s.length>0)for(var o in s){var u=s[o];r.is_collection?u[r.prop_name].push(n):u[r.prop_name]=n}else r==null&&(e instanceof Array?e.push(n):e=n);return e},t.mapUpdated=function(e,n){var r=t._findMapping(n._type),i=t._findByIdAndType(e,n.id,n._type);for(var s in i){var o=i[s];if(o!=null)for(var u in n)o[u]=n[u]}var a=t._removeOldParents(e,n,r);a.length==0&&t._attachToParents(e,n,r);for(var f in a)t._attachToParents(e,a[f],r);return i.length==0&&r==null&&(e instanceof Array?e.push(n):e=n),e},t.mapDelete=function(e,n){var r=t._findMapping(n._type),i=t._findCurrentParents(e,n,r);for(var s in i){var o=i[s],u=o[r.prop_name];if(u instanceof Array)for(var a in u)t._compareIds(u[a].id,n.id)&&o[r.prop_name].splice(a,1);else o[r.prop_name]=null}if(i.length==0)if(e instanceof Array)for(var a in e)t._compareIds(e[a].id,n.id)&&e.splice(a,1);else t._compareIds(e.id,n.id)&&(e=null)},t._findMapping=function(e){if(t.channelMaps==null)return null;for(var n in t.channelMaps){var r=t.channelMaps[n];if(r.child_type==e)return r}return null},t._findByIdAndType=function(e,n,r,i){function s(e){if(e._type==r)t._compareIds(e.id,n)&&i.push(e);else for(var s in e)e[s]instanceof Object&&t._findByIdAndType(e[s],n,r,i)}i==null&&(i=[]);if(e instanceof Array)for(var o in e)s(e[o]);else s(e);return i},t._findCurrentParents=function(e,n,r,i){i==null&&(i=[]),r==null&&(r=t._findMapping(n._type));if(r==null)return i;if(e instanceof Array)for(var s in e){var o=e[s];if(o._type==r.parent_type)if(r.is_collection)for(var u in o[r.prop_name])t._compareIds(o[r.prop_name][u].id,n.id)&&i.push(o);else o[r.prop_name]!=null&&t._compareIds(o[r.prop_name].id,n.id)&&i.push(o);else for(var a in o)o[a]instanceof Object&&this._findCurrentParents(o[a],n,r,i)}else e._type==r.parent_type&&t._compareIds(e.id,n[r.via])&&i.push(e);return i},t._removeOldParents=function(e,n,r,i){var s=[],o=t._findCurrentParents(e,n,r);for(var u in o){var a=o[u];if(t._compareIds(a.id,n[r.via])==0){var f=a[r.prop_name];if(r.is_collection)for(var l in f){var c=f[l];t._compareIds(c.id,n.id)&&s.push(f.splice(l,1)[0])}else a[r.prop_name]=null}}return s},t._attachToParents=function(e,n,r){if(r==null)return;var i=n[r.via],s=[];if(i instanceof Array)for(var o in i){var u=i[o],a=t._findByIdAndType(e,u,r.parent_type);for(var f in a)s.push(a[f])}else s=t._findByIdAndType(e,i,r.parent_type);for(var l in s){var c=!0,h=s[l];if(r.is_collection){for(var p in h[r.prop_name]){var d=h[r.prop_name][p];if(t._compareIds(d.id,n.id)){c=!1;break}}c&&h[r.prop_name].push(n)}else h[r.prop_name]=n}},t._compareIds=function(e,t){if(t==null||e==null)return!1;if(t instanceof Array){for(var n in t)if(t[n].toString()==e)return!0;return!1}return e.toString()==t.toString()},t};
  