Skip to content

Commit

Permalink
Merge branch 'extract-endpoint'
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Oct 1, 2024
2 parents c937874 + 85f4a4d commit e1a60ab
Show file tree
Hide file tree
Showing 62 changed files with 5,966 additions and 2,139 deletions.
9 changes: 6 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = {
],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
sourceType: 'module',
project: ['./tsconfig.json']
},
plugins: [
'@typescript-eslint'
Expand Down Expand Up @@ -64,14 +65,16 @@ module.exports = {
'@typescript-eslint/no-misused-new': 'error', // no constructors for interfaces or new for classes
'@typescript-eslint/no-namespace': 'off', // disallow the use of custom TypeScript modules and namespaces
'@typescript-eslint/no-non-null-assertion': 'off', // allow ! operator
'@typescript-eslint/parameter-properties': 'error', // no property definitions in class constructors
"@typescript-eslint/parameter-properties": "error", // no property definitions in class constructors
'@typescript-eslint/no-unused-vars': ['error', { // disallow Unused Variables
'argsIgnorePattern': '^_'
}],
'@typescript-eslint/no-var-requires': 'error', // use import instead of require
'@typescript-eslint/prefer-for-of': 'error', // prefer for-of loop over arrays
'@typescript-eslint/prefer-namespace-keyword': 'error', // prefer namespace over module in TypeScript
'@typescript-eslint/triple-slash-reference': 'error', // ban /// <reference />, prefer imports
'@typescript-eslint/type-annotation-spacing': 'error' // consistent space around colon ':'
'@typescript-eslint/type-annotation-spacing': 'error', // consistent space around colon ':'
'@typescript-eslint/strict-boolean-expressions': 'error', // Disallow certain types in boolean expressions
'@typescript-eslint/no-unnecessary-condition': 'error' // Disallow conditionals where the type is always truthy or always falsy
}
}
40 changes: 26 additions & 14 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,69 @@ jobs:
name: wtd
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
deploy_pages: ${{ steps.gen_output.outputs.deploy_gha }}

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
uses: actions/checkout@v4

- name: Volta
uses: volta-cli/action@v4

- name: Check Environment
env:
DEPLOY_GHP: ${{ false || github.event.inputs.ghp == 'true' || github.ref_name == 'main' }}
run: |
echo "DEPLOY_GHP=${DEPLOY_GHP}" >> $GITHUB_ENV
- name: Install
run: |
npm ci
- name: Lint
run: |
npm run lint
- name: Build
run: |
npm run build
- name: Test
run: |
npm run test
- name: Build Production
run: |
npm --prefix packages/examples run build:production
npm run build:production
- name: Setup Pages
if: ${{ env.DEPLOY_GHP == 'true' }}
id: pages
uses: actions/configure-pages@v4
uses: actions/configure-pages@v5

- name: Upload artifact
if: ${{ env.DEPLOY_GHP == 'true' }}
uses: actions/upload-pages-artifact@v3
with:
path: ./packages/examples/production/

- name: Generate output
id: gen_output
run: |
deploy_to_gp=${{ env.DEPLOY_GHP }}
echo "deploy_gha=${deploy_to_gp}" >> "$GITHUB_OUTPUT"
deploy:
needs: build
needs: [ build ]
if: ${{ needs.build.outputs.deploy_gha == 'true' }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest

steps:
- name: Check Environment
env:
DEPLOY_GHP: ${{ false || github.event.inputs.ghp == 'true' || github.ref_name == 'main' }}
run: |
echo "DEPLOY_GHP=${DEPLOY_GHP}" >> $GITHUB_ENV
- name: Deploy to GitHub Pages
if: ${{ env.DEPLOY_GHP == 'true' }}

id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ docs
bundle
*.tsbuildinfo
*.tgz
.vscode/profile
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
image: gitpod/workspace-full

ports:
- port: 8080
- port: 23001
onOpen: open-browser

tasks:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"davidanson.vscode-markdownlint",
"zixuanchen.vitest-explorer"
"vitest.explorer"
]
}
7 changes: 4 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
"name": "Chrome",
"url": "http://localhost:23001",
"webRoot": "${workspaceFolder}",
"userDataDir": "${workspaceFolder}/.vscode/profile"
}
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"vitest.enable": true
"vitest.disableWorkspaceWarning": true
}
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.0.0 - 2024-10-01

- ComChannelEndpoint has been extracted from WorkerTask
- Now Worker, MessageChannel or DedicatedWorkerGlobalScope can be channel endpoints. Both ends of the communication channel can use the same implementation to send message and await responses if needed.
- Added new example **HelloWorldComChannelEndpoint**

## 3.0.0 - 2024-01-05

- Make the worker lifecylce no longer mandatory if not using `WorkerTaskDirector`.
Expand All @@ -12,7 +18,7 @@
- Better function and class names
- Added helper functions for creating an OffscreenCanvas and delegating events to the worker.
- Extracted `Payload` from `DataPayload` and created `RawPayload` for supporting plain messages.
- Added offscreen canvas related funcitonality and utilities:
- Added offscreen canvas related functionality and utilities:
- Provide framework independent worker and message payload extensions (`OffscreenWorker` and `OffscreenPayload`) (**wtd-core**)
- `MainEventProxy` allows configurable event delegation to a Worker (**wtd-core**)
- `ElementProxyReceiver` can be used to simulate a canvas in a Worker (**wtd-three-ext**)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Build applications with workers with less boiler plate code.
There are multiple examples available demonstarting the features described above (listed from simpler to more advanced):

- Using [wtd-core](https://www.npmjs.com/package/wtd-core) only:
- **ComChannelEndpoint: Hello World**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/helloWorldComChannelEndpoint.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/helloWorld/HelloWorldComChannelEndpoint.ts), [worker](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/HelloWorldComChannelEndpointWorker.ts)
- **WorkerTask: Hello World**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/helloWorldWorkerTask.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/helloWorld/HelloWorldWorkerTask.ts), [worker](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/HelloWorldWorker.ts)
- **WorkerTaskDirector: Hello World**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/helloWorldWorkerTaskDirector.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/helloWorld/helloWorldWorkerTaskDirector.ts), [worker](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/HelloWorldWorker.ts)
- **WorkerTask: Inter-Worker Communication**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/workerCom.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/com/WorkerCom.ts), **Worker**: [1](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/Com1Worker.ts) and [2](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/Com2Worker.ts)
Expand Down Expand Up @@ -63,7 +64,7 @@ const workerTask = new WorkerTask({

try {
// creates and connects the worker callback functions and the WorkerTask
workerTask.connectWorker();
workerTask.connect();

// execute without init and an empty message
const resultExec = await workerTask.executeWorker({
Expand Down Expand Up @@ -100,7 +101,7 @@ Whatever environment you choose to start [Vite](https://vitejs.dev/) is used to
If you run Vite locally you require a `nodejs` and `npm`. The Gitpod and local docker environment ensure all prerequisites are fulfilled.
In any environment the dev server is reachable on port 8080.
In any environment the dev server is reachable on port 23001.
## WorkerTaskDirector Execution Workflow
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
dockerfile: Dockerfile
context: .
ports:
- target: 8080
published: 8080
- target: 23001
published: 23001
protocol: tcp
mode: host
volumes:
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<div style="padding: 5px">
<h1>Examples</h1>

<a href="packages/examples/helloWorldComChannelEndpoint.html">ComChannelEndpoint: Hello World</a>
<br>
<a href="packages/examples/helloWorldWorkerTask.html">WorkerTask: Hello World</a>
<br>
<a href="packages/examples/helloWorldWorkerTaskDirector.html">WorkerTaskDirector: Hello World</a>
Expand Down
Loading

0 comments on commit e1a60ab

Please sign in to comment.