The Purpose of $tw.mws.store.getBagRecentTiddlers(bag_name, greater_than_tiddler_id, limit)
is to be able to poll the MWS tiddler database for new and updated tiddlers.
These are the current tiddlers in 'bag-alpha':
$tw.mws.store.getBagTiddlers('bag-alpha')
[
{ title: '$:/SiteTitle', tiddler_id: 18943 },
{ title: 'In the bag', tiddler_id: 13264 },
{ title: 'ππππππ₯Ήπ
π', tiddler_id: 18944 }
]
The first request will return the most recently updated tiddlers up to the default limit of tiddlers. Take note of the bag_max_tiddler_id and greater_than_tiddler_id fields
The name of greater_than_tiddler_id should probably be last_known_tiddler_id ?
bag_max_tiddler_id is the highest (most recent) tiddler_id contained in the bag. greater_than_tiddler_id is the tiddler_id of the last known tiddler in the bag - by default it is tiddler_id number 1.
$tw.mws.store.getBagRecentTiddlers('bag-alpha')
{
bag_name: 'bag-alpha',
count: 3,
bag_max_tiddler_id: 18944,
greater_than_tiddler_id: 1,
tiddlers: [
{
title: 'ππππππ₯Ήπ
π',
is_deleted: 0,
tiddler_id: 18944,
fields: { title: 'ππππππ₯Ήπ
π', text: 'Bag Alpha' }
},
{
title: '$:/SiteTitle',
is_deleted: 0,
tiddler_id: 18943,
fields: { title: '$:/SiteTitle', text: 'Bag Alpha' }
},
{
title: 'In the bag',
is_deleted: 0,
tiddler_id: 13264,
fields: { title: 'In the bag', text: 'This tiddler is in bag-alpha' }
}
]
}
The next request uses the bag_max_tiddler_id 18944 of the previous response being the last known tiddler_id. The response to this request indicates that there are no changes - no new or updated tiddlers. The bag_max_tiddler_id has remained unchanged and the count is 0.
$tw.mws.store.getBagRecentTiddlers('bag-alpha',18944)
{
bag_name: 'bag-alpha',
count: 0,
bag_max_tiddler_id: 18944,
greater_than_tiddler_id: 18944,
tiddlers: []
}
Let's change a tiddler in the bag. (Assume that another user has done the change and we are currently unaware of it).
var changeTiddler = {
title: 'In the bag',
text: 'This tiddler is still in the bag-alpha'
}
$tw.mws.store.saveBagTiddler(changeTiddler,'bag-alpha')
Again, will use the bag_max_tiddler_id 18944 of the previous response as the greater_than_tiddler_id parameter in this request.
$tw.mws.store.getBagRecentTiddlers('bag-alpha',18944)
{
bag_name: 'bag-alpha',
count: 1,
bag_max_tiddler_id: 18947,
greater_than_tiddler_id: 18944,
tiddlers: [
{
title: 'In the bag',
is_deleted: 0,
tiddler_id: 18947,
fields: { title: 'In the bag', text: 'This tiddler is still in the bag-alpha' }
}
]
}
The In the bag tiddler was changed - a new tiddler_id was assigned. If the tiddler had been deleted then the is_deleted value would be 1. The next request would use the bag_max_tiddler_id value of 18947 as the greater_than_tiddler_id.
and so on and so forth...
Still some to do but wanted feedback if this is going in the right direction? If so will also do same for recipes.