Skip to content

Commit

Permalink
add max log header and default mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pemrouz committed Apr 10, 2016
1 parent bd455ed commit b63200d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ function data(ripple) {
parse: function parse(res) {
var existing = ripple.resources[res.name] || {};

res.body = (0, _set2.default)()(res.body || [], existing.body && existing.body.log);
(0, _extend2.default)(res.headers)(existing.headers);
res.body = (0, _set2.default)()(res.body || [], existing.body && existing.body.log, _is2.default.num(res.headers.log) ? res.headers.log : -1);
(0, _overwrite2.default)(res.body.on)(listeners(existing));
res.body.on('change.bubble', function (change) {
return ripple.emit('change', [res.name, change], (0, _not2.default)(_is2.default.in(['data'])));
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ export default function data(ripple){
, parse(res){
const existing = ripple.resources[res.name] || {}

res.body = set()(res.body || [], existing.body && existing.body.log)
extend(res.headers)(existing.headers)
res.body = set()(
res.body || []
, existing.body && existing.body.log
, is.num(res.headers.log) ? res.headers.log : -1
)
overwrite(res.body.on)(listeners(existing))
res.body.on('change.bubble', change => ripple.emit('change', [res.name, change], not(is.in(['data']))))

Expand Down
23 changes: 9 additions & 14 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,17 @@ describe('Data Type', function() {
ripple('foo', ['foo'])
update(0, 'bar')(ripple('foo'))

ripple('foo', set()(['baz']))
ripple('foo', ['baz'])
update(0, 'boo')(ripple('foo'))

expect(ripple('foo').log)
.to.eql(changes)
.to.eql([
{ time: 0, type: 'update', value: ['foo'] }
, { time: 1, type: 'update', value: 'bar', key: '0' }
, { time: 2, type: 'update', value: ['baz'] }
, { time: 3, type: 'update', value: 'boo', key: '0' }
])

ripple('bar', ripple('foo'))
expect(ripple('foo')).to.not.equal(ripple('bar'))
expect(ripple('foo').log).to.have.lengthOf(4)
expect(ripple('bar').log).to.have.lengthOf(5)
expect(changes).to.eql([
{ time: 0, type: 'update', value: ['foo'] }
, { time: 1, type: 'update', value: 'bar', key: '0' }
, { time: 2, type: 'update', value: ['baz'] }
, { time: 3, type: 'update', value: 'boo', key: '0' }
])

expect(ripple('foo').log).to.eql([null, null, null, null])
})

it('should not lose existing headers', function(){
Expand Down

0 comments on commit b63200d

Please sign in to comment.