/
TemporaryAssembliesMixin.ts
51 lines (47 loc) · 1.35 KB
/
TemporaryAssembliesMixin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { types } from 'mobx-state-tree'
import PluginManager from '@jbrowse/core/PluginManager'
import { AnyConfiguration } from '@jbrowse/core/configuration'
import { BaseSession } from '@jbrowse/product-core'
/**
* #stateModel TemporaryAssembliesMixin
* #category root
*/
export function TemporaryAssembliesMixin(
pluginManager: PluginManager,
assemblyConfigSchemasType = types.frozen(),
) {
return types
.model({
/**
* #property
*/
temporaryAssemblies: types.array(assemblyConfigSchemasType),
})
.actions(s => {
const self = s as typeof s & BaseSession
return {
/**
* #action
* used for read vs ref type assemblies.
*/
addTemporaryAssembly(conf: AnyConfiguration) {
const asm = self.temporaryAssemblies.find(f => f.name === conf.name)
if (asm) {
console.warn(`Assembly ${conf.name} was already existing`)
return asm
}
const length = self.temporaryAssemblies.push(conf)
return self.temporaryAssemblies[length - 1]
},
/**
* #action
*/
removeTemporaryAssembly(name: string) {
const elt = self.temporaryAssemblies.find(a => a.name === name)
if (elt) {
self.temporaryAssemblies.remove(elt)
}
},
}
})
}