Comparing version 0.4.0 to 0.5.0
509
gedi.js
@@ -95,6 +95,2 @@ //Copyright (C) 2012 Kory Nunn | ||
return array; | ||
}; | ||
function pathTokenCallback(value, scopedVariables) { | ||
return get(resolvePath(scopedVariables._gediModelContext_, value), model); | ||
} | ||
@@ -153,4 +149,4 @@ | ||
return isDirty(resolvePath(scope.get('_gediModelContext_'), (token instanceof PathToken) ? token.original : new Path())); | ||
} | ||
return isDirty(resolvePath(scope.get('_gediModelContext_'), (token instanceof PathToken) ? token.original : createPath())); | ||
}; | ||
@@ -172,3 +168,3 @@ gel.scope.getAllDirty = function (scope, args) { | ||
if (source.hasOwnProperty(key)) { | ||
itemPath = resolvePath(path, key); | ||
itemPath = resolvePath(path, createPath(key)); | ||
if (result instanceof Array) { | ||
@@ -203,14 +199,13 @@ isDirty(itemPath) && result.push(source[key]); | ||
} | ||
path = Path.parse(path); | ||
if(path.isRoot()){ | ||
if(isPathRoot(path)){ | ||
return model; | ||
} | ||
var reference = model, | ||
var pathParts = pathToParts(path), | ||
reference = model, | ||
index = 0, | ||
pathLength = path.length; | ||
pathLength = pathParts.length; | ||
if(path.isAbsolute()){ | ||
if(isPathAbsolute(path)){ | ||
index = 1; | ||
@@ -220,3 +215,3 @@ } | ||
for(; index < pathLength; index++){ | ||
var key = path[index]; | ||
var key = pathParts[index]; | ||
@@ -239,3 +234,3 @@ if (reference == null) { | ||
memoiseCache[path.toString()] = { | ||
memoiseCache[path] = { | ||
model: model, | ||
@@ -280,10 +275,12 @@ value: reference | ||
// If you just pass in an object, you are overwriting the model. | ||
if (typeof path === "object" && !(path instanceof Path) && !(path instanceof Expression)) { | ||
if (typeof path === "object") { | ||
value = path; | ||
path = Path.root(); | ||
path = createRootPath; | ||
} | ||
path = Path.parse(path); | ||
if(path.isRoot()){ | ||
var pathParts = pathToParts(path), | ||
index = 0, | ||
pathLength = pathParts.length; | ||
if(isPathRoot(path)){ | ||
overwriteModel(value, model); | ||
@@ -293,6 +290,3 @@ return; | ||
var index = 0, | ||
pathLength = path.length; | ||
if(path.isAbsolute()){ | ||
if(isPathAbsolute(path)){ | ||
index = 1; | ||
@@ -304,7 +298,7 @@ } | ||
for(; index < pathLength; index++){ | ||
var key = path[index]; | ||
var key = pathParts[index]; | ||
// if we have hit a non-object property on the reference and we have more keys after this one | ||
// make an object (or array) here and move on. | ||
if ((typeof reference[key] !== "object" || reference[key] === null) && index < path.length - 1) { | ||
if ((typeof reference[key] !== "object" || reference[key] === null) && index < pathLength - 1) { | ||
if (!isNaN(key)) { | ||
@@ -339,5 +333,7 @@ reference[key] = []; | ||
path = Path.parse(path); | ||
var pathParts = pathToParts(path), | ||
index = 0, | ||
pathLength = pathParts.length; | ||
if(path.isRoot()){ | ||
if(isPathRoot(path)){ | ||
overwriteModel({}, model); | ||
@@ -347,6 +343,3 @@ return; | ||
var index = 0, | ||
pathLength = path.length; | ||
if(path.isAbsolute()){ | ||
if(isPathAbsolute(path)){ | ||
index = 1; | ||
@@ -356,5 +349,5 @@ } | ||
for(; index < pathLength; index++){ | ||
var key = path[index]; | ||
var key = pathParts[index]; | ||
//if we have hit a non-object and we have more keys after this one | ||
if (typeof reference[key] !== "object" && index < path.length - 1) { | ||
if (typeof reference[key] !== "object" && index < pathLength - 1) { | ||
break; | ||
@@ -386,8 +379,3 @@ } | ||
function trigger(path) { | ||
if (eventsPaused) { | ||
return; | ||
} | ||
path = Path.parse(path); | ||
var reference = internalBindings, | ||
@@ -402,2 +390,3 @@ references = [reference], | ||
callbackBinding = callback.binding, | ||
callbackBindingParts, | ||
parentPath = callback.parentPath, | ||
@@ -407,6 +396,6 @@ wildcardIndex = callbackBinding.indexOf(gediConstructor.pathWildcard), | ||
if(wildcardIndex >= 0 && Expression.parse(callbackBinding).paths[0].toString() === callbackBinding.toString()){ | ||
if(wildcardIndex >= 0 && getPathsInExpression(callbackBinding)[0] === callbackBinding){ | ||
//fully resolve the callback path | ||
callbackBinding = resolvePath('[/]', callback.parentPath, callbackBinding); | ||
callbackBindingParts = pathToParts(resolvePath('[/]', callback.parentPath, callbackBinding)); | ||
@@ -416,5 +405,5 @@ //null out the now not needed parent path | ||
fastEach(callbackBinding, function(pathPart, i){ | ||
fastEach(callbackBindingParts, function(pathPart, i){ | ||
if(pathPart === gediConstructor.pathWildcard){ | ||
callbackBinding[i] = target[i]; | ||
callbackBindingParts[i] = target[i]; | ||
}else if (pathPart !== target[i]){ | ||
@@ -449,9 +438,10 @@ return wildcardMatchFail = true; | ||
if(path.isAbsolute()){ | ||
if(isPathAbsolute(path)){ | ||
index = 1; | ||
} | ||
for(; index < path.length; index++){ | ||
var key = path[index]; | ||
var pathParts = pathToParts(path); | ||
for(; index < pathParts.length; index++){ | ||
var key = pathParts[index]; | ||
if (!isNaN(key) || key in arrayProto) { | ||
@@ -470,4 +460,3 @@ key = "_" + key; | ||
while (references.length > 1) { | ||
var reference = references.shift(); | ||
reference = references.shift(); | ||
triggerListeners(reference); | ||
@@ -517,4 +506,4 @@ } | ||
//If the binding has opperators in it, break them apart and set them individually. | ||
if (!(binding instanceof Path)) { | ||
var paths = Expression.parse(binding).paths; | ||
if (!createPath(binding)) { | ||
var paths = getPathsInExpression(binding); | ||
@@ -528,9 +517,9 @@ fastEach(paths, function (path) { | ||
path = binding; | ||
callback.references.push(path); | ||
if (parentPath) { | ||
path = resolvePath('[/]', parentPath, path); | ||
path = resolvePath(createRootPath(), parentPath, path); | ||
} | ||
callback.references.push(path); | ||
// Handle wildcards | ||
@@ -543,3 +532,3 @@ | ||
if(path.isRoot()){ | ||
if(isPathRoot(path)){ | ||
reference.push(callback); | ||
@@ -551,9 +540,11 @@ return; | ||
if(path.isAbsolute()){ | ||
if(isPathAbsolute(path)){ | ||
index = 1; | ||
} | ||
for(; index < path.length; index++){ | ||
var key = path[index]; | ||
var pathParts = pathToParts(path); | ||
for(; index < pathParts.length; index++){ | ||
var key = pathParts[index]; | ||
//escape properties of the array with an underscore. | ||
@@ -568,7 +559,7 @@ // numbers mean a binding has been set on an array index. | ||
//make an array here and move on. | ||
if (typeof reference[key] !== "object" && index < path.length - 1) { | ||
if (typeof reference[key] !== "object" && index < pathParts.length - 1) { | ||
reference[key] = []; | ||
reference = reference[key]; | ||
} | ||
else if (index === path.length - 1) { | ||
else if (index === pathParts.length - 1) { | ||
// if we are at the end of the line, add the callback | ||
@@ -582,3 +573,3 @@ reference[key] = reference[key] || []; | ||
} | ||
}; | ||
} | ||
} | ||
@@ -608,3 +599,3 @@ | ||
}); | ||
}else{ | ||
}else{ | ||
internalBindings = []; | ||
@@ -614,5 +605,6 @@ } | ||
} | ||
if(!(path instanceof Path)){ | ||
fastEach(Expression.parse(path).paths, function(path){ | ||
var paths = getPathsInExpression(path); | ||
if(paths.length > 1){ | ||
fastEach(paths, function(path){ | ||
removeBinding(path, callback); | ||
@@ -623,14 +615,14 @@ }); | ||
var resolvedPath = resolvePath(parentPath, path), | ||
var resolvedPathParts = pathToParts(resolvePath(parentPath, path)), | ||
bindingPathParts = []; | ||
for(var i = 0; i < resolvedPath.length; i++){ | ||
if(parseInt(resolvedPath[i]).toString() === resolvedPath[i]){ | ||
bindingPathParts[i] = '_' + resolvedPath[i]; | ||
for(var i = 0; i < resolvedPathParts.length; i++){ | ||
if(parseInt(resolvedPathParts[i]).toString() === resolvedPathParts[i]){ | ||
bindingPathParts[i] = '_' + resolvedPathParts[i]; | ||
}else{ | ||
bindingPathParts[i] = resolvedPath[i]; | ||
bindingPathParts[i] = resolvedPathParts[i]; | ||
} | ||
} | ||
var escapedPath = new Path(bindingPathParts); | ||
var escapedPath = createPath(bindingPathParts); | ||
@@ -661,19 +653,22 @@ if(!callback){ | ||
//*********************************************** | ||
var memoisedExpressionPaths = {}; | ||
function getPathsInExpression(expression) { | ||
var paths = []; | ||
function getPathsInExpression(exp) { | ||
var paths = [], | ||
expressionString = exp instanceof Expression ? exp.original : exp; | ||
if(memoisedExpressionPaths[expression]){ | ||
return memoisedExpressionPaths[expression]; | ||
} | ||
if (gel) { | ||
var tokens = gel.tokenise(expressionString); | ||
var tokens = gel.tokenise(expression); | ||
for(var index = 0; index < tokens.length; index++){ | ||
var token = tokens[index]; | ||
if(token instanceof PathToken){ | ||
paths.push(Path.parse(token.original)); | ||
paths.push(token.original); | ||
} | ||
} | ||
} else { | ||
return [Path.parse(expressionString)]; | ||
return memoisedExpressionPaths[expression] = [createPath(expression)]; | ||
} | ||
return paths; | ||
return memoisedExpressionPaths[expression] = paths; | ||
} | ||
@@ -698,3 +693,3 @@ | ||
function rawToPath(rawPath) { | ||
return gediConstructor.pathStart + rawPath + gediConstructor.pathEnd; | ||
return gediConstructor.pathStart + (rawPath == null ? '' : rawPath) + gediConstructor.pathEnd; | ||
} | ||
@@ -708,17 +703,30 @@ | ||
var memoisePathCache = {}; | ||
function resolvePath() { | ||
var memoiseKey = ''; | ||
for(var argumentIndex = 0; argumentIndex < arguments.length; argumentIndex++){ | ||
memoiseKey += arguments[argumentIndex]; | ||
} | ||
if(memoisePathCache[memoiseKey]){ | ||
return memoisePathCache[memoiseKey]; | ||
} | ||
var absoluteParts = [], | ||
lastRemoved; | ||
lastRemoved, | ||
pathParts, | ||
pathPart; | ||
for(var i = 0; i < arguments.length; i++){ | ||
var path = arguments[i]; | ||
for(var argumentIndex = 0; argumentIndex < arguments.length; argumentIndex++){ | ||
pathParts = pathToParts(arguments[argumentIndex]); | ||
if(!(path instanceof Path)){ | ||
path = Path.parse(path); | ||
if(!pathParts || !pathParts.length){ | ||
continue; | ||
} | ||
for(var index = 0; index < path.length; index++){ | ||
var pathPart = path[index]; | ||
for(var pathPartIndex = 0; pathPartIndex < pathParts.length; pathPartIndex++){ | ||
pathPart = pathParts[pathPartIndex]; | ||
if(path.length === 0){ | ||
if(pathParts.length === 0){ | ||
// Empty path, maintain parent path. | ||
@@ -731,3 +739,7 @@ } else if (pathPart === gediConstructor.currentKey) { | ||
} | ||
} else if (pathPart.length === 2 && pathPart === gediConstructor.upALevel) { | ||
} else if (pathPart === gediConstructor.rootPath) { | ||
// Root path? Reset parts to be absolute. | ||
absoluteParts = ['']; | ||
} else if (pathPart === gediConstructor.upALevel) { | ||
// Up a level? Remove the last item in absoluteParts | ||
@@ -744,11 +756,5 @@ lastRemoved = absoluteParts.pop(); | ||
} | ||
} else if (pathPart === gediConstructor.rootPath) { | ||
// Root path? Do nothing | ||
absoluteParts = ['']; | ||
} else { | ||
// any following valid part? Add it to the absoluteParts. | ||
absoluteParts.push(pathPart); | ||
} | ||
@@ -758,4 +764,4 @@ } | ||
// Convert the absoluteParts to a Path. | ||
return new Path(absoluteParts); | ||
// Convert the absoluteParts to a Path and memoise the result. | ||
return memoisePathCache[memoiseKey] = createPath(absoluteParts); | ||
} | ||
@@ -770,5 +776,5 @@ | ||
function modelGet(binding, parentPath, scope, returnAsTokens) { | ||
if(parentPath && !(typeof parentPath === "string" || parentPath instanceof Path)){ | ||
if(parentPath && typeof parentPath !== "string"){ | ||
scope = parentPath; | ||
parentPath = new Path(); | ||
parentPath = createPath(); | ||
} | ||
@@ -784,10 +790,6 @@ | ||
if (binding instanceof Path || binding instanceof Expression) { | ||
expression = binding.toString(); | ||
} | ||
return gel.evaluate(expression, scope, returnAsTokens); | ||
} | ||
parentPath = parentPath || new Path(); | ||
parentPath = parentPath || createPath(); | ||
@@ -806,6 +808,6 @@ binding = resolvePath(parentPath, binding); | ||
function modelSet(path, value, parentPath, dirty) { | ||
if(typeof path === 'object' && !Path.mightParse(path)){ | ||
if(typeof path === 'object' && !createPath(path)){ | ||
dirty = value; | ||
value = path; | ||
path = Path.root(); | ||
path = createRootPath(); | ||
}else if(typeof parentPath === 'boolean'){ | ||
@@ -816,5 +818,5 @@ dirty = parentPath; | ||
parentPath = parentPath || new Path(); | ||
parentPath = parentPath || createPath(); | ||
path = new resolvePath(parentPath, path); | ||
path = resolvePath(parentPath, path); | ||
@@ -838,3 +840,3 @@ setDirtyState(path, dirty); | ||
parentPath = parentPath || new Path(); | ||
parentPath = parentPath || createPath(); | ||
@@ -865,13 +867,12 @@ path = resolvePath(parentPath, path); | ||
if(!Path.mightParse(path)){ | ||
if(!createPath(path)){ | ||
throw exceptions.invalidPath; | ||
} | ||
parentPath = parentPath || new Path(); | ||
parentPath = parentPath || createPath(); | ||
path = resolvePath(parentPath, path); | ||
dirty = dirty !== false; | ||
if(path.isRoot()){ | ||
if(isPathRoot(path)){ | ||
dirtyModel = { | ||
@@ -885,12 +886,14 @@ '_isDirty_': dirty | ||
if(path.isAbsolute()){ | ||
if(isPathAbsolute(path)){ | ||
index = 1; | ||
} | ||
for(; index < path.length; index++){ | ||
var key = path[index]; | ||
if ((typeof reference[key] !== "object" || reference[key] === null) && index < path.length - 1) { | ||
var pathParts = pathToParts(resolvePath(parentPath, path)); | ||
for(; index < pathParts.length; index++){ | ||
var key = pathParts[index]; | ||
if ((typeof reference[key] !== "object" || reference[key] === null) && index < pathParts.length - 1) { | ||
reference[key] = {}; | ||
} | ||
if (index === path.length - 1) { | ||
if (index === pathParts.length - 1) { | ||
reference[key] = {}; | ||
@@ -904,3 +907,3 @@ reference[key]['_isDirty_'] = dirty; | ||
if(!path.length){ | ||
if(!pathParts.length){ | ||
dirtyModel['_isDirty_'] = dirty; | ||
@@ -933,4 +936,2 @@ } | ||
path = Path.parse(path); | ||
reference = get(path, dirtyModel); | ||
@@ -943,201 +944,113 @@ | ||
// IE7 is a pile of shit and won't let you inherit from arrays. | ||
function inheritFromArray() { | ||
inheritFromArray.canInherit = inheritFromArray.canInherit || (function () { | ||
function ie7Test() { } | ||
ie7Test.prototype = new Array(); | ||
var instance = new ie7Test(); | ||
instance.push(1); | ||
return instance.length === 1; | ||
})(); | ||
var memoisedPathTokens = {}; | ||
if (inheritFromArray.canInherit) { | ||
return new Array(); | ||
} else { | ||
var tempPrototype = {}; | ||
for (var key in arrayProto) { | ||
tempPrototype[key] = arrayProto[key]; | ||
} | ||
tempPrototype.length = 0; | ||
tempPrototype.pop = arrayProto.pop; | ||
tempPrototype.push = arrayProto.push; | ||
tempPrototype.slice = arrayProto.slice; | ||
tempPrototype.splice = arrayProto.splice; | ||
tempPrototype.join = arrayProto.join; | ||
tempPrototype.indexOf = arrayProto.indexOf; | ||
// add fastEach | ||
tempPrototype.fastEach = arrayProto.fastEach; | ||
return tempPrototype; | ||
function createPath(path){ | ||
if(path == null){ | ||
return rawToPath(); | ||
} | ||
} | ||
//*********************************************** | ||
// | ||
// Path Object | ||
// | ||
//*********************************************** | ||
// passed in an Expression or an 'expression formatted' Path (eg: '[bla]') | ||
if(memoisedPathTokens[path]){ | ||
return memoisedPathTokens[path]; | ||
}else if (typeof path === "string"){ | ||
if(path.charAt(0) === gediConstructor.pathStart) { | ||
var pathString = path.toString(), | ||
detectedPathToken = detectPathToken(pathString); | ||
var memoisedPathTokens = {}; | ||
function pathTokenToPath(pathToken){ | ||
var result = pathToken.original.slice(1,-1); | ||
if(result.indexOf('\\') < 0){ | ||
return result; | ||
if (detectedPathToken && detectedPathToken.length === pathString.length) { | ||
return memoisedPathTokens[pathString] = detectedPathToken.original; | ||
} else { | ||
return false; | ||
} | ||
}else{ | ||
return createPath(rawToPath(path)); | ||
} | ||
} | ||
for(var i = 0; i < result.length; i++){ | ||
if(result.charAt(i) === '\\'){ | ||
if(result.charAt(i+1) === '\\' || result.charAt(i+1) === ']' || result.charAt(i+1) === '['){ | ||
result = result.slice(0, i) + result.slice(i + 1); | ||
if(path instanceof Array) { | ||
var parts = []; | ||
for (var i = 0; i < path.length; i++) { | ||
var pathPart = path[i]; | ||
if(pathPart.indexOf('\\') >= 0){ | ||
pathPart = pathPart.replace(/([\[|\]|\\|\/])/g, '\\$1'); | ||
} | ||
parts.push(pathPart); | ||
} | ||
return rawToPath(parts.join(gediConstructor.pathSeparator)); | ||
} | ||
} | ||
return result; | ||
function createRootPath(){ | ||
return createPath([gediConstructor.rootPath, gediConstructor.rootPath]); | ||
} | ||
function constructPath(instance, path){ | ||
function pathToParts(path){ | ||
if(!path){ | ||
return; | ||
} | ||
if(Array.isArray(path)){ | ||
return path; | ||
} | ||
// passed in an Expression or an 'expression formatted' Path (eg: '[bla]') | ||
if(memoisedPathTokens[path]){ | ||
path = memoisedPathTokens[path]; | ||
}else if ((typeof path === "string" && path.charAt(0) === gediConstructor.pathStart) || path instanceof Expression) { | ||
var pathString = path.toString(), | ||
detectedPathToken = detectPathToken(pathString); | ||
path = path.slice(1,-1); | ||
if (detectedPathToken && detectedPathToken.length === pathString.length) { | ||
path = memoisedPathTokens[pathString] = pathTokenToPath(detectedPathToken); | ||
} else { | ||
console.warn('Invalid Path syntax'); | ||
var lastPartIndex = 0, | ||
parts, | ||
nextChar, | ||
currentChar; | ||
if(path.indexOf('\\') < 0){ | ||
if(path === ""){ | ||
return []; | ||
} | ||
return path.split(gediConstructor.pathSeparator); | ||
} | ||
if(typeof path === 'string'){ | ||
var pathParts; | ||
if(path.indexOf(gediConstructor.pathSeparator) >= 0){ | ||
pathParts = path.split(gediConstructor.pathSeparator); | ||
if(pathParts[0] === '' && pathParts[1] === ''){ | ||
pathParts.pop(); | ||
parts = []; | ||
for(var i = 0; i < path.length; i++){ | ||
currentChar = path.charAt(i); | ||
if(currentChar === gediConstructor.pathSeparator){ | ||
parts.push(path.slice(lastPartIndex,i)); | ||
lastPartIndex = i+1; | ||
}else if(currentChar === '\\'){ | ||
nextChar = path.charAt(i+1); | ||
if(nextChar === '\\'){ | ||
path = path.slice(0, i) + path.slice(i + 1); | ||
}else if(nextChar === ']' || nextChar === '['){ | ||
path = path.slice(0, i) + path.slice(i + 1); | ||
}else if(nextChar === gediConstructor.pathSeparator){ | ||
parts.push(path.slice(lastPartIndex), i); | ||
} | ||
}else{ | ||
if(path === ''){ | ||
pathParts = []; | ||
}else{ | ||
pathParts = [path]; | ||
} | ||
} | ||
} | ||
parts.push(path.slice(lastPartIndex)); | ||
while(pathParts.length){ | ||
instance.push(pathParts.shift()); | ||
} | ||
return parts; | ||
} | ||
} else if (path instanceof Array || path instanceof Path) { | ||
for (var i = 0; i < path.length; i++) { | ||
instance.push(path[i]); | ||
function appendPath(){ | ||
var parts = pathToParts(arguments[0]); | ||
for (var argumentIndex = 1; argumentIndex < arguments.length; argumentIndex++) { | ||
var pathParts = pathToParts(arguments[argumentIndex]); | ||
for (var partIndex = 0; partIndex < pathParts.length; partIndex++) { | ||
parts.push(pathParts[partIndex]); | ||
} | ||
} | ||
instance.original = path; | ||
return instance; | ||
return createPath(parts); | ||
} | ||
function Path(path) { | ||
return constructPath(this, path); | ||
function isPathAbsolute(path){ | ||
return pathToParts(path)[0] === gediConstructor.rootPath; | ||
} | ||
Path.prototype = inheritFromArray(); | ||
Path.prototype.push = Path.prototype.push || function () { | ||
Array.prototype.push.apply(this, arguments); | ||
this.length++; | ||
} | ||
Path.prototype.pop = Path.prototype.pop || function () { | ||
Array.prototype.pop.apply(this, arguments); | ||
this.length--; | ||
} | ||
Path.prototype.toString = function () { | ||
return rawToPath(this.join(gediConstructor.pathSeparator)); | ||
}; | ||
Path.prototype.toRawString = function () { | ||
return this.join(gediConstructor.pathSeparator); | ||
}; | ||
Path.prototype.slice = function () { | ||
return new Path(Array.prototype.slice.apply(this, arguments)); | ||
}; | ||
Path.prototype.splice = function () { | ||
return new Path(Array.prototype.splice.apply(this, arguments)); | ||
}; | ||
Path.prototype.append = function () { | ||
var result = this.slice(); | ||
fastEach(arguments, function(arg){ | ||
fastEach(Path.parse(arg), function(argPart){ | ||
result.push(argPart); | ||
}); | ||
}); | ||
return result; | ||
}; | ||
Path.prototype.last = function () { | ||
return this[this.length - 1]; | ||
}; | ||
Path.prototype.isRoot = function () { | ||
return (this.length === 1 && this.isAbsolute()) || this.length === 0; | ||
}; | ||
Path.prototype.isAbsolute = function () { | ||
return this[0] === gediConstructor.rootPath; | ||
}; | ||
Path.prototype.toJSON = function(){ | ||
return this.toString(); | ||
}; | ||
Path.parse = function (path) { | ||
return path instanceof this && path || new Path(path); | ||
}; | ||
Path.mightParse = function (path) { | ||
return path instanceof this || path instanceof Expression || typeof path === 'string' || Array.isArray(path); | ||
}; | ||
Path.root = function () { | ||
return new Path(gediConstructor.rootPath); | ||
}; | ||
//*********************************************** | ||
// | ||
// Expression Object | ||
// | ||
//*********************************************** | ||
function Expression(input) { | ||
var expression = this, | ||
absolute = false; | ||
//Passed an Expression? pass it back. | ||
if (input instanceof Expression) { | ||
return input; | ||
} | ||
expression.original = input; | ||
if (typeof input === "string") { | ||
//passed a string or array? make a new Expression. | ||
var tokens = gel.tokenise(input); | ||
fastEach(tokens, function (key) { | ||
expression.push(key); | ||
}); | ||
} | ||
expression.paths = getPathsInExpression(expression); | ||
function isPathRoot(path){ | ||
var parts = pathToParts(path); | ||
return (isPathAbsolute(parts) && parts[0] === parts[1]) || parts.length === 0; | ||
} | ||
Expression.prototype = inheritFromArray(); | ||
Expression.prototype.toString = function () { | ||
return this.original; | ||
}; | ||
Expression.prototype.toJSON = function(){ | ||
return this.toString(); | ||
}; | ||
Expression.parse = function (input) { | ||
input instanceof Path && (input = input.toString()); | ||
return input instanceof Expression && input || new Expression(input); | ||
}; | ||
function Gedi() { | ||
@@ -1148,13 +1061,10 @@ | ||
Gedi.prototype = { | ||
Path: Path, | ||
Expression: Expression, | ||
paths: { | ||
create: createPath, | ||
resolve: resolvePath, | ||
isRoot: isPathRoot, | ||
isAbsolute: isPathAbsolute, | ||
append: appendPath | ||
}, | ||
// ************************************************************************* | ||
// DO NOT USE THIS API. | ||
// If you are using this, you are almost definitally doing something wrong. | ||
pauseEvents: pauseModelEvents, | ||
resumeEvents: resumeModelEvents, | ||
// ************************************************************************* | ||
get: modelGet, | ||
@@ -1184,3 +1094,3 @@ | ||
setDirtyState: setDirtyState, | ||
gel: gel, // expose gel instance for extension | ||
@@ -1204,5 +1114,4 @@ | ||
return new Gedi(); | ||
} | ||
module.exports = gediConstructor; |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"main": "gedi.js", | ||
@@ -11,0 +11,0 @@ "dependencies": { |
40735
845