update
This commit is contained in:
@@ -1,33 +1,26 @@
|
||||
import { inject, type InjectionKey, ref } from "vue";
|
||||
import { inject, type InjectionKey, ref, provide, getCurrentInstance } from "vue";
|
||||
import { Bound } from "./utils";
|
||||
|
||||
export type UITool =
|
||||
| "track-unit-type"
|
||||
| "eraser"
|
||||
| "sticking";
|
||||
|
||||
export function createAppStateStore() {
|
||||
const selectedTool = ref<UITool>("track-unit-type");
|
||||
const activeTrackUnitType = ref(0);
|
||||
const activeStickingType = ref(1);
|
||||
const unitMouseStart = ref<string | null>(null);
|
||||
const selectingUnits = ref(false);
|
||||
const deselectingUnits = ref(false);
|
||||
|
||||
return {
|
||||
selectingUnits,
|
||||
deselectingUnits,
|
||||
selectedTool,
|
||||
activeTrackUnitType,
|
||||
activeStickingType,
|
||||
unitMouseStart,
|
||||
};
|
||||
export class AppStateStore extends Bound {
|
||||
selectedTool = ref<UITool>("track-unit-type");
|
||||
activeTrackUnitType = ref(0);
|
||||
activeStickingType = ref(1);
|
||||
unitMouseStart = ref<string | null>(null);
|
||||
selectingUnits = ref(false);
|
||||
deselectingUnits = ref(false);
|
||||
}
|
||||
|
||||
|
||||
export type AppStateStore = ReturnType<typeof createAppStateStore>;
|
||||
|
||||
export const AppStateStoreKey = Symbol("AppStateStore") as InjectionKey<AppStateStore>;
|
||||
const AppStateStoreKey = Symbol("AppStateStore") as InjectionKey<AppStateStore>;
|
||||
|
||||
export function useAppStateStore(): AppStateStore {
|
||||
return inject(AppStateStoreKey, createAppStateStore, true);
|
||||
return inject(AppStateStoreKey, () => {
|
||||
const store = new AppStateStore();
|
||||
getCurrentInstance()?.appContext?.app.provide(AppStateStoreKey, store);
|
||||
return store;
|
||||
}, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user