ui_migration refactor(store) Remove lingering getters at wot.js pinia store

This commit is contained in:
Antonio Anaya 2026-05-24 18:16:01 -06:00
parent ace7ae9855
commit f8c4ffe62b

View file

@ -9,6 +9,10 @@ export const useWotStore = defineStore(
const thingDescriptions = ref({});
const servient = ref(null);
const helpers = ref(null);
// Getters
const thingList = computed(() => Object.keys(thingDescriptions.value));
// Actions
function addThingDescription(thingName, thingDescription) {
thingDescriptions.value[thingName] = thingDescription;
@ -42,58 +46,53 @@ export const useWotStore = defineStore(
}
}
const thingList = computed(() => Object.keys(thingDescriptions.value));
const thingAvailable = computed(() => (thingName) => {
function thingAvailable(thingName) {
return thingName in thingDescriptions.value;
});
}
const thingAffordanceAvailable = computed(() => (thing, affordanceType, affordance) => {
function thingAffordanceAvailable(thing, affordanceType, affordance) {
const td = thingDescriptions.value[thing];
if (!td || !td[affordanceType]) return false;
return affordance in td[affordanceType];
});
}
const thingFormUrl = computed(
() =>
(thing, affordanceType, affordance, op, allowUndefined = true) => {
// Find the URL for a particular operation
const td = thingDescriptions.value[thing];
if (!td) {
if (allowUndefined) return undefined;
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;
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
}
// If we've found an href, prepend the `base` URL if appropriate
if (href.startsWith("http")) return href;
if ("base" in td) {
let base = td.base;
if (href.startsWith("/")) href = href.slice(1);
if (!base.endsWith("/")) base += "/";
return base + href;
}
return href;
},
);
function thingFormUrl(thing, affordanceType, affordance, op, allowUndefined = true) {
// Find the URL for a particular operation
const td = thingDescriptions.value[thing];
if (!td) {
if (allowUndefined) return undefined;
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;
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
}
// If we've found an href, prepend the `base` URL if appropriate
if (href.startsWith("http")) return href;
if ("base" in td) {
let base = td.base;
if (href.startsWith("/")) href = href.slice(1);
if (!base.endsWith("/")) base += "/";
return base + href;
}
return href;
}
const thingPropertyUrl = computed(() => (thing, property, op, allowUndefined) => {
function thingPropertyUrl(thing, property, op, allowUndefined) {
// Find the URL for a particular property
return thingFormUrl.value(thing, "properties", property, op, allowUndefined);
});
return thingFormUrl(thing, "properties", property, op, allowUndefined);
}
const thingActionUrl = computed(() => (thing, action, op, allowUndefined) => {
function thingActionUrl(thing, action, op, allowUndefined) {
// Find the URL for a particular action
return thingFormUrl.value(thing, "actions", action, op, allowUndefined);
});
return thingFormUrl(thing, "actions", action, op, allowUndefined);
}
return {
thingDescriptions,