Skip to content

Commit

Permalink
fix readme for svelte demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Oct 26, 2024
1 parent fd3b9e0 commit bc18363
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 111 deletions.
107 changes: 9 additions & 98 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,18 @@
# This repo is no longer maintained. Consider using `npm init vite` and selecting the `svelte` option or — if you want a full-fledged app framework — use [SvelteKit](https://kit.svelte.dev), the official application framework for Svelte.
# `@notemine/svelte-demo`

---
The vanilla-js demo ported to Svelte with `@notemine/wrapper` as the dependency instead of `@notemine/core`

# svelte app

This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template.

To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):

```bash
npx degit sveltejs/template svelte-app
cd svelte-app
```

*Note that you will need to have [Node.js](https://nodejs.org) installed.*


## Get started

Install the dependencies...

```bash
cd svelte-app
npm install
```

...then start [Rollup](https://rollupjs.org):

```bash
npm run dev
yarn install
```

Navigate to [localhost:8080](http://localhost:8080). 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
## Usage
Run development server
```

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"
yarn dev
```

## 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
```

If you want to use `baseUrl` or `path` aliases within your `tsconfig`, you need to set up `@rollup/plugin-alias` to tell Rollup to resolve the aliases. For more info, see [this StackOverflow question](https://stackoverflow.com/questions/63427935/setup-tsconfig-path-in-svelte).

## 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
Build package
```
yarn build
```
26 changes: 13 additions & 13 deletions demo/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'wss://140.f7z.io'
];
let notemineInstance;
let notemine;
let progressSub, successSub, errorSub, bestPowSub, workersPowSub;
const activeRelays = derived(
Expand Down Expand Up @@ -87,14 +87,14 @@
miningState.update(m => ({ ...m, mining: true, result: 'Mining started...' }));
notemineInstance = new Notemine({
notemine = new Notemine({
content: currentContent.content,
pubkey: currentUser.pubkey,
difficulty: currentContent.difficulty,
numberOfWorkers: currentContent.numberOfWorkers,
});
workersPowSub = notemineInstance.workersPow$.subscribe((data) => {
workersPowSub = notemine.workersPow$.subscribe((data) => {
miningState.update(m => {
const workersBestPow = Object.values(data);
return {
Expand All @@ -104,7 +104,7 @@
});
});
bestPowSub = notemineInstance.highestPow$.subscribe((data) => {
bestPowSub = notemine.highestPow$.subscribe((data) => {
miningState.update(m => {
const overallBestPow = data;
return {
Expand All @@ -114,10 +114,10 @@
});
});
progressSub = notemineInstance.progress$.subscribe(() => {
progressSub = notemine.progress$.subscribe(() => {
miningState.update(m => {
const overallBestPow = m.overallBestPow;
const hashRate = notemineInstance.totalHashRate
const hashRate = notemine.totalHashRate
return {
...m,
overallBestPow,
Expand All @@ -126,7 +126,7 @@
});
});
successSub = notemineInstance.success$.subscribe(({ result: minedResult }) => {
successSub = notemine.success$.subscribe(({ result: minedResult }) => {
const currentActiveRelays = get(activeRelays);
miningState.update(m => ({
...m,
Expand All @@ -136,7 +136,7 @@
}));
});
errorSub = notemineInstance.error$.subscribe(({ error }) => {
errorSub = notemine.error$.subscribe(({ error }) => {
console.error('Mining error:', error);
miningState.update(m => ({
...m,
Expand All @@ -145,7 +145,7 @@
}));
});
notemineInstance.mine();
notemine.mine();
}
const resetMiningState = () => {
Expand All @@ -160,8 +160,8 @@
}
function stopMining() {
if (notemineInstance) {
notemineInstance.cancel();
if (notemine) {
notemine.cancel();
resetMiningState();
}
}
Expand All @@ -174,8 +174,8 @@
progressSub && progressSub.unsubscribe();
successSub && successSub.unsubscribe();
errorSub && errorSub.unsubscribe();
if (notemineInstance && get(miningState).mining) {
notemineInstance.cancel();
if (notemine && get(miningState).mining) {
notemine.cancel();
}
});
</script>
Expand Down

0 comments on commit bc18363

Please sign in to comment.