Commits

adamschmideg committed ab8f13d

Db.setValue and resolve works again! @0.6

  • Participants
  • Parent commits b3fe34d

Comments (0)

Files changed (2)

       result
 
   setValue: (up, value) ->
-    if value
-      @db().select(up.asString()).replace value
-      @
+    arr = up.asArray()
+    if arr.length is 1
+      result = new Db assoc(@data(), arr[0], value)
+    else if arr.length > 1
+      data = @data()[arr[0]]
+      child = new Db(data).setValue new UniquePath(arr[1..]), value
+      result = new Db assoc(@data(), arr[0], child.data())
     else
-      throw new Error "To be implemented, setting value #{value} for #{up.asString()}"
+      throw new Error "Cannot set '#{value}' at root"
+    result
     
 class DepGraph
   constructor: (map, parent=null) ->
     in: '/falsey'
     out: [0, null, '']
   ]
+
+@setValue = (assert) ->
+  fun = (pathStr, data) ->
+    db = new testing.Db data
+    db.setValue(new testing.UniquePath(pathStr), 'set').data()
+  testing.withData assert, fun, [
+    in: ['/foo'
+      foo: 1
+    ]
+    out: foo: 'set'
+  ,
+    in: ['/foo/bar'
+      foo: bar: 5
+    ]
+    out:
+      foo: bar: 'set'
+  ]