Skip to content

Commit

Permalink
always create new diff object
Browse files Browse the repository at this point in the history
  • Loading branch information
pemrouz committed Apr 10, 2016
1 parent e679661 commit 0f683a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
15 changes: 11 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ var _values = require('utilise/values');

var _values2 = _interopRequireDefault(_values);

var _last = require('utilise/last');
var _key = require('utilise/key');

var _last2 = _interopRequireDefault(_last);
var _key2 = _interopRequireDefault(_key);

var _is = require('utilise/is');

Expand Down Expand Up @@ -92,7 +92,11 @@ var register = function register(ripple) {

if (!res) return err('failed to register', name), false;
ripple.resources[name] = res;
ripple.emit('change', [name, res.body.log ? (0, _last2.default)(res.body.log) : { type: 'update', value: res.body }]);
ripple.emit('change', [name, {
type: 'update',
value: res.body,
time: now(res)
}]);
return ripple.resources[name].body;
};
};
Expand Down Expand Up @@ -124,4 +128,7 @@ var types = function types() {
};

var err = require('utilise/err')('[ri/core]'),
log = require('utilise/log')('[ri/core]');
log = require('utilise/log')('[ri/core]'),
now = function now(d, t) {
return t = (0, _key2.default)('body.log.length')(d), _is2.default.num(t) ? t - 1 : t;
};
14 changes: 8 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ const register = ripple => ({name, body, headers = {}}) => {

if (!res) return err('failed to register', name), false
ripple.resources[name] = res
ripple.emit('change', [name, res.body.log
? last(res.body.log)
: { type: 'update', value: res.body }
])
ripple.emit('change', [name, {
type: 'update'
, value: res.body
, time: now(res)
}])
return ripple.resources[name].body
}

Expand All @@ -69,10 +70,11 @@ import chainable from 'utilise/chainable'
import identity from 'utilise/identity'
import header from 'utilise/header'
import values from 'utilise/values'
import last from 'utilise/last'
import key from 'utilise/key'
import is from 'utilise/is'
import to from 'utilise/to'
import za from 'utilise/za'
import text from './types/text'
const err = require('utilise/err')('[ri/core]')
, log = require('utilise/log')('[ri/core]')
, log = require('utilise/log')('[ri/core]')
, now = (d, t) => (t = key('body.log.length')(d), is.num(t) ? t - 1 : t)
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,21 @@ describe('Core', function() {

ripple.on('change', fn)
ripple('foo', 'bar')
expect(params).to.eql(['foo', { type: 'update', value: 'bar' }])
expect(params).to.eql(['foo', { type: 'update', value: 'bar', time: undefined }])

ripple.types['data'] = { header: 'data', check: String }
ripple('boo', { log: ['baz'] })
expect(params).to.eql(['boo', 'baz'])
expect(params).to.eql(['boo', { type: 'update', value: { log: ['baz'] }, time: 0 }])
})

it('should indicate if new resource', function(done){
var ripple = core()
ripple.once('change', function(d, change){
expect(d).to.eql('foo')
expect(change).to.eql({ type: 'update', value: 'foo' })
expect(change).to.eql({ type: 'update', value: 'foo', time: undefined })
ripple.once('change', function(d, change){
expect(d).to.eql('foo')
expect(change).to.eql({ type: 'update', value: 'bar' })
expect(change).to.eql({ type: 'update', value: 'bar', time: undefined })
done()
})
ripple('foo', 'bar')
Expand Down

0 comments on commit 0f683a5

Please sign in to comment.