UNPKG

ucsc-xena-client

Version:

UCSC Xena Client. Functional genomics visualizations.

75 lines (62 loc) 2.68 kB
'use strict'; // Desired behavior: // When we change the state structure, add a migration. // Sources of state: // sessionStorage // bookmarks // initial state // // function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } var version = 1; var _require = require('./underscore_ext'), assoc = _require.assoc, get = _require.get, getIn = _require.getIn, Let = _require.Let, pick = _require.pick, isString = _require.isString, flatten = _require.flatten, updateIn = _require.updateIn, without = _require.without; var setVersion = function setVersion(state) { return assoc(state, 'version', version); }; var getVersion = function getVersion(state) { return Let(function () { var s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : get(state, 'version', 0); return isString(s) ? 0 : s; }); }; var noComposite = function noComposite(state) { return assoc(state, 'cohort', state.cohort[0], 'cohortSamples', state.cohortSamples[0]); }; var spreadsheetProps = ['columnOrder', 'columns', 'mode', 'notifications', 'servers', 'showWelcome', 'wizardMode', 'zoom', 'defaultWidth', 'data', 'cohort', 'cohortSamples', 'km', 'survival', 'sampleSearch', 'samplesOver', 'editing', 'openVizSettings', 'chartState', 'hasPrivateSamples']; //var dropProps = ['cohortMeta', 'cohortPreferred', 'cohortPhenotype', 'cohorts', 'datasets', 'features', 'samples', 'columnEdit']; var splitPages = function splitPages(state) { // console.log('Unhandled state', pick(state, (v, k) => !contains(spreadsheetProps, k) && !contains(dropProps, k))); return { spreadsheet: pick(state, spreadsheetProps), page: 'heatmap' }; }; // This will break bookmarks with sample search and samples to the right var samplesToLeft = function samplesToLeft(state) { return ( // We don't want to create a blank spreadsheet object if there is none, so check // if there's a columnOrder before doing anything. indexOf could be -1 or 0 getIn(state, ['spreadsheet', 'columnOrder'], []).indexOf('samples') > 0 ? updateIn(state, ['spreadsheet', 'columnOrder'], function (order) { return ['samples'].concat(_toConsumableArray(without(order, 'samples'))); }) : state ); }; // This must be sorted, with later versions appearing last. var migrations = [[noComposite, splitPages, samplesToLeft]]; function apply(state) { var v = getVersion(state), toDo = flatten(migrations.slice(v)); return setVersion(toDo.reduce(function (prev, fn) { return fn(prev); }, state)); } module.exports = apply;