[Search] Index directly on mutation

Pass model directly when indexing is triggered via object mutation,
to avoid issuing an extra, unnecessary request to the server.

Additionally supports indexing of objects which have been created
but not yet persisted.

Addresses #377.
This commit is contained in:
Victor Woeltjen 2016-03-07 14:42:40 -08:00
parent ff5f37dfbe
commit 2d305415b3
2 changed files with 9 additions and 6 deletions

View File

@ -121,9 +121,9 @@ define([
provider = this;
mutationTopic.listen(function (mutatedObject) {
var id = mutatedObject.getId();
provider.indexedIds[id] = false;
provider.scheduleForIndexing(id);
var id = mutatedObject.getId(),
model = mutatedObject.getModel();
provider.index(id, model);
});
};

View File

@ -99,12 +99,15 @@ define([
.toHaveBeenCalledWith(jasmine.any(Function));
});
it('reschedules indexing when mutation occurs', function () {
it('re-indexes when mutation occurs', function () {
var mockDomainObject =
jasmine.createSpyObj('domainObj', ['getId']);
jasmine.createSpyObj('domainObj', ['getId', 'getModel']),
testModel = { some: 'model' };
mockDomainObject.getId.andReturn("some-id");
mockDomainObject.getModel.andReturn(testModel);
spyOn(provider, 'index').andCallThrough();
mutationTopic.listen.mostRecentCall.args[0](mockDomainObject);
expect(provider.scheduleForIndexing).toHaveBeenCalledWith('some-id');
expect(provider.index).toHaveBeenCalledWith('some-id', testModel);
});
it('starts indexing roots', function () {