Linter fixes

This commit is contained in:
Richard Bowman 2023-11-30 23:21:45 +00:00
parent f1f6ed5f80
commit 54df1faeeb
4 changed files with 37 additions and 18 deletions

View file

@ -22,30 +22,42 @@ export const wotStoreModule = {
async start() {
// Set up thing client - not currently used.
},
async fetchThingDescription({ commit }, {uri, name=null}) {
async fetchThingDescription({ commit }, { uri, name = null }) {
// Fetch the thing description from the given URI and consume it
// NB this should only be called once, or we'll duplicate effort.
// Deduplication should be done elsewhere.
let response = await axios.get(uri);
let td = response.data;
let thing_name = name | uri.replace(/\/$/, "").split("/").pop();
commit("addThingDescription", { thingName: thing_name, thingDescription: td });
let thing_name =
name |
uri
.replace(/\/$/, "")
.split("/")
.pop();
commit("addThingDescription", {
thingName: thing_name,
thingDescription: td
});
},
async fetchThingDescriptions({ commit }, uri) {
// Fetch thing descriptions from the given URI
let response = await axios.get(uri);
if (response.status != 200) throw "Could not retrieve thing descriptions";
for (const k in response.data){
for (const k in response.data) {
let thing_name = k.replace(/\/$/, "").replace(/^\//, "");
commit("addThingDescription", {thing_name: thing_name, thing_description: response.data[k]});
commit("addThingDescription", {
thingName: thing_name,
thingDescription: response.data[k]
});
}
},
}
},
getters: {
thingDescription: state => thingName => {
return state.thingDescriptions[thingName];
},
thingAvailable: state => thingName => {
console.log("thingAvailable", thingName, state.thingDescriptions)
return thingName in state.thingDescriptions;
},
thingFormUrl: state => (thing, affordanceType, affordance, op) => {
@ -62,11 +74,11 @@ export const wotStoreModule = {
thingActionUrl: (_state, getters) => (thing, action, op) => {
// Find the URL for a particular action
return getters.thingFormUrl(thing, "actions", action, op);
},
}
}
};
export function findForm(affordance, op){
export function findForm(affordance, op) {
// Find the form in the affordance that matches the given operation type
let forms = affordance.forms;
let matchingForm = forms.find(f => f.op == op || f.op.includes(op));