Scope of addType function is global
This commit is contained in:
@@ -16,5 +16,6 @@ module.exports = {
|
|||||||
rules: {
|
rules: {
|
||||||
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
|
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
|
||||||
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
|
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
|
||||||
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -70,9 +70,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
celestial: Object
|
celestial: Object
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
console.log(this.celestial);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
26
src/plugins/methods/index.ts
Normal file
26
src/plugins/methods/index.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
export const addCelestialType = (celestial: any) => {
|
||||||
|
if (celestial.isPlanet) {
|
||||||
|
if (celestial.moons) {
|
||||||
|
celestial.type = "planète à lunes";
|
||||||
|
} else {
|
||||||
|
celestial.type = "planète";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if element is moon
|
||||||
|
} else if (celestial.aroundPlanet != null) {
|
||||||
|
celestial.type = "lune";
|
||||||
|
|
||||||
|
// Check if element is star
|
||||||
|
} else if (celestial.id === "soleil") {
|
||||||
|
celestial.type = "étoile";
|
||||||
|
|
||||||
|
// ...else, body is "other"
|
||||||
|
} else {
|
||||||
|
celestial.type = "autre";
|
||||||
|
}
|
||||||
|
return celestial;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
addCelestialType
|
||||||
|
};
|
||||||
@@ -11,9 +11,13 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
|
import CelestialsList from "@/components/celestials/CelestialsList.vue";
|
||||||
|
|
||||||
|
// API
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import CelestialsList from "@/components/celestials/CelestialsList.vue";
|
// Global methods
|
||||||
|
import { addCelestialType } from "@/plugins/methods";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "Celestials",
|
name: "Celestials",
|
||||||
@@ -24,7 +28,7 @@ export default defineComponent({
|
|||||||
// Initial state
|
// Initial state
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
celestials: []
|
celestials: Array<any>()
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -34,13 +38,14 @@ export default defineComponent({
|
|||||||
// ...and add type
|
// ...and add type
|
||||||
this.celestials = this.addType(res);
|
this.celestials = this.addType(res);
|
||||||
});
|
});
|
||||||
|
console.log(this.$options);
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
/**
|
||||||
* Fetches celestial bodies from API
|
* Fetches celestial bodies from API
|
||||||
*/
|
*/
|
||||||
fetchBodies() {
|
fetchBodies(): Promise<any> {
|
||||||
return axios
|
return axios
|
||||||
.get("https://api.le-systeme-solaire.net/rest/bodies/")
|
.get("https://api.le-systeme-solaire.net/rest/bodies/")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
@@ -55,30 +60,8 @@ export default defineComponent({
|
|||||||
/**
|
/**
|
||||||
* Assign a type from the celestial object provided
|
* Assign a type from the celestial object provided
|
||||||
*/
|
*/
|
||||||
addType(bodies: []) {
|
addType(bodies: Array<any>): Array<any> {
|
||||||
return bodies.filter((e: any) => {
|
return bodies.map((e: any) => addCelestialType(e));
|
||||||
// Check if element is planet
|
|
||||||
if (e.isPlanet) {
|
|
||||||
if (e.moons) {
|
|
||||||
e.type = "planète à lunes";
|
|
||||||
} else {
|
|
||||||
e.type = "planète";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if element is moon
|
|
||||||
} else if (e.aroundPlanet != null) {
|
|
||||||
e.type = "lune";
|
|
||||||
|
|
||||||
// Check if element is star
|
|
||||||
} else if (e.id === "soleil") {
|
|
||||||
e.type = "étoile";
|
|
||||||
|
|
||||||
// ...else, body is "other"
|
|
||||||
} else {
|
|
||||||
e.type = "autre";
|
|
||||||
}
|
|
||||||
return e;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user