Anton Shestakov <av6@dwimlabs.net>, Thu, 05 Jul 2018 22:55:53 +0800
demo: jQuery 3.3.1
test/changing-models.js
Permissions: -rw-r--r--
var a, b, c, d, col, additions, removals, changes, likechanges, readShard, unreadShard; module('Backbone.Shard', { a = new Backbone.Model({data: 'a', read: true, like: false}); b = new Backbone.Model({data: 'b', read: true, like: false}); c = new Backbone.Model({data: 'c', read: false, like: false}); d = new Backbone.Model({data: 'd', read: false, like: false}); col = new Backbone.Collection([a, b, c, d]); readShard = new Backbone.Shard({ filter: function(model) { return model.get('read'); } unreadShard = new Backbone.Shard({ filter: function(model) { return !model.get('read'); } additions = {read: 0, unread: 0}; removals = {read: 0, unread: 0}; changes = {read: 0, unread: 0}; likechanges = {read: 0, unread: 0}; readShard.on('add', function() { }).on('remove', function() { }).on('change', function() { }).on('change:like', function() { unreadShard.on('add', function() { }).on('remove', function() { }).on('change', function() { }).on('change:like', function() { test('Updating model attributes not used in shard filter', function() { equal(likechanges.read, 1, 'change:like triggered in readShard'); equal(likechanges.unread, 0, 'change:like not triggered in unreadShard'); test('Updating model attributes used in shard filter', function() { deepEqual(readShard.size(), 1, 'removes from readShard'); equal(removals.read, 1, '... and triggers remove event'); equal(unreadShard.size(), 3, 'adds to unreadShard'); equal(additions.unread, 1, '... and triggers add event');