-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from mainmatter/transform-function
feat: add `transform` function to annotate a function to be transformed by the vite plugin
- Loading branch information
Showing
24 changed files
with
1,616 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: Transform | ||
description: the transform function | ||
--- | ||
|
||
import { LinkCard, Tabs, TabItem, Aside } from '@astrojs/starlight/components'; | ||
|
||
This function allows you to mark a function that is not directly passed to the `task` function as | ||
transformable from the Async Transform. | ||
|
||
<LinkCard | ||
href="/explainers/async-transform" | ||
title="Async Transform" | ||
description="Read more about the Async Transform" | ||
/> | ||
|
||
## Usage | ||
|
||
You can import this function from `@sheepdog/svelte/utils` and call it with the same first argument | ||
you would pass to the `task` function | ||
|
||
```ts | ||
import { transform } from '@sheepdog/svelte/utils'; | ||
|
||
const myTask = transform(async (id: number) => { | ||
const res = await fetch(`/products/${id}`); | ||
return await res.json(); | ||
}); | ||
``` | ||
|
||
and this is really all you need to do. If you added the Async Transform vite plugin this function | ||
will be transformed and the `transform` import will be removed | ||
|
||
```ts | ||
const myTask = async function* (id: number) { | ||
const res = yield fetch(`/products/${id}`); | ||
return yield res.json(); | ||
}; | ||
``` | ||
|
||
If by any chance you forgot to add the vite plugin the function will just return the function as is | ||
but it will throw an error at runtime (only in dev mode) to let you know that you need to include | ||
the vite plugin to actually transform the function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ | |
"pnpm": { | ||
"patchedDependencies": { | ||
"fixturify-project": "patches/fixturify-project.patch" | ||
}, | ||
"overrides": { | ||
"@sveltejs/vite-plugin-svelte": "^4.0.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Reexport your entry components here | ||
import { didCancel, timeout } from './utils'; | ||
import { didCancel, timeout, transform } from './utils'; | ||
import { task, CancelationError } from './task.js'; | ||
export type { Task, SheepdogUtils, TaskInstance } from './task.js'; | ||
|
||
export { task, CancelationError, didCancel, timeout }; | ||
export { task, CancelationError, didCancel, timeout, transform }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.