CBLLiveQuery and CBLUITableSource

150 views
Skip to first unread message

Scott Ahten

unread,
May 17, 2013, 2:35:02 PM5/17/13
to mobile-c...@googlegroups.com
I have a question about using CBLUITableSource with a CBLLiveQuery to drive a UITableView. 

I'm using a custom UITableViewCell that displays a different image depending if the related document for that row has a completedOn date, which indicates a task in the list is completed, The table view is populated correctly when the view controller is displayed and new rows appear when documents are added that match the query.
 
However, when I change the completedOn property in another view controller, the table view doesn't always reflect this change. Changing the value, then adding or deleting an item cause the row to be updated, but changing it, then saving it in another view controller rarely causes the table view to be updated. 

Does CBLUITableSource with a CBLLiveQuery just track the addition or removal of items that match the query in the DB or does it also track change to the documents properties?

Or perhaps it only tracks the change of properties that are part of the underling view?

Thanks, 

- Scott

Scott Ahten

unread,
May 17, 2013, 2:47:30 PM5/17/13
to mobile-c...@googlegroups.com
Looks like by guess was correct. Implementing this was a bit tricky because the completedOn properly is absent from the document if the item is not complete and emitting a nil value as part of the value throws an exception when the view is updated. I ended up emitting NSNull in this case. 

[view setMapBlock: MAPBLOCK({
            
            if ([doc[@"type"] isEqualToString:@"my-doctype"]) {
                
                id displayName = doc[@"displayName"];
                
                id completedOn = doc[@"completedOn"];
                if (!completedOn)
                    completedOn = [NSNull null];
                
                emit(@[doc[@"type"],doc[@"createdAt"]],@[displayName, doc[@"type"], completedOn]);
            }

        }) version: @"2"];

Jens Alfke

unread,
May 17, 2013, 4:15:20 PM5/17/13
to mobile-c...@googlegroups.com

On May 17, 2013, at 11:35 AM, Scott Ahten <lightand...@gmail.com> wrote:

Or perhaps it only tracks the change of properties that are part of the underling view?

Yes: it’s watching for the view’s result rows to change. It won’t notice if a document changes in a way that doesn’t affect the view.

emitting a nil value as part of the value throws an exception when the view is updated. I ended up emitting NSNull in this case.

That’s right. Cocoa collections don’t allow nil values, so an NSNull object is used to represent a JSON “null” value.

—Jens
Reply all
Reply to author
Forward
0 new messages