go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/common/store/invocation_page.ts (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import { reaction } from 'mobx'; 16 import { 17 addDisposer, 18 Instance, 19 SnapshotIn, 20 SnapshotOut, 21 types, 22 } from 'mobx-state-tree'; 23 24 import { InvocationState } from './invocation_state'; 25 import { ServicesStore } from './services'; 26 27 export const InvocationPage = types 28 .model('InvocationPage', { 29 services: types.safeReference(ServicesStore), 30 31 invocationId: types.maybe(types.string), 32 33 invocation: types.optional(InvocationState, {}), 34 }) 35 .actions((self) => ({ 36 setDependencies(deps: Partial<Pick<typeof self, 'services'>>) { 37 Object.assign<typeof self, Partial<typeof self>>(self, deps); 38 }, 39 setInvocationId(invId: string) { 40 self.invocationId = invId; 41 }, 42 afterCreate() { 43 addDisposer( 44 self, 45 reaction( 46 () => self.services, 47 (services) => { 48 self.invocation.setDependencies({ 49 services, 50 }); 51 }, 52 { fireImmediately: true }, 53 ), 54 ); 55 56 self.invocation.setDependencies({ 57 invocationIdGetter: () => self.invocationId || null, 58 }); 59 }, 60 })); 61 62 export type InvocationPageInstance = Instance<typeof InvocationPage>; 63 export type InvocationPageSnapshotIn = SnapshotIn<typeof InvocationPage>; 64 export type InvocationPageSnapshotOut = SnapshotOut<typeof InvocationPage>;