Skip to content

Commit

Permalink
Merge pull request #35 from lipp/feature-alias-value_as_result
Browse files Browse the repository at this point in the history
alias value_as_result to valueAsResult
  • Loading branch information
lipp committed Nov 30, 2014
2 parents db58d29 + d332f64 commit 20a4b94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/peer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,32 @@ create_peer_tests = function(config)
})
end)

it('peer can set value and value_as_result aliases valueAsResult',function(done)
peer:state({
path = 'adjusting_state',
value = {
x = 3
},
set = function(newval)
local t = {}
t.x = math.floor(newval.x)
-- return the "real" adjusted value
return t
end
})
local new_val = 716.44
peer:set('adjusting_state',{x=new_val},{
value_as_result = true,
success = async(function(result)
assert.is_same(result,{x=math.floor(new_val)})
done()
end),
error = async(function(err)
assert.is_falsy(err)
end)
})
end)

it('peer can set value and adjustments are not visible in result if valueAsResult is undefined',function(done)
peer:state({
path = 'adjusting_state2',
Expand Down
4 changes: 4 additions & 0 deletions src/jet/peer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ local new = function(config)
path = path,
value = value
}
if callbacks and not callbacks.valueAsResult then
callbacks.valueAsResult = callbacks.value_as_result
callbacks.value_as_result = nil
end
service('set',params,nil,callbacks)
end

Expand Down

0 comments on commit 20a4b94

Please sign in to comment.