|
1 | | -import { filterSessionInPlace } from '@jbrowse/app-core' |
2 | | -import TextSearchManager from '@jbrowse/core/TextSearch/TextSearchManager' |
3 | | -import assemblyManagerFactory from '@jbrowse/core/assemblyManager' |
4 | | -import RpcManager from '@jbrowse/core/rpc/RpcManager' |
5 | | -import { |
6 | | - cast, |
7 | | - getSnapshot, |
8 | | - getType, |
9 | | - isStateTreeNode, |
10 | | - types, |
11 | | -} from '@jbrowse/mobx-state-tree' |
12 | | - |
13 | | -import type PluginManager from '@jbrowse/core/PluginManager' |
14 | | -import type { BaseAssemblyConfigSchema } from '@jbrowse/core/assemblyManager' |
15 | | -import type { IAnyType, Instance } from '@jbrowse/mobx-state-tree' |
| 1 | +import type TextSearchManager from '@jbrowse/core/TextSearch/TextSearchManager' |
| 2 | +import type { AssemblyManager } from '@jbrowse/core/assemblyManager' |
| 3 | +import type RpcManager from '@jbrowse/core/rpc/RpcManager' |
16 | 4 |
|
17 | 5 | /** |
18 | | - * #stateModel BaseRootModel |
19 | | - * #category root |
20 | | - * factory function for the Base-level root model shared by all products |
| 6 | + * Base interface for root model properties that sessions expect to exist |
21 | 7 | */ |
22 | | -export function BaseRootModelFactory({ |
23 | | - pluginManager, |
24 | | - jbrowseModelType, |
25 | | - sessionModelType, |
26 | | - assemblyConfigSchema, |
27 | | -}: { |
28 | | - pluginManager: PluginManager |
29 | | - jbrowseModelType: IAnyType |
30 | | - sessionModelType: IAnyType |
31 | | - assemblyConfigSchema: BaseAssemblyConfigSchema |
32 | | -}) { |
33 | | - return types |
34 | | - .model('BaseRootModel', { |
35 | | - /** |
36 | | - * #property |
37 | | - * `jbrowse` is a mapping of the config.json into the in-memory state |
38 | | - * tree |
39 | | - */ |
40 | | - jbrowse: jbrowseModelType, |
41 | | - |
42 | | - /** |
43 | | - * #property |
44 | | - * `session` encompasses the currently active state of the app, including |
45 | | - * views open, tracks open in those views, etc. |
46 | | - */ |
47 | | - session: types.maybe(sessionModelType), |
48 | | - /** |
49 | | - * #property |
50 | | - */ |
51 | | - sessionPath: types.optional(types.string, ''), |
52 | | - |
53 | | - /** |
54 | | - * #property |
55 | | - */ |
56 | | - assemblyManager: types.optional( |
57 | | - assemblyManagerFactory(assemblyConfigSchema, pluginManager), |
58 | | - {}, |
59 | | - ), |
60 | | - }) |
61 | | - .volatile(self => ({ |
62 | | - /** |
63 | | - * #volatile |
64 | | - */ |
65 | | - rpcManager: new RpcManager( |
66 | | - pluginManager, |
67 | | - self.jbrowse.configuration.rpc, |
68 | | - { |
69 | | - MainThreadRpcDriver: {}, |
70 | | - }, |
71 | | - ), |
72 | | - |
73 | | - /** |
74 | | - * #volatile |
75 | | - */ |
76 | | - adminMode: false, |
77 | | - /** |
78 | | - * #volatile |
79 | | - */ |
80 | | - error: undefined as unknown, |
81 | | - /** |
82 | | - * #volatile |
83 | | - */ |
84 | | - textSearchManager: new TextSearchManager(pluginManager), |
85 | | - /** |
86 | | - * #volatile |
87 | | - */ |
88 | | - pluginManager, |
89 | | - })) |
90 | | - .actions(self => ({ |
91 | | - /** |
92 | | - * #action |
93 | | - */ |
94 | | - setError(error: unknown) { |
95 | | - self.error = error |
96 | | - }, |
97 | | - /** |
98 | | - * #action |
99 | | - */ |
100 | | - setSession(sessionSnapshot?: Record<string, unknown>) { |
101 | | - const oldSession = self.session |
102 | | - self.session = cast(sessionSnapshot) |
103 | | - if (self.session) { |
104 | | - // validate all references in the session snapshot |
105 | | - try { |
106 | | - filterSessionInPlace(self.session, getType(self.session)) |
107 | | - } catch (error) { |
108 | | - // throws error if session filtering failed |
109 | | - self.session = oldSession |
110 | | - throw error |
111 | | - } |
112 | | - } |
113 | | - }, |
114 | | - /** |
115 | | - * #action |
116 | | - */ |
117 | | - setDefaultSession() { |
118 | | - this.setSession(self.jbrowse.defaultSession) |
119 | | - }, |
120 | | - /** |
121 | | - * #action |
122 | | - */ |
123 | | - setSessionPath(path: string) { |
124 | | - self.sessionPath = path |
125 | | - }, |
126 | | - /** |
127 | | - * #action |
128 | | - */ |
129 | | - renameCurrentSession(newName: string) { |
130 | | - if (self.session) { |
131 | | - this.setSession({ |
132 | | - ...getSnapshot(self.session), |
133 | | - name: newName, |
134 | | - }) |
135 | | - } |
136 | | - }, |
137 | | - })) |
138 | | -} |
139 | | - |
140 | | -export type BaseRootModelType = ReturnType<typeof BaseRootModelFactory> |
141 | | -export type BaseRootModel = Instance<BaseRootModelType> |
142 | | - |
143 | | -/** Type guard for checking if something is a JB root model */ |
144 | | -export function isRootModel(thing: unknown): thing is BaseRootModelType { |
145 | | - return ( |
146 | | - isStateTreeNode(thing) && |
147 | | - 'session' in thing && |
148 | | - 'jbrowse' in thing && |
149 | | - 'assemblyManager' in thing |
150 | | - ) |
| 8 | +export interface BaseRootModelType { |
| 9 | + jbrowse: { |
| 10 | + assemblies: unknown[] |
| 11 | + configuration: unknown |
| 12 | + } |
| 13 | + session: unknown |
| 14 | + assemblyManager: AssemblyManager |
| 15 | + rpcManager: RpcManager |
| 16 | + adminMode: boolean |
| 17 | + textSearchManager: TextSearchManager |
151 | 18 | } |
0 commit comments