Skip to content

Commit

Permalink
Use snapshot preprocessor to filter out non-array old connectionInsta…
Browse files Browse the repository at this point in the history
…nces (#1910)

* Snapshot preprocessor to try to avoid connectionInstances

* Add is-object dependency and add to jbrowse-desktop also
  • Loading branch information
cmdcolin authored Apr 15, 2021
1 parent 475ac14 commit 67ca1c3
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 156 deletions.
1 change: 1 addition & 0 deletions products/jbrowse-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"electron-debug": "^3.0.1",
"electron-is-dev": "^1.1.0",
"fontsource-roboto": "3.0.3",
"is-object": "^1.0.2",
"json-stable-stringify": "^1.0.1",
"mobx": "^5.10.1",
"mobx-react": "^6.0.0",
Expand Down
20 changes: 19 additions & 1 deletion products/jbrowse-desktop/src/sessionModelFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { AnyConfigurationModel } from '@jbrowse/core/configuration/configurationSchema'
import isObject from 'is-object'
import {
readConfObject,
isConfigurationModel,
Expand Down Expand Up @@ -41,7 +42,7 @@ export default function sessionModelFactory(
assemblyConfigSchemasType = types.frozen(), // if not using sessionAssemblies
) {
const minDrawerWidth = 128
return types
const sessionModel = types
.model('JBrowseDesktopSessionModel', {
name: types.identifier,
margin: 0,
Expand Down Expand Up @@ -552,6 +553,23 @@ export default function sessionModelFactory(
]
},
}))

return types.snapshotProcessor(sessionModel, {
// @ts-ignore
preProcessor(snapshot) {
if (snapshot) {
// @ts-ignore
const { connectionInstances, ...rest } = snapshot || {}
// connectionInstances schema changed from object to an array, so any
// old connectionInstances as object is in snapshot, filter it out
// https://github.com/GMOD/jbrowse-components/issues/1903
if (isObject(connectionInstances)) {
return rest
}
}
return snapshot
},
})
}

export type SessionStateModel = ReturnType<typeof sessionModelFactory>
Expand Down
1 change: 1 addition & 0 deletions products/jbrowse-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"crypto-js": "^3.0.0",
"fastestsmallesttextencoderdecoder": "^1.0.14",
"fontsource-roboto": "3.0.3",
"is-object": "^1.0.2",
"json-stable-stringify": "^1.0.1",
"merge-deep": "^3.0.2",
"mobx": "^5.10.1",
Expand Down
20 changes: 19 additions & 1 deletion products/jbrowse-web/src/sessionModelFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { AnyConfigurationModel } from '@jbrowse/core/configuration/configurationSchema'
import isObject from 'is-object'
import {
readConfObject,
getConf,
Expand Down Expand Up @@ -46,7 +47,7 @@ export default function sessionModelFactory(
assemblyConfigSchemasType = types.frozen(), // if not using sessionAssemblies
) {
const minDrawerWidth = 128
return types
const sessionModel = types
.model('JBrowseWebSessionModel', {
id: types.optional(types.identifier, shortid()),
name: types.string,
Expand Down Expand Up @@ -650,6 +651,23 @@ export default function sessionModelFactory(
]
},
}))

return types.snapshotProcessor(sessionModel, {
// @ts-ignore
preProcessor(snapshot) {
if (snapshot) {
// @ts-ignore
const { connectionInstances, ...rest } = snapshot || {}
// connectionInstances schema changed from object to an array, so any
// old connectionInstances as object is in snapshot, filter it out
// https://github.com/GMOD/jbrowse-components/issues/1903
if (isObject(connectionInstances)) {
return rest
}
}
return snapshot
},
})
}

export type SessionStateModel = ReturnType<typeof sessionModelFactory>
Expand Down
Loading

0 comments on commit 67ca1c3

Please sign in to comment.