Skip to content

Commit 98ef091

Browse files
authored
refactor(core): adjustments to plugin lifecycle (#51)
* refactor(core): remove timeout logic and next * refactor(with-caching): custom headers are prefixed with `x-fetcher` * fix(with-caching): store url as part of the cache * refactor(plugins): use objects to pass options to plugins * chore(deps): add encoding as a fetcher core dep * fix(docs): fix base `eslint` import
1 parent f2be96c commit 98ef091

File tree

25 files changed

+191
-165
lines changed

25 files changed

+191
-165
lines changed

.changeset/gold-sloths-listen.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@composite-fetcher/with-caching': patch
3+
'@composite-fetcher/with-logging': patch
4+
---
5+
6+
refactor(plugins): use objects to pass options to plugins

.changeset/good-steaks-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@composite-fetcher/with-caching': patch
3+
---
4+
5+
fix(with-caching): store url as part of the cache

.changeset/hot-guests-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@composite-fetcher/with-caching': patch
3+
---
4+
5+
refactor(with-caching): custom headers are prefixed with `x-fetcher`

.changeset/olive-fishes-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@composite-fetcher/core': patch
3+
---
4+
5+
chore(deps): add encoding as a fetcher core dep

.changeset/tiny-years-raise.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@composite-fetcher/core': patch
3+
'@composite-fetcher/with-caching': patch
4+
'@composite-fetcher/with-logging': patch
5+
---
6+
7+
refactor(core): remove timeout logic and next

apps/docs/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
root: true,
3-
extends: ['@composite-fetcher/eslint-config'],
3+
extends: ['@composite-fetcher/eslint-config/base'],
44
};

apps/docs/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next"
1212
},
1313
"dependencies": {
14+
"@composite-fetcher/core": "workspace:^",
1415
"@composite-fetcher/utils": "workspace:*",
16+
"@composite-fetcher/with-caching": "workspace:^",
17+
"@composite-fetcher/with-logging": "workspace:^",
1518
"next": "^13.4.1",
1619
"react": "^18.2.0",
1720
"react-dom": "^18.2.0"

apps/docs/src/app/page.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
'use client';
2+
3+
import fetcher from '../lib/fetcher';
4+
15
export default function Page() {
6+
const handleClick = () => {
7+
fetcher
8+
.fetch('https://catfact.ninja/breeds?limit=1')
9+
.then((res) => res.json())
10+
.then(console.log)
11+
.catch(console.error);
12+
};
213
return (
314
<>
415
<h1>Web</h1>
5-
<button>Boop</button>
16+
<button onClick={handleClick}>Boop</button>
617
</>
718
);
819
}

apps/docs/src/lib/fetcher.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Fetcher } from '@composite-fetcher/core';
2+
import {
3+
SessionStorageDriver,
4+
withCaching as WithCaching,
5+
} from '@composite-fetcher/with-caching';
6+
import { withLogging as WithLogging } from '@composite-fetcher/with-logging';
7+
8+
const fetcher = new Fetcher();
9+
fetcher.use(new WithLogging());
10+
fetcher.use(new WithCaching({ cacheDriver: new SessionStorageDriver() }));
11+
12+
export default fetcher;

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"ts-jest": "^29.1.1"
3939
},
4040
"dependencies": {
41+
"encoding": "^0.1.13",
4142
"isomorphic-fetch": "^3.0.0"
4243
}
4344
}

0 commit comments

Comments
 (0)