jinaga
Version:
Data management for web and mobile applications.
46 lines • 1.87 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BookmarkManager = void 0;
class BookmarkManager {
constructor() {
this.bookmarks = new Map();
this.counter = 0;
}
getBookmark(feed) {
var _a;
return (_a = this.bookmarks.get(feed)) !== null && _a !== void 0 ? _a : "";
}
setBookmark(feed, bookmark) {
this.bookmarks.set(feed, bookmark);
}
advanceBookmark(feed) {
return __awaiter(this, void 0, void 0, function* () {
const next = `${Date.now()}:${this.counter++}`;
this.bookmarks.set(feed, next);
return next;
});
}
/**
* If a bookmark is already known for the feed and differs from the provided value,
* return the known bookmark so callers can synchronize the client.
* Returns null if no sync is necessary.
*/
syncBookmarkIfMismatch(feed, provided) {
const current = this.bookmarks.get(feed);
if (current && current !== provided) {
return current;
}
return null;
}
}
exports.BookmarkManager = BookmarkManager;
//# sourceMappingURL=bookmark-manager.js.map