UNPKG

ucsc-xena-client

Version:

UCSC Xena Client. Functional genomics visualizations.

42 lines (34 loc) 1.41 kB
'use strict'; var LZ = require('./lz-string'); var _require = require('./compactData'), compactState = _require.compactState, expandState = _require.expandState; var migrateState = require('./migrateState'); var _require2 = require('./schemaCheck'), schemaCheckThrow = _require2.schemaCheckThrow; var version = 1; // XXX This encode version never worked, because it's encoded inside the blob. // Needs to be outside the blob. We would need to rewrite the db or API to // fix this. Maybe should be a POST param, instead of part of the json. // Serialization var stringify = function stringify(state) { return LZ.compressToUTF16(JSON.stringify({ version: version, appState: compactState(state) })); }; var parse = function parse(bookmark) { return schemaCheckThrow(expandState(migrateState(JSON.parse(LZ.decompressFromUTF16(bookmark)).appState))); }; module.exports = { version: version, hasBookmark: function hasBookmark() { return location.search.match(/^\?bookmark=/); }, getBookmark: function getBookmark() { return location.search.replace(/^\?bookmark=([0-9a-z]+)/, '$1'); }, resetBookmarkLocation: function resetBookmarkLocation() { return history.replaceState({}, 'UCSC Xena', location.pathname + location.search.replace(/\?bookmark=([0-9a-z]+)/, '')); }, createBookmark: stringify, // Need to add version check & merge of state + bookmark. parseBookmark: parse };