- (void) initializeQuery {
// Set up my live query during view initialization:
CBLQuery* query = [[self.db viewNamed: @"widgets"] createQuery];
query.limit = 100;
self.liveQuery = query.asLiveQuery;
[self.liveQuery addObserver: self forKeyPath: @"rows"
options: 0 context: NULL];
[self.liveQuery start];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if (object == self.liveQuery) {
[self displayRows: self.liveQuery.rows]; // update the UI
}
}
CBLQueryEnumerator* result = [self.liveQuery run: &error];
for (CBLQueryRow* row in result) {
NSLog(@"found a row for mssession: %@, %@", row.key, row.value);
}
Since both row.key and row.value are up to date, I believe the query itself is valid. It's just that the observeValueForKeyPath was never called.
On Feb 25, 2015, at 8:38 AM, SeanDev <xyvict...@gmail.com> wrote:
- I get the query from CBLModel subclass.
- (void) dealloc {
NSLog(@"Dealloc of MSSession object");
}
+ (CBLQuery*) queryProfilesInDatabase: (CBLDatabase*)db {
CBLView* view = [db viewNamed: @"profiles"];
if (!view.mapBlock) {
// Register the map function, the first time we access the view:
[view setMapBlock: MAPBLOCK({
if ([doc[@"type"] isEqualToString:kType])
emit(doc[@"_id"], doc[@"queue"]);
}) reduceBlock: nil version: @"1"]; // bump version any time you change the MAPBLOCK body!
}
return [view createQuery];
}
Actually no instance of the CBLModel is created.
Since I'm using emit(doc[@"_id"], doc[@"queue"]); Is it possible that index is not refreshed when I modify ony the doc[@"queue"]?
Could you please post a link to an entire source file that demonstrates the problem?
{
"log": ["CRUD", "REST+","HTTP+"],
"databases": {
"demoqueue": {
"server": "walrus:",
"bucket": "demoqueue",
"users": {
"GUEST": {"disabled": false, "admin_channels": ["*"] }
}
}
}
}
[self.queueLiveQuery addObserver: self forKeyPath: @"demoqueue"options: 0 context: NULL];