ui_migration refactor(store) Remove lingering getters at wot.js pinia store
This commit is contained in:
parent
ace7ae9855
commit
f8c4ffe62b
1 changed files with 41 additions and 42 deletions
|
|
@ -9,6 +9,10 @@ export const useWotStore = defineStore(
|
||||||
const thingDescriptions = ref({});
|
const thingDescriptions = ref({});
|
||||||
const servient = ref(null);
|
const servient = ref(null);
|
||||||
const helpers = ref(null);
|
const helpers = ref(null);
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
const thingList = computed(() => Object.keys(thingDescriptions.value));
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
function addThingDescription(thingName, thingDescription) {
|
function addThingDescription(thingName, thingDescription) {
|
||||||
thingDescriptions.value[thingName] = thingDescription;
|
thingDescriptions.value[thingName] = thingDescription;
|
||||||
|
|
@ -42,58 +46,53 @@ export const useWotStore = defineStore(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const thingList = computed(() => Object.keys(thingDescriptions.value));
|
function thingAvailable(thingName) {
|
||||||
|
|
||||||
const thingAvailable = computed(() => (thingName) => {
|
|
||||||
return thingName in thingDescriptions.value;
|
return thingName in thingDescriptions.value;
|
||||||
});
|
}
|
||||||
|
|
||||||
const thingAffordanceAvailable = computed(() => (thing, affordanceType, affordance) => {
|
function thingAffordanceAvailable(thing, affordanceType, affordance) {
|
||||||
const td = thingDescriptions.value[thing];
|
const td = thingDescriptions.value[thing];
|
||||||
if (!td || !td[affordanceType]) return false;
|
if (!td || !td[affordanceType]) return false;
|
||||||
return affordance in td[affordanceType];
|
return affordance in td[affordanceType];
|
||||||
});
|
}
|
||||||
|
|
||||||
const thingFormUrl = computed(
|
function thingFormUrl(thing, affordanceType, affordance, op, allowUndefined = true) {
|
||||||
() =>
|
// Find the URL for a particular operation
|
||||||
(thing, affordanceType, affordance, op, allowUndefined = true) => {
|
const td = thingDescriptions.value[thing];
|
||||||
// Find the URL for a particular operation
|
if (!td) {
|
||||||
const td = thingDescriptions.value[thing];
|
if (allowUndefined) return undefined;
|
||||||
if (!td) {
|
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||||
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)) {
|
||||||
const affordances = td[affordanceType];
|
if (allowUndefined) return undefined;
|
||||||
if (!affordances || !(affordance in affordances)) {
|
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||||
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) {
|
||||||
let href = findFormHref(affordances[affordance], op);
|
if (allowUndefined) return undefined;
|
||||||
if (href === undefined) {
|
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||||
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 we've found an href, prepend the `base` URL if appropriate
|
if ("base" in td) {
|
||||||
if (href.startsWith("http")) return href;
|
let base = td.base;
|
||||||
if ("base" in td) {
|
if (href.startsWith("/")) href = href.slice(1);
|
||||||
let base = td.base;
|
if (!base.endsWith("/")) base += "/";
|
||||||
if (href.startsWith("/")) href = href.slice(1);
|
return base + href;
|
||||||
if (!base.endsWith("/")) base += "/";
|
}
|
||||||
return base + href;
|
return href;
|
||||||
}
|
}
|
||||||
return href;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const thingPropertyUrl = computed(() => (thing, property, op, allowUndefined) => {
|
function thingPropertyUrl(thing, property, op, allowUndefined) {
|
||||||
// Find the URL for a particular property
|
// 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
|
// Find the URL for a particular action
|
||||||
return thingFormUrl.value(thing, "actions", action, op, allowUndefined);
|
return thingFormUrl(thing, "actions", action, op, allowUndefined);
|
||||||
});
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
thingDescriptions,
|
thingDescriptions,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue