Commits

adamschmideg committed 3eea4a5

when more path patterns resolve to the same target path, the first one wins @1.3

Comments (0)

Files changed (3)

     
 class DepGraph
   constructor: (map, parent=null) ->
-    @map = {}
-    if parent
-      _(@map).extend parent.map
-    # TODO: check in a more efficient way if new map overwrites anything
-    common = _.intersect(_.keys(map), _.keys(@map))
-    if _.isEmpty common
-      _(@map).extend map
-    else
-      throw new Error "Path already defined as target #{common}"
+    @map = if parent then parent.map else {}
+    @map = _(@map).defaults map
 
   resolutionOrder: (uniquePaths) ->
     unless @_dg
         absDependPath = targetUPath.join dependPath
         for uniqueDependPath in absDependPath.uniquePaths db
           dependPathStrings[uniqueDependPath.asString()] = yes
-      unless _.isEmpty dependPathStrings
-        result[targetUPath.asString()] = dependPathStrings
+      result[targetUPath.asString()] = dependPathStrings
     for k,v of result
       result[k] = _.keys v
     new DepGraph result
     #console.log 'updateObject', @asString(), '\n\t', obj, '\n\t', result.data()
     result
 
-@resolve = (data, depDicts, wantedExpressions...) ->
+@resolve = (data, depDicts, wantedExpressions) ->
   db = new Db data
   wantedPaths = _(wantedExpressions).map (x) -> new Path x
   db = db.update wantedPaths # add placeholders
   pathStrToDep = {}
   for dep in deps
     for up in dep.target.uniquePaths db
-      pathStrToDep[up.asString()] = dep
+      unless pathStrToDep[up.asString()]
+        pathStrToDep[up.asString()] = dep
   sortedUPs = depGraph.resolutionOrder wantedUPs
   fun = (db, up) ->
     current = db.value up
       dep = pathStrToDep[up.asString()]
       value = dep.calculateValue db, up
       result = db.setValue up, value
-      #console.log 'value', result
+      #console.log 'value', value
       result
     else
       db

test/dependency.coffee

       depends:
         base: '../</value'
     out:
+      '/items/0/value': []
       '/items/1/value': ['/items/0/value']
+  ,
+    in:
+      target: '/main/base'
+    out:
+      '/main/base': []
   ]
 
 @fullDepGraph = (assert) ->
   ,
     in: [[
       target: '/items/0/value'
-      depends:
-        base: '../base'
     ,
       target: '/items/*/value'
       depends:
-        base: '../base'
+        base: '../</value'
     ]]
-    out: 'Error: Path already defined as target /items/0/value'
+    out:
+      '/items/0/value': []
+      '/items/1/value': ['/items/0/value']
   ]
 
 @resolutionOrder = (assert) ->
     in:
       map:
         '/main/value': ['/items/0/value', '/items/1/value']
-        '/items/0/value': ['/items/0/base']
+        '/items/0/value': []
         '/items/1/value': ['/items/0/value', '/items/1/base']
       wanted:
         ['/main/value']
     out: [
-      '/items/0/base'
       '/items/0/value'
       '/items/1/base'
       '/items/1/value'

test/resolve.coffee

       sum - @discount
   ]
 
-  result = resolve data, deps, '/general/price', '/products/*/price'
+  result = resolve data, deps, ['/general/price', '/products/*/price']
   expected =
     general:
       discount: 0.1
   assert.done()
 
 @fibonacci = (assert) ->
-  data = nums: [{},{}]
-  data.nums[0].index = 1
-  data.nums[1].index = 1
+  data = {}
   deps = [
+    target: '/nums/0/index'
+    calculate: -> 1
+  ,
+    target: '/nums/1/index'
+    calculate: -> 1
+  ,
     target: '/nums/*/index'
     depends:
       prev: '../</index'
     calculate: ->
       @prev + @prev2 
   ]
-  result = resolve data, deps, '/nums/6/index'
+  result = resolve data, deps, ['/nums/6/index']
   assert.deepEqual [1,1,2,3,5,8,13], _(result.nums).map (x) -> x.index
   assert.done()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.