Commit 214e40fc authored by Robert Knight's avatar Robert Knight

Match drafts by local tag as well as ID

In preparation for making Annotation objects immutable, enable the
drafts service to match local annotations which do not have an ID by
their local tag.
parent 979b83c4
......@@ -23,11 +23,10 @@ function DraftStore() {
* Returns true if 'draft' is a draft for a given
* annotation.
*
* Annotations are matched by ID and annotation instance (for unsaved
* annotations which have no ID)
* Annotations are matched by ID or local tag.
*/
function match(draft, model) {
return draft.model === model ||
return (draft.model.$$tag && model.$$tag === draft.model.$$tag) ||
(draft.model.id && model.id === draft.model.id);
}
......
'use strict';
var draftsService = require('../drafts');
describe('drafts', function () {
......@@ -7,7 +9,7 @@ describe('drafts', function () {
drafts = draftsService();
});
describe('.update', function () {
describe('#update', function () {
it('should save changes', function () {
var model = {id: 'foo'};
assert.notOk(drafts.get(model));
......@@ -31,9 +33,17 @@ describe('drafts', function () {
drafts.update(modelB, {isPrivate:true, tags:['foo'], text:'bar'});
assert.equal(drafts.get(modelA).text, 'bar');
});
it('should replace drafts with the same tag', function () {
var modelA = {$$tag: 'foo'};
var modelB = {$$tag: 'foo'};
drafts.update(modelA, {isPrivate:true, tags:['foo'], text:'foo'});
drafts.update(modelB, {isPrivate:true, tags:['foo'], text:'bar'});
assert.equal(drafts.get(modelA).text, 'bar');
});
});
describe('.remove', function () {
describe('#remove', function () {
it('should remove drafts', function () {
var model = {id: 'foo'};
drafts.update(model, {text: 'bar'});
......@@ -42,7 +52,7 @@ describe('drafts', function () {
});
});
describe('.unsaved', function () {
describe('#unsaved', function () {
it('should return drafts for unsaved annotations', function () {
var model = {};
drafts.update(model, {text: 'bar'});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment