made with requirebin
Created
January 12, 2016 03:19
-
-
Save trxcllnt/4781d686d40f5add031e to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isArray = Array.isArray; | |
var iterateKeySet = require("falcor-path-utils").iterateKeySet; | |
// module.exports = getJSON; | |
// debugger; | |
var paths = [ | |
['list', 'selected', 'name'], | |
['list', [0, 1, 3, 5], 'name'], | |
['list', 5, 'name'], | |
['foo', 'bar'] | |
]; | |
var jsonEnvelope = { json: {} }; | |
var results = getJSON({ _root: { cache: getCache()}}, paths, jsonEnvelope); | |
// console.log(JSON.stringify(getCache(), null, ' ')); | |
console.log(JSON.stringify(jsonEnvelope, null, ' ')); | |
console.log(JSON.stringify(jsonEnvelope.json.list.selected.map(function(x) { | |
return x.name; | |
}))); | |
console.log(' requested paths:', JSON.stringify(paths)); | |
console.log('missing requested paths:', JSON.stringify(results[0])); | |
console.log('missing optimized paths:', JSON.stringify(results[1])); | |
function getCache() { | |
return { | |
ツpath: [], | |
ツversion: 0, | |
list: { | |
ツkey: 'list', | |
ツpath: ['list'], | |
ツversion: 0, | |
// Each ref in the cache will now have hardlink _array_ | |
// instead of single field. We'll just always use an array | |
// regardless of pathset or path. All reference targets will still have | |
// backreferences just as they do today. | |
selected: { | |
$type: 'refset', | |
value: ['list', [0, 1, 2]], | |
// value: ['list', [0, 1]], | |
ツkey: 'selected', | |
ツpath: ['list', 'selected'], | |
ツversion: 0, | |
}, | |
0: { | |
name: { | |
$type: 'atom', | |
value: 'name 0', | |
ツkey: 'name', | |
ツpath: ['list', 0, 'name'], | |
ツversion: 0, | |
}, | |
ツkey: 0, | |
ツpath: ['list', 0], | |
ツversion: 0, | |
}, | |
1: { | |
name: { | |
$type: 'atom', | |
value: 'name 1', | |
ツkey: 'name', | |
ツpath: ['list', 1, 'name'], | |
ツversion: 0, | |
}, | |
ツkey: 1, | |
ツpath: ['list', 1], | |
ツversion: 0, | |
}, | |
2: { | |
$type: 'refset', | |
value: ['list', [3, 4, 5]], | |
ツkey: 2, | |
ツpath: ['list', 2], | |
ツversion: 0, | |
}, | |
3: { | |
name: { | |
$type: 'atom', | |
value: 'name 3', | |
ツkey: 'name', | |
ツpath: ['list', 3, 'name'], | |
ツversion: 0, | |
}, | |
ツkey: 3, | |
ツpath: ['list', 3], | |
ツversion: 0, | |
}, | |
6: { | |
name: { | |
$type: 'atom', | |
value: 'name 6', | |
ツkey: 'name', | |
ツpath: ['list', 6, 'name'], | |
ツversion: 0, | |
}, | |
ツkey: 6, | |
ツpath: ['list', 6], | |
ツversion: 0, | |
}, | |
}, | |
}; | |
} | |
/** | |
* Gets a list of {@link PathSet}s from a {@link JSONGraph} as a JSON tree. | |
* @function | |
* @param {Object} model - the Model for which to insert the {@link PathSet}s. | |
* @param {Array.<PathSet>} pathSets - the list of {@link PathSet}s to get. | |
* @return {Array.<Array.<Path>>} - an Array of Arrays where each inner Array is a list | |
* of the requested and optimized paths (respectively) for the values that weren't found. | |
*/ | |
function getJSON(model, pathSets, jsonEnvelope) { | |
if (!jsonEnvelope) { | |
jsonEnvelope = {}; | |
} | |
var modelRoot = model._root; | |
var lru = modelRoot; | |
var expired = modelRoot.expired; | |
var bound = model._path || []; | |
var cache = modelRoot.cache; | |
var node = cache; | |
var json = jsonEnvelope.json || (jsonEnvelope.json = {}); | |
var parent = node && node.ツparent || cache; | |
var rPath = []; | |
var rPaths = []; | |
var oPaths = []; | |
var oIndex = bound.length; | |
var pathSetIndex = -1; | |
var pathSetCount = pathSets.length; | |
while (++pathSetIndex < pathSetCount) { | |
var pathSet = pathSets[pathSetIndex]; | |
var oPath = bound.slice(0); | |
oPath.index = oIndex; | |
getPathSet( | |
pathSet, pathSet, 0, cache, parent, node, json, | |
expired, lru, false, rPath, oPath, rPaths, oPaths | |
); | |
} | |
return [rPaths, oPaths]; | |
} | |
function getPathSet( | |
requestedPathSet, pathSet, depth, root, parent, node, json, | |
expired, lru, isFollowingReference, rPath, oPath, rPaths, oPaths) { | |
var ns = [], js = [], ps = [], results; | |
var note = {}, keySet = pathSet[depth]; | |
var isBranch = depth < pathSet.length - 1; | |
var key = iterateKeySet(keySet, note); | |
var oIndex = oPath.index; | |
do { | |
if (key == null) { | |
if (isBranch) { | |
// throw new NullInPathError(); | |
throw 'NullInPathError'; | |
} else { | |
key = node.ツkey; | |
} | |
} | |
if (!isFollowingReference) { | |
rPath[depth] = key; | |
rPath.index = depth; | |
} | |
oPath[oPath.index++] = key; | |
var index = -1; | |
var count = 01; | |
var nodes = [node], jsons = [json], parents = [parent]; | |
while (++index < count) { | |
var n = nodes[index]; | |
var j = jsons[index]; | |
var p = parents[index]; | |
if (n) { | |
var t = n.$type; | |
if (t === 'ref' || t === 'refset') { | |
if (isFollowingReference && isBranch) { | |
throw new Error('References must not cross other references.'); | |
} | |
var ref = n.value; | |
oPath.splice(0, oPath.length); | |
oPath.index = 0; | |
results = getPathSet( | |
requestedPathSet, ref, 0, root, root, root, j, | |
expired, lru, true, rPath, oPath, rPaths, oPaths | |
); | |
var n2 = results[0]; | |
var j2 = results[1]; | |
var p2 = results[2]; | |
if (!n2) { | |
ns.push(n2); | |
js.push(j2); | |
ps.push(p2); | |
} else if (!isArray(n2)) { | |
count -= 1; | |
nodes[index] = n2; | |
jsons[index] = j2; | |
parents[index] = p2; | |
} else { | |
count += n2.length; | |
nodes.push.apply(nodes, n2); | |
jsons.push.apply(jsons, j2); | |
parents.push.apply(parents, p2); | |
} | |
continue; | |
} | |
if (t !== undefined) { | |
ns.push(n); | |
js.push(j); | |
ps.push(p); | |
continue; | |
} | |
p = n; | |
n = n[key]; | |
if (n) { | |
t = n.$type; | |
if (!isBranch) { | |
if (isFollowingReference) { | |
if (t !== 'ref' && t !== 'refset') { | |
j = j[key] = Object.defineProperties({}, { | |
$__key: { writable: false, enumerable: false, value: n.ツkey }, | |
$__path: { writable: false, enumerable: false, value: n.ツpath }, | |
$__version: { writable: true, enumerable: true, value: n.ツversion }, | |
$__refPath: { writable: false, enumerable: false, value: (t === 'ref' || t === 'refset') ? n.value.slice(0) : undefined }, | |
$__toReference: { writable: false, enumerable: false, value: (t === 'ref' || t === 'refset') ? oPath.slice(0, oPath.index - 1) : undefined }, | |
}); | |
} | |
} else if (!j[key]) { | |
j = j[key] = n.value; | |
} else { | |
j = j[key]; | |
} | |
ns.push(n); | |
js.push(j); | |
ps.push(p); | |
} else { | |
if (!isFollowingReference) { | |
if (!j[key]) { | |
j = j[key] = Object.defineProperties(t === 'refset' ? [] : {}, { | |
$__key: { writable: false, enumerable: false, value: n.ツkey }, | |
$__path: { writable: false, enumerable: false, value: n.ツpath }, | |
$__version: { writable: true, enumerable: true, value: n.ツversion }, | |
$__refPath: { writable: false, enumerable: false, value: (t === 'ref' || t === 'refset') ? n.value.slice(0) : undefined }, | |
$__toReference: { writable: false, enumerable: false, value: (t === 'ref' || t === 'refset') ? oPath.slice(0, oPath.index - 1) : undefined }, | |
}); | |
} else { | |
j = j[key]; | |
} | |
} | |
results = getPathSet( | |
requestedPathSet, pathSet, depth + 1, root, p, n, j, | |
expired, lru, isFollowingReference, rPath, oPath, rPaths, oPaths); | |
ns.push.apply(ns, results[0]); | |
js.push.apply(js, results[1]); | |
js.push.apply(ps, results[2]); | |
} | |
} else { | |
rPaths.push(rPath | |
.slice(0, rPath.index + Number(!isFollowingReference)) | |
.concat(requestedPathSet.slice(rPath.index + Number(!isFollowingReference)))); | |
oPaths.push(oPath | |
.slice(0, oPath.index) | |
.concat(requestedPathSet.slice(rPath.index + Number(!isFollowingReference)))); | |
} | |
} else { | |
rPaths.push(rPath | |
.slice(0, rPath.index) | |
.concat(requestedPathSet.slice(rPath.index))); | |
oPaths.push(oPath | |
.slice(0, oPath.index - 1) | |
.concat(requestedPathSet.slice(rPath.index))); | |
} | |
} | |
key = iterateKeySet(keySet, note); | |
if (note.done) { | |
break; | |
} | |
oPath.index = oIndex; | |
} while (true); | |
return [ns, js, ps]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var toPaths=require("./toPaths");var toTree=require("./toTree");module.exports=function collapse(paths){var collapseMap=paths.reduce(function(acc,path){var len=path.length;if(!acc[len]){acc[len]=[]}acc[len].push(path);return acc},{});Object.keys(collapseMap).forEach(function(collapseKey){collapseMap[collapseKey]=toTree(collapseMap[collapseKey])});return toPaths(collapseMap)}},{"./toPaths":12,"./toTree":13}],2:[function(require,module,exports){module.exports={innerReferences:"References with inner references are not allowed.",circularReference:"There appears to be a circular reference, maximum reference following exceeded."}},{}],3:[function(require,module,exports){var cloneArray=require("./support/cloneArray");var $ref=require("./support/types").$ref;var errors=require("./errors");module.exports=function followReference(cacheRoot,ref,maxRefFollow){var current=cacheRoot;var refPath=ref;var depth=-1;var length=refPath.length;var key,next,type;var referenceCount=0;while(++depth<length){key=refPath[depth];next=current[key];type=next&&next.$type;if(!next||type&&type!==$ref){current=next;break}if(type&&type===$ref&&depth+1<length){var err=new Error(errors.innerReferences);err.throwToNext=true;throw err}if(depth+1===length){if(type===$ref){depth=-1;refPath=next.value;length=refPath.length;next=cacheRoot;referenceCount++}if(referenceCount>maxRefFollow){throw new Error(errors.circularReference)}}current=next}return[current,cloneArray(refPath)]}},{"./errors":2,"./support/cloneArray":10,"./support/types":11}],4:[function(require,module,exports){var iterateKeySet=require("./iterateKeySet");module.exports=function hasIntersection(tree,path,depth){var current=tree;var intersects=true;for(;intersects&&depth<path.length;++depth){var key=path[depth];var keyType=typeof key;if(key&&keyType==="object"){var note={};var innerKey=iterateKeySet(key,note);var nextDepth=depth+1;do{var next=current[innerKey];intersects=next!==undefined;if(intersects){intersects=hasIntersection(next,path,nextDepth)}innerKey=iterateKeySet(key,note)}while(intersects&&!note.done);break}current=current[key];intersects=current!==undefined}return intersects}},{"./iterateKeySet":5}],5:[function(require,module,exports){var isArray=Array.isArray;module.exports=function iterateKeySet(keySet,note){if(note.isArray===undefined){initializeNote(keySet,note)}if(note.isArray){var nextValue;do{if(note.loaded&¬e.rangeOffset>note.to){++note.arrayOffset;note.loaded=false}var idx=note.arrayOffset,length=keySet.length;if(idx>=length){note.done=true;break}var el=keySet[note.arrayOffset];var type=typeof el;if(type==="object"){if(!note.loaded){initializeRange(el,note)}if(note.empty){continue}nextValue=note.rangeOffset++}else{++note.arrayOffset;nextValue=el}}while(nextValue===undefined);return nextValue}else if(note.isObject){if(!note.loaded){initializeRange(keySet,note)}if(note.rangeOffset>note.to){note.done=true;return undefined}return note.rangeOffset++}else{note.done=true;return keySet}};function initializeRange(key,memo){var from=memo.from=key.from||0;var to=memo.to=key.to||(typeof key.length==="number"&&memo.from+key.length-1||0);memo.rangeOffset=memo.from;memo.loaded=true;if(from>to){memo.empty=true}}function initializeNote(key,note){note.done=false;var isObject=note.isObject=!!(key&&typeof key==="object");note.isArray=isObject&&isArray(key);note.arrayOffset=0}},{}],6:[function(require,module,exports){var iterateKeySet=require("./iterateKeySet");var cloneArray=require("./support/cloneArray");var catAndSlice=require("./support/catAndSlice");var $types=require("./support/types");var $ref=$types.$ref;var followReference=require("./followReference");module.exports=function optimizePathSets(cache,paths,maxRefFollow){var optimized=[];paths.forEach(function(p){optimizePathSet(cache,cache,p,0,optimized,[],maxRefFollow)});return optimized};function optimizePathSet(cache,cacheRoot,pathSet,depth,out,optimizedPath,maxRefFollow){if(cache===undefined){out[out.length]=catAndSlice(optimizedPath,pathSet,depth);return}if(cache===null||cache.$type&&cache.$type!==$ref||typeof cache!=="object"){return}if(cache.$type===$ref&&depth===pathSet.length){return}var keySet=pathSet[depth];var isKeySet=typeof keySet==="object";var nextDepth=depth+1;var iteratorNote=false;var key=keySet;if(isKeySet){iteratorNote={};key=iterateKeySet(keySet,iteratorNote)}var next,nextOptimized;do{next=cache[key];var optimizedPathLength=optimizedPath.length;if(key!==null){optimizedPath[optimizedPathLength]=key}if(next&&next.$type===$ref&&nextDepth<pathSet.length){var refResults=followReference(cacheRoot,next.value,maxRefFollow);next=refResults[0];nextOptimized=cloneArray(refResults[1])}else{nextOptimized=optimizedPath}optimizePathSet(next,cacheRoot,pathSet,nextDepth,out,nextOptimized,maxRefFollow);optimizedPath.length=optimizedPathLength;if(iteratorNote&&!iteratorNote.done){key=iterateKeySet(keySet,iteratorNote)}}while(iteratorNote&&!iteratorNote.done)}},{"./followReference":3,"./iterateKeySet":5,"./support/catAndSlice":9,"./support/cloneArray":10,"./support/types":11}],7:[function(require,module,exports){var hasIntersection=require("./hasIntersection");module.exports=function pathsComplementFromLengthTree(paths,tree){var out=[];var outLength=-1;for(var i=0,len=paths.length;i<len;++i){var path=paths[i];if(!hasIntersection(tree[path.length],path,0)){out[++outLength]=path}}return out}},{"./hasIntersection":4}],8:[function(require,module,exports){var hasIntersection=require("./hasIntersection");module.exports=function pathsComplementFromTree(paths,tree){var out=[];var outLength=-1;for(var i=0,len=paths.length;i<len;++i){if(!hasIntersection(tree,paths[i],0)){out[++outLength]=paths[i]}}return out}},{"./hasIntersection":4}],9:[function(require,module,exports){module.exports=function catAndSlice(a,b,slice){var next=[],i,j,len;for(i=0,len=a.length;i<len;++i){next[i]=a[i]}for(j=slice||0,len=b.length;j<len;++j,++i){next[i]=b[j]}return next}},{}],10:[function(require,module,exports){function cloneArray(arr,index){var a=[];var len=arr.length;for(var i=index||0;i<len;i++){a[i]=arr[i]}return a}module.exports=cloneArray},{}],11:[function(require,module,exports){module.exports={$ref:"ref",$atom:"atom",$error:"error"}},{}],12:[function(require,module,exports){var isArray=Array.isArray;var typeOfObject="object";module.exports=function toPaths(lengths){var pathmap;var allPaths=[];var allPathsLength=0;for(var length in lengths){if(isNumber(length)&&isObject(pathmap=lengths[length])){var paths=collapsePathMap(pathmap,0,parseInt(length,10)).sets;var pathsIndex=-1;var pathsCount=paths.length;while(++pathsIndex<pathsCount){allPaths[allPathsLength++]=collapsePathSetIndexes(paths[pathsIndex])}}}return allPaths};function isObject(value){return value!==null&&typeof value===typeOfObject}function collapsePathMap(pathmap,depth,length){var key;var code=getHashCode(String(depth));var subs=Object.create(null);var codes=[];var codesIndex=-1;var codesCount=0;var pathsets=[];var pathsetsCount=0;var subPath,subCode,subKeys,subKeysIndex,subKeysCount,subSets,subSetsIndex,subSetsCount,pathset,pathsetIndex,pathsetCount,firstSubKey,pathsetClone;subKeys=[];subKeysIndex=-1;if(depth<length-1){subKeysCount=getSortedKeys(pathmap,subKeys);while(++subKeysIndex<subKeysCount){key=subKeys[subKeysIndex];subPath=collapsePathMap(pathmap[key],depth+1,length);subCode=subPath.code;if(subs[subCode]){subPath=subs[subCode]}else{codes[codesCount++]=subCode;subPath=subs[subCode]={keys:[],sets:subPath.sets}}code=getHashCode(code+key+subCode);isNumber(key)&&subPath.keys.push(parseInt(key,10))||subPath.keys.push(key)}while(++codesIndex<codesCount){key=codes[codesIndex];subPath=subs[key];subKeys=subPath.keys;subKeysCount=subKeys.length;if(subKeysCount>0){subSets=subPath.sets;subSetsIndex=-1;subSetsCount=subSets.length;firstSubKey=subKeys[0];while(++subSetsIndex<subSetsCount){pathset=subSets[subSetsIndex];pathsetIndex=-1;pathsetCount=pathset.length;pathsetClone=new Array(pathsetCount+1);pathsetClone[0]=subKeysCount>1&&subKeys||firstSubKey;while(++pathsetIndex<pathsetCount){pathsetClone[pathsetIndex+1]=pathset[pathsetIndex]}pathsets[pathsetsCount++]=pathsetClone}}}}else{subKeysCount=getSortedKeys(pathmap,subKeys);if(subKeysCount>1){pathsets[pathsetsCount++]=[subKeys]}else{pathsets[pathsetsCount++]=subKeys}while(++subKeysIndex<subKeysCount){code=getHashCode(code+subKeys[subKeysIndex])}}return{code:code,sets:pathsets}}function collapsePathSetIndexes(pathset){var keysetIndex=-1;var keysetCount=pathset.length;while(++keysetIndex<keysetCount){var keyset=pathset[keysetIndex];if(isArray(keyset)){pathset[keysetIndex]=collapseIndex(keyset)}}return pathset}function collapseIndex(keyset){var keyIndex=-1;var keyCount=keyset.length-1;var isSparseRange=keyCount>0;while(++keyIndex<=keyCount){var key=keyset[keyIndex];if(!isNumber(key)){isSparseRange=false;break}keyset[keyIndex]=parseInt(key,10)}if(isSparseRange===true){keyset.sort(sortListAscending);var from=keyset[0];var to=keyset[keyCount];if(to-from<=keyCount){return{from:from,to:to}}}return keyset}function sortListAscending(a,b){return a-b}function getSortedKeys(map,keys,sort){var len=0;for(var key in map){keys[len++]=key}if(len>1){keys.sort(sort)}return len}function getHashCode(key){var code=5381;var index=-1;var count=key.length;while(++index<count){code=(code<<5)+code+key.charCodeAt(index)}return String(code)}function isNumber(val){return!isArray(val)&&val-parseFloat(val)+1>=0}},{}],13:[function(require,module,exports){var iterateKeySet=require("./../lib/iterateKeySet");var isArray=Array.isArray;module.exports=function toTree(paths){return paths.reduce(function(acc,path){innerToTree(acc,path,0);return acc},{})};function innerToTree(seed,path,depth){var keySet=path[depth];var iteratorNote={};var key;var nextDepth=depth+1;key=iterateKeySet(keySet,iteratorNote);do{var next=seed[key];if(!next){if(nextDepth===path.length){seed[key]=null}else{next=seed[key]={}}}if(nextDepth<path.length){innerToTree(next,path,nextDepth)}if(!iteratorNote.done){key=iterateKeySet(keySet,iteratorNote)}}while(!iteratorNote.done)}},{"./../lib/iterateKeySet":5}],14:[function(require,module,exports){},{}],"falcor-path-utils":[function(require,module,exports){module.exports={iterateKeySet:require("./iterateKeySet"),toTree:require("./toTree"),toTreeWithUnion:require("./toTreeWithUnion"),pathsComplementFromTree:require("./pathsComplementFromTree"),pathsComplementFromLengthTree:require("./pathsComplementFromLengthTree"),hasIntersection:require("./hasIntersection"),toPaths:require("./toPaths"),collapse:require("./collapse"),optimizePathSets:require("./optimizePathSets")}},{"./collapse":1,"./hasIntersection":4,"./iterateKeySet":5,"./optimizePathSets":6,"./pathsComplementFromLengthTree":7,"./pathsComplementFromTree":8,"./toPaths":12,"./toTree":13,"./toTreeWithUnion":14}]},{},[]);var isArray=Array.isArray;var iterateKeySet=require("falcor-path-utils").iterateKeySet;var paths=[["list","selected","name"],["list",[0,1,3,5],"name"],["list",5,"name"],["foo","bar"]];var jsonEnvelope={json:{}};var results=getJSON({_root:{cache:getCache()}},paths,jsonEnvelope);console.log(JSON.stringify(jsonEnvelope,null," "));console.log(JSON.stringify(jsonEnvelope.json.list.selected.map(function(x){return x.name})));console.log(" requested paths:",JSON.stringify(paths));console.log("missing requested paths:",JSON.stringify(results[0]));console.log("missing optimized paths:",JSON.stringify(results[1]));function getCache(){return{"ツpath":[],"ツversion":0,list:{"ツkey":"list","ツpath":["list"],"ツversion":0,selected:{$type:"refset",value:["list",[0,1,2]],"ツkey":"selected","ツpath":["list","selected"],"ツversion":0},0:{name:{$type:"atom",value:"name 0","ツkey":"name","ツpath":["list",0,"name"],"ツversion":0},"ツkey":0,"ツpath":["list",0],"ツversion":0},1:{name:{$type:"atom",value:"name 1","ツkey":"name","ツpath":["list",1,"name"],"ツversion":0},"ツkey":1,"ツpath":["list",1],"ツversion":0},2:{$type:"refset",value:["list",[3,4,5]],"ツkey":2,"ツpath":["list",2],"ツversion":0},3:{name:{$type:"atom",value:"name 3","ツkey":"name","ツpath":["list",3,"name"],"ツversion":0},"ツkey":3,"ツpath":["list",3],"ツversion":0},6:{name:{$type:"atom",value:"name 6","ツkey":"name","ツpath":["list",6,"name"],"ツversion":0},"ツkey":6,"ツpath":["list",6],"ツversion":0}}}}function getJSON(model,pathSets,jsonEnvelope){if(!jsonEnvelope){jsonEnvelope={}}var modelRoot=model._root;var lru=modelRoot;var expired=modelRoot.expired;var bound=model._path||[];var cache=modelRoot.cache;var node=cache;var json=jsonEnvelope.json||(jsonEnvelope.json={});var parent=node&&node.ツparent||cache;var rPath=[];var rPaths=[];var oPaths=[];var oIndex=bound.length;var pathSetIndex=-1;var pathSetCount=pathSets.length;while(++pathSetIndex<pathSetCount){var pathSet=pathSets[pathSetIndex];var oPath=bound.slice(0);oPath.index=oIndex;getPathSet(pathSet,pathSet,0,cache,parent,node,json,expired,lru,false,rPath,oPath,rPaths,oPaths)}return[rPaths,oPaths]}function getPathSet(requestedPathSet,pathSet,depth,root,parent,node,json,expired,lru,isFollowingReference,rPath,oPath,rPaths,oPaths){var ns=[],js=[],ps=[],results;var note={},keySet=pathSet[depth];var isBranch=depth<pathSet.length-1;var key=iterateKeySet(keySet,note);var oIndex=oPath.index;do{if(key==null){if(isBranch){throw"NullInPathError"}else{key=node.ツkey}}if(!isFollowingReference){rPath[depth]=key;rPath.index=depth}oPath[oPath.index++]=key;var index=-1;var count=1;var nodes=[node],jsons=[json],parents=[parent];while(++index<count){var n=nodes[index];var j=jsons[index];var p=parents[index];if(n){var t=n.$type;if(t==="ref"||t==="refset"){if(isFollowingReference&&isBranch){throw new Error("References must not cross other references.")}var ref=n.value;oPath.splice(0,oPath.length);oPath.index=0;results=getPathSet(requestedPathSet,ref,0,root,root,root,j,expired,lru,true,rPath,oPath,rPaths,oPaths);var n2=results[0];var j2=results[1];var p2=results[2];if(!n2){ns.push(n2);js.push(j2);ps.push(p2)}else if(!isArray(n2)){count-=1;nodes[index]=n2;jsons[index]=j2;parents[index]=p2}else{count+=n2.length;nodes.push.apply(nodes,n2);jsons.push.apply(jsons,j2);parents.push.apply(parents,p2)}continue}if(t!==undefined){ns.push(n);js.push(j);ps.push(p);continue}p=n;n=n[key];if(n){t=n.$type;if(!isBranch){if(isFollowingReference){if(t!=="ref"&&t!=="refset"){j=j[key]=Object.defineProperties({},{$__key:{writable:false,enumerable:false,value:n.ツkey},$__path:{writable:false,enumerable:false,value:n.ツpath},$__version:{writable:true,enumerable:true,value:n.ツversion},$__refPath:{writable:false,enumerable:false,value:t==="ref"||t==="refset"?n.value.slice(0):undefined},$__toReference:{writable:false,enumerable:false,value:t==="ref"||t==="refset"?oPath.slice(0,oPath.index-1):undefined}})}}else if(!j[key]){j=j[key]=n.value}else{j=j[key]}ns.push(n);js.push(j);ps.push(p)}else{if(!isFollowingReference){if(!j[key]){j=j[key]=Object.defineProperties(t==="refset"?[]:{},{$__key:{writable:false,enumerable:false,value:n.ツkey},$__path:{writable:false,enumerable:false,value:n.ツpath},$__version:{writable:true,enumerable:true,value:n.ツversion},$__refPath:{writable:false,enumerable:false,value:t==="ref"||t==="refset"?n.value.slice(0):undefined},$__toReference:{writable:false,enumerable:false,value:t==="ref"||t==="refset"?oPath.slice(0,oPath.index-1):undefined}})}else{j=j[key]}}results=getPathSet(requestedPathSet,pathSet,depth+1,root,p,n,j,expired,lru,isFollowingReference,rPath,oPath,rPaths,oPaths);ns.push.apply(ns,results[0]);js.push.apply(js,results[1]);js.push.apply(ps,results[2])}}else{rPaths.push(rPath.slice(0,rPath.index+Number(!isFollowingReference)).concat(requestedPathSet.slice(rPath.index+Number(!isFollowingReference))));oPaths.push(oPath.slice(0,oPath.index).concat(requestedPathSet.slice(rPath.index+Number(!isFollowingReference))))}}else{rPaths.push(rPath.slice(0,rPath.index).concat(requestedPathSet.slice(rPath.index)));oPaths.push(oPath.slice(0,oPath.index-1).concat(requestedPathSet.slice(rPath.index)))}}key=iterateKeySet(keySet,note);if(note.done){break}oPath.index=oIndex}while(true);return[ns,js,ps]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"falcor-path-utils": "0.4.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <body> --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <head> --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment