Skip to content

Commit

Permalink
should make changes accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
pemrouz committed Apr 27, 2016
1 parent 862ac94 commit 33a83e4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ var resource = function resource(ripple) {
// batch renders on render frames
var batch = function batch(ripple) {
return function (el) {
return !el.pending && (el.pending = requestAnimationFrame(function (d) {
return delete el.pending, ripple.render(el);
return el.pending ? el.pending.push(ripple.change) : (el.pending = [ripple.change], requestAnimationFrame(function (d) {
el.change = el.pending;
delete el.pending;
ripple.render(el);
}));
};
};
Expand Down
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ const resource = ripple => name => {
}

// batch renders on render frames
const batch = ripple => el => !el.pending
&& (el.pending = requestAnimationFrame(d => (delete el.pending, ripple.render(el))))
const batch = ripple => el => el.pending
? el.pending.push(ripple.change)
: (el.pending = [ripple.change]
, requestAnimationFrame(d => {
el.change = el.pending
delete el.pending
ripple.render(el)
}))

// main function to render a particular custom element with any data it needs
const invoke = ripple => el => {
Expand Down
23 changes: 23 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,27 @@ describe('Custom Elements', function(){
})
})

it('should make changes accessible', function(done){
var ripple = components(fn(data(core())))
, result

once(container)('component-28[data="foo"]', 1)
ripple('component-28', function(){ result = this.change })
ripple('foo', [{ bar: 5 }, { baz: 10 }])

time(50, function(){
result = null
update('bar', 15)(ripple('foo'))
update('baz', 25)(ripple('foo'))
})

time(100, function(){
expect(result).to.eql([
['foo', { type: 'update', key: 'bar', value: 15, time: 1}]
, ['foo', { type: 'update', key: 'baz', value: 25, time: 2}]
])
done()
})
})

})

0 comments on commit 33a83e4

Please sign in to comment.