ui_migration refactor(store) update store files droppping mutations
This commit is contained in:
parent
1db63ad778
commit
3ecb5b32e4
2 changed files with 32 additions and 29 deletions
|
|
@ -15,8 +15,8 @@ function getOriginFromLocation() {
|
|||
}
|
||||
|
||||
// Define Pinia store
|
||||
export const useDefaultStore = defineStore(
|
||||
"default",
|
||||
export const useSettingsStore = defineStore(
|
||||
"settings",
|
||||
() => {
|
||||
// State
|
||||
const origin = ref(getOriginFromLocation());
|
||||
|
|
|
|||
|
|
@ -42,17 +42,19 @@ export const useWotStore = defineStore("wot", () => {
|
|||
|
||||
const thingList = computed(() => Object.keys(thingDescriptions.value));
|
||||
|
||||
const thingAvailable = (thingName) => thingName in thingDescriptions.value;
|
||||
const thingAvailable = computed(() => (thingName) => {
|
||||
return thingName in thingDescriptions.value;
|
||||
});
|
||||
|
||||
const thingAffordanceAvailable = (thing, affordanceType, affordance) => {
|
||||
const thingAffordanceAvailable = computed(() => (thing, affordanceType, affordance) => {
|
||||
const td = thingDescriptions.value[thing];
|
||||
if (!td || !td[affordanceType]) {
|
||||
return false;
|
||||
}
|
||||
if (!td || !td[affordanceType]) return false;
|
||||
return affordance in td[affordanceType];
|
||||
};
|
||||
});
|
||||
|
||||
const thingFormUrl = (thing, affordanceType, affordance, op, allowUndefined = true) => {
|
||||
const thingFormUrl = computed(
|
||||
() =>
|
||||
(thing, affordanceType, affordance, op, allowUndefined = true) => {
|
||||
// Find the URL for a particular operation
|
||||
const td = thingDescriptions.value[thing];
|
||||
if (!td) {
|
||||
|
|
@ -60,12 +62,10 @@ export const useWotStore = defineStore("wot", () => {
|
|||
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||
}
|
||||
const affordances = td[affordanceType];
|
||||
|
||||
if (!affordances || !(affordance in affordances)) {
|
||||
if (allowUndefined) return undefined;
|
||||
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||
}
|
||||
|
||||
let href = findFormHref(affordances[affordance], op);
|
||||
if (href === undefined) {
|
||||
if (allowUndefined) return undefined;
|
||||
|
|
@ -80,15 +80,18 @@ export const useWotStore = defineStore("wot", () => {
|
|||
return base + href;
|
||||
}
|
||||
return href;
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
const thingPropertyUrl = (thing, property, op, allowUndefined) =>
|
||||
const thingPropertyUrl = computed(() => (thing, property, op, allowUndefined) => {
|
||||
// Find the URL for a particular property
|
||||
thingFormUrl(thing, "properties", property, op, allowUndefined);
|
||||
return thingFormUrl.value(thing, "properties", property, op, allowUndefined);
|
||||
});
|
||||
|
||||
const thingActionUrl = (thing, action, op, allowUndefined) =>
|
||||
const thingActionUrl = computed(() => (thing, action, op, allowUndefined) => {
|
||||
// Find the URL for a particular action
|
||||
thingFormUrl(thing, "actions", action, op, allowUndefined);
|
||||
return thingFormUrl.value(thing, "actions", action, op, allowUndefined);
|
||||
});
|
||||
|
||||
return {
|
||||
thingDescriptions,
|
||||
|
|
@ -105,7 +108,7 @@ export const useWotStore = defineStore("wot", () => {
|
|||
removeThingDescription,
|
||||
removeAllThingDescriptions,
|
||||
thingAffordanceAvailable,
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
export function findFormHref(affordance, op) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue