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
|
// Define Pinia store
|
||||||
export const useDefaultStore = defineStore(
|
export const useSettingsStore = defineStore(
|
||||||
"default",
|
"settings",
|
||||||
() => {
|
() => {
|
||||||
// State
|
// State
|
||||||
const origin = ref(getOriginFromLocation());
|
const origin = ref(getOriginFromLocation());
|
||||||
|
|
|
||||||
|
|
@ -42,17 +42,19 @@ export const useWotStore = defineStore("wot", () => {
|
||||||
|
|
||||||
const thingList = computed(() => Object.keys(thingDescriptions.value));
|
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];
|
const td = thingDescriptions.value[thing];
|
||||||
if (!td || !td[affordanceType]) {
|
if (!td || !td[affordanceType]) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return affordance in td[affordanceType];
|
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
|
// Find the URL for a particular operation
|
||||||
const td = thingDescriptions.value[thing];
|
const td = thingDescriptions.value[thing];
|
||||||
if (!td) {
|
if (!td) {
|
||||||
|
|
@ -60,12 +62,10 @@ export const useWotStore = defineStore("wot", () => {
|
||||||
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||||
}
|
}
|
||||||
const affordances = td[affordanceType];
|
const affordances = td[affordanceType];
|
||||||
|
|
||||||
if (!affordances || !(affordance in affordances)) {
|
if (!affordances || !(affordance in affordances)) {
|
||||||
if (allowUndefined) return undefined;
|
if (allowUndefined) return undefined;
|
||||||
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let href = findFormHref(affordances[affordance], op);
|
let href = findFormHref(affordances[affordance], op);
|
||||||
if (href === undefined) {
|
if (href === undefined) {
|
||||||
if (allowUndefined) return undefined;
|
if (allowUndefined) return undefined;
|
||||||
|
|
@ -80,15 +80,18 @@ export const useWotStore = defineStore("wot", () => {
|
||||||
return base + href;
|
return base + href;
|
||||||
}
|
}
|
||||||
return href;
|
return href;
|
||||||
};
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const thingPropertyUrl = (thing, property, op, allowUndefined) =>
|
const thingPropertyUrl = computed(() => (thing, property, op, allowUndefined) => {
|
||||||
// Find the URL for a particular property
|
// 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
|
// Find the URL for a particular action
|
||||||
thingFormUrl(thing, "actions", action, op, allowUndefined);
|
return thingFormUrl.value(thing, "actions", action, op, allowUndefined);
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
thingDescriptions,
|
thingDescriptions,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue