Przeglądaj źródła

replace request-js with native fetch

Aneurin Barker Snook 11 miesięcy temu
rodzic
commit
66fce99f19
3 zmienionych plików z 6 dodań i 13 usunięć
  1. 0 7
      package-lock.json
  2. 0 1
      package.json
  3. 6 5
      src/components/Skills.ts

+ 0 - 7
package-lock.json

@@ -9,7 +9,6 @@
       "version": "1.0.0",
       "dependencies": {
         "@annybs/eslint": "^1.0.0",
-        "@annybs/request-js": "^1.0.2",
         "alpinejs": "^3.14.0",
         "sass": "^1.77.5"
       },
@@ -31,12 +30,6 @@
         "typescript-eslint": "^7.13.0"
       }
     },
-    "node_modules/@annybs/request-js": {
-      "version": "1.0.2",
-      "resolved": "https://npm.pkg.github.com/download/@annybs/request-js/1.0.2/6b33f14776e5dccaa585d8b1eb18fcdc34f5601d",
-      "integrity": "sha512-6oqDMoRmjRYb7XQNE3AC3f6WBVjxqx5OY+86mpxp8BruWUYYURNwTvbw6BXQvpiGSGKa/Z8cERSEC50Ew8hz7A==",
-      "license": "MIT"
-    },
     "node_modules/@esbuild/linux-x64": {
       "version": "0.20.2",
       "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.20.2.tgz",

+ 0 - 1
package.json

@@ -15,7 +15,6 @@
   },
   "dependencies": {
     "@annybs/eslint": "^1.0.0",
-    "@annybs/request-js": "^1.0.2",
     "alpinejs": "^3.14.0",
     "sass": "^1.77.5"
   }

+ 6 - 5
src/components/Skills.ts

@@ -1,5 +1,3 @@
-import request, { ErrorResponse } from '@annybs/request-js'
-
 export interface Skill {
   name: string
   link?: string
@@ -53,11 +51,14 @@ export default function Skills(): SkillsState {
       this.currentTag = tag
 
       try {
-        const res = await request.get(url)
-        this.skills = (res.json as Skill[]).sort((a, b) => a.name.localeCompare(b.name))
+        const res = await fetch(url)
+        if (res.status !== 200) throw new Error('not OK')
+
+        const data = await res.json() as Skill[]
+        this.skills = (data).sort((a, b) => a.name.localeCompare(b.name))
         updateVisibleSkills.apply(this)
       } catch (err) {
-        const e = err as ErrorResponse
+        const e = err as Error
         console.error(e.name, e.message)
       }
     },