-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add svelte example, maybe batch (#5)
- Loading branch information
1 parent
0b81434
commit ef742ef
Showing
23 changed files
with
1,728 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,41 @@ | ||
import { createApi } from "@rtk-incubator/simple-query/dist"; | ||
import { createApi, fetchBaseQuery } from '@rtk-incubator/simple-query/dist'; | ||
|
||
interface CountResponse { | ||
count: number; | ||
} | ||
|
||
interface QueryArg { | ||
queryString: string; | ||
method?: string; | ||
body?: string; | ||
headers?: any; | ||
} | ||
|
||
export const counterApi = createApi({ | ||
reducerPath: "counterApi", | ||
baseQuery({ | ||
queryString = "", | ||
method = "GET", | ||
body, | ||
headers = { | ||
"Content-Type": "application/json" | ||
} | ||
}: QueryArg) { | ||
return fetch(`/${queryString}`, { method, body, headers }).then((res) => | ||
res.json() | ||
); | ||
}, | ||
entityTypes: ["Counter"], // used for invalidation | ||
reducerPath: 'counterApi', | ||
baseQuery: fetchBaseQuery(), | ||
entityTypes: ['Counter'], | ||
endpoints: (build) => ({ | ||
getCount: build.query<CountResponse, void>({ | ||
query() { | ||
return { | ||
queryString: `count` | ||
queryString: `count`, | ||
}; | ||
}, | ||
provides: [{ type: "Counter" }] // this provides entities of the type X - if you use a mutation that impacts this entity it will refetch | ||
provides: [{ type: 'Counter' }], | ||
}), | ||
incrementCount: build.mutation<CountResponse, number>({ | ||
query(amount) { | ||
return { | ||
queryString: `increment`, | ||
method: "PUT", | ||
body: JSON.stringify({ amount }) | ||
method: 'PUT', | ||
body: JSON.stringify({ amount }), | ||
}; | ||
}, | ||
invalidates: [{ type: "Counter" }] | ||
invalidates: [{ type: 'Counter' }], | ||
}), | ||
decrementCount: build.mutation<CountResponse, number>({ | ||
query(amount) { | ||
return { | ||
queryString: `decrement`, | ||
method: "PUT", | ||
body: JSON.stringify({ amount }) | ||
method: 'PUT', | ||
body: JSON.stringify({ amount }), | ||
}; | ||
}, | ||
invalidates: [{ type: "Counter" }] | ||
}) | ||
}) | ||
invalidates: [{ type: 'Counter' }], | ||
}), | ||
}), | ||
}); |
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,4 @@ | ||
/node_modules/ | ||
/public/build/ | ||
|
||
.DS_Store |
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,7 @@ | ||
{ | ||
"tabWidth": 4, | ||
"printWidth": 120, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
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,3 @@ | ||
{ | ||
"recommendations": ["svelte.svelte-vscode"] | ||
} |
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,6 @@ | ||
{ | ||
"[svelte]": { | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "svelte.svelte-vscode" | ||
} | ||
} |
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,90 @@ | ||
# Svelte app with msw | ||
|
||
Just a basic test hooking up MSW for svelte trial purposes. | ||
|
||
## Get started | ||
|
||
Install the dependencies... | ||
|
||
```bash | ||
cd svelte-app | ||
npm install | ||
``` | ||
|
||
...then start [Rollup](https://rollupjs.org): | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. | ||
|
||
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`. | ||
|
||
If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense. | ||
|
||
## Building and running in production mode | ||
|
||
To create an optimised version of the app: | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com). | ||
|
||
## Single-page app mode | ||
|
||
By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere. | ||
|
||
If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for _any_ path. You can make it so by editing the `"start"` command in package.json: | ||
|
||
```js | ||
"start": "sirv public --single" | ||
``` | ||
|
||
## Using TypeScript | ||
|
||
This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with: | ||
|
||
```bash | ||
node scripts/setupTypeScript.js | ||
``` | ||
|
||
Or remove the script via: | ||
|
||
```bash | ||
rm scripts/setupTypeScript.js | ||
``` | ||
|
||
## Deploying to the web | ||
|
||
### With [Vercel](https://vercel.com) | ||
|
||
Install `vercel` if you haven't already: | ||
|
||
```bash | ||
npm install -g vercel | ||
``` | ||
|
||
Then, from within your project folder: | ||
|
||
```bash | ||
cd public | ||
vercel deploy --name my-project | ||
``` | ||
|
||
### With [surge](https://surge.sh/) | ||
|
||
Install `surge` if you haven't already: | ||
|
||
```bash | ||
npm install -g surge | ||
``` | ||
|
||
Then, from within your project folder: | ||
|
||
```bash | ||
npm run build | ||
surge public my-project.surge.sh | ||
``` |
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,32 @@ | ||
{ | ||
"name": "svelte-app-rtk-simplequery-demo", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w", | ||
"start": "sirv public", | ||
"validate": "svelte-check" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^14.0.0", | ||
"@rollup/plugin-node-resolve": "^8.0.0", | ||
"@rollup/plugin-typescript": "^6.0.0", | ||
"@rtk-incubator/simple-query": "https://pkg.csb.dev/rtk-incubator/simple-query/commit/fcea624c/@rtk-incubator/simple-query", | ||
"@tsconfig/svelte": "^1.0.0", | ||
"msw": "^0.21.3", | ||
"rollup": "^2.3.4", | ||
"rollup-plugin-inject-process-env": "^1.3.1", | ||
"rollup-plugin-livereload": "^2.0.0", | ||
"rollup-plugin-svelte": "^6.0.0", | ||
"rollup-plugin-terser": "^7.0.0", | ||
"svelte": "^3.0.0", | ||
"svelte-check": "^1.0.0", | ||
"svelte-preprocess": "^4.0.0", | ||
"tslib": "^2.0.0", | ||
"typescript": "^3.9.3" | ||
}, | ||
"dependencies": { | ||
"@reduxjs/toolkit": "^1.4.0", | ||
"sirv-cli": "^1.0.0" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
html, body { | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
body { | ||
color: #333; | ||
margin: 0; | ||
padding: 8px; | ||
box-sizing: border-box; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; | ||
} | ||
|
||
a { | ||
color: rgb(0,100,200); | ||
text-decoration: none; | ||
} | ||
|
||
a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
a:visited { | ||
color: rgb(0,80,160); | ||
} | ||
|
||
label { | ||
display: block; | ||
} | ||
|
||
input, button, select, textarea { | ||
font-family: inherit; | ||
font-size: inherit; | ||
-webkit-padding: 0.4em 0; | ||
padding: 0.4em; | ||
margin: 0 0 0.5em 0; | ||
box-sizing: border-box; | ||
border: 1px solid #ccc; | ||
border-radius: 2px; | ||
} | ||
|
||
input:disabled { | ||
color: #ccc; | ||
} | ||
|
||
button { | ||
color: #333; | ||
background-color: #f4f4f4; | ||
outline: none; | ||
} | ||
|
||
button:disabled { | ||
color: #999; | ||
} | ||
|
||
button:not(:disabled):active { | ||
background-color: #ddd; | ||
} | ||
|
||
button:focus { | ||
border-color: #666; | ||
} |
Oops, something went wrong.