-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmst-types.ts
56 lines (46 loc) · 1.53 KB
/
mst-types.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
52
53
54
55
56
import shortid from 'shortid'
import { types, SnapshotOut } from 'mobx-state-tree'
import propTypes from 'prop-types'
import { PropTypes as MxPropTypes } from 'mobx-react'
export const ElementId = types.optional(types.identifier, shortid.generate)
// PropTypes that are useful when working with instances of these in react components
export const PropTypes = {
Region: propTypes.shape({
refName: propTypes.string.isRequired,
start: propTypes.number.isRequired,
end: propTypes.number.isRequired,
}),
ConfigSchema: MxPropTypes.objectOrObservableObject,
Feature: propTypes.shape({
get: propTypes.func.isRequired,
id: propTypes.func.isRequired,
}),
}
export const NoAssemblyRegion = types
.model('Region', {
refName: types.string,
start: types.number,
end: types.number,
})
.actions(self => ({
setRefName(newRefName: string) {
self.refName = newRefName
},
}))
type TNoAssemblyRegion = SnapshotOut<typeof NoAssemblyRegion>
export type INoAssemblyRegion = TNoAssemblyRegion
export const Region = types.compose(
NoAssemblyRegion,
types.model({
assemblyName: types.string,
}),
)
export type IRegion = SnapshotOut<typeof Region>
export const LocalPathLocation = types.model('LocalPathLocation', {
localPath: types.string, // TODO: refine
})
export const UriLocation = types.model('UriLocation', {
uri: types.string, // TODO: refine
})
export const FileLocation = types.union(LocalPathLocation, UriLocation)
export type IFileLocation = SnapshotOut<typeof FileLocation> | { blob: Blob }