Skip to content

Commit 0f683a5

Browse files
author
pemrouz
committed
always create new diff object
1 parent e679661 commit 0f683a5

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

dist/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ var _values = require('utilise/values');
2929

3030
var _values2 = _interopRequireDefault(_values);
3131

32-
var _last = require('utilise/last');
32+
var _key = require('utilise/key');
3333

34-
var _last2 = _interopRequireDefault(_last);
34+
var _key2 = _interopRequireDefault(_key);
3535

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

@@ -92,7 +92,11 @@ var register = function register(ripple) {
9292

9393
if (!res) return err('failed to register', name), false;
9494
ripple.resources[name] = res;
95-
ripple.emit('change', [name, res.body.log ? (0, _last2.default)(res.body.log) : { type: 'update', value: res.body }]);
95+
ripple.emit('change', [name, {
96+
type: 'update',
97+
value: res.body,
98+
time: now(res)
99+
}]);
96100
return ripple.resources[name].body;
97101
};
98102
};
@@ -124,4 +128,7 @@ var types = function types() {
124128
};
125129

126130
var err = require('utilise/err')('[ri/core]'),
127-
log = require('utilise/log')('[ri/core]');
131+
log = require('utilise/log')('[ri/core]'),
132+
now = function now(d, t) {
133+
return t = (0, _key2.default)('body.log.length')(d), _is2.default.num(t) ? t - 1 : t;
134+
};

src/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ const register = ripple => ({name, body, headers = {}}) => {
4040

4141
if (!res) return err('failed to register', name), false
4242
ripple.resources[name] = res
43-
ripple.emit('change', [name, res.body.log
44-
? last(res.body.log)
45-
: { type: 'update', value: res.body }
46-
])
43+
ripple.emit('change', [name, {
44+
type: 'update'
45+
, value: res.body
46+
, time: now(res)
47+
}])
4748
return ripple.resources[name].body
4849
}
4950

@@ -69,10 +70,11 @@ import chainable from 'utilise/chainable'
6970
import identity from 'utilise/identity'
7071
import header from 'utilise/header'
7172
import values from 'utilise/values'
72-
import last from 'utilise/last'
73+
import key from 'utilise/key'
7374
import is from 'utilise/is'
7475
import to from 'utilise/to'
7576
import za from 'utilise/za'
7677
import text from './types/text'
7778
const err = require('utilise/err')('[ri/core]')
78-
, log = require('utilise/log')('[ri/core]')
79+
, log = require('utilise/log')('[ri/core]')
80+
, now = (d, t) => (t = key('body.log.length')(d), is.num(t) ? t - 1 : t)

test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,21 @@ describe('Core', function() {
137137

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

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

147147
it('should indicate if new resource', function(done){
148148
var ripple = core()
149149
ripple.once('change', function(d, change){
150150
expect(d).to.eql('foo')
151-
expect(change).to.eql({ type: 'update', value: 'foo' })
151+
expect(change).to.eql({ type: 'update', value: 'foo', time: undefined })
152152
ripple.once('change', function(d, change){
153153
expect(d).to.eql('foo')
154-
expect(change).to.eql({ type: 'update', value: 'bar' })
154+
expect(change).to.eql({ type: 'update', value: 'bar', time: undefined })
155155
done()
156156
})
157157
ripple('foo', 'bar')

0 commit comments

Comments
 (0)