Skip to content

Commit 1204536

Browse files
committed
First version
0 parents  commit 1204536

22 files changed

Lines changed: 982 additions & 0 deletions

.github/workflows/build.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Build
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
7+
jobs:
8+
prettier:
9+
name: "prettier"
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
deno-version: [1.45.3]
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: "20.x"
21+
registry-url: "https://registry.npmjs.org"
22+
- run: yarn install --frozen-lockfile
23+
24+
- name: run prettier checker
25+
run: yarn prettier:check
26+
27+
- name: Use Deno Version ${{ matrix.deno-version }}
28+
uses: denoland/setup-deno@v1
29+
with:
30+
deno-version: ${{ matrix.deno-version }}

.github/workflows/publish.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish
2+
on:
3+
push:
4+
tags:
5+
- "*"
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
deno-version: [1.45.3]
13+
14+
permissions:
15+
contents: read
16+
id-token: write
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set Versions
22+
uses: actions/github-script@v4
23+
id: set_version
24+
with:
25+
script: |
26+
const tag = context.ref.substring(10).replace('v', '')
27+
core.setOutput('tag', tag)
28+
console.log(tag)
29+
30+
- uses: actions/setup-node@v4
31+
with:
32+
node-version: "20.x"
33+
registry-url: "https://registry.npmjs.org"
34+
- run: yarn install --frozen-lockfile
35+
36+
- name: run prettier checker
37+
run: yarn prettier:check
38+
39+
- name: Add version to package.json
40+
uses: jaywcjlove/github-action-package@main
41+
with:
42+
path: "./deno.json"
43+
data: |
44+
{
45+
"version": "${{ steps.set_version.outputs.tag }}"
46+
}
47+
48+
- name: Publish package
49+
run: npx jsr publish --allow-dirty

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.idea

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# @oh/queue
2+
3+
The idea is to make a ticker and a queue that works exactly the same between back runtime and web.
4+
Using `setTimeout` on back and `requestAnimationFrame` on the web.
5+
6+
## with web
7+
8+
`yarn dlx jsr add @oh/queue`
9+
10+
```ts
11+
import { queue, windowTicker, TickerQueue, ticker } from "@oh/queue";
12+
13+
const $ticker = windowTicker();
14+
const $queue = queue();
15+
16+
$ticker.onTick(({ delta }) => $queue.tick(delta));
17+
$ticker.load({ fps: 60 });
18+
$ticker.start();
19+
20+
const startTime = performance.now();
21+
$queue.add({
22+
type: TickerQueue.DURATION,
23+
duration: 5_000,
24+
onFunc(delta) {
25+
console.log("onFunc", delta);
26+
},
27+
onDone() {
28+
console.log("onDone", performance.now() - startTime);
29+
},
30+
});
31+
```
32+
33+
## with deno
34+
35+
`deno add @oh/queue`
36+
37+
```ts
38+
import { queue, ticker, TickerQueue } from "@oh/queue/mod.ts";
39+
40+
const $ticker = ticker();
41+
const $queue = queue();
42+
43+
$ticker.onTick(({ delta }) => $queue.tick(delta));
44+
$ticker.load({ ticks: 60 });
45+
$ticker.start();
46+
47+
const startTime = performance.now();
48+
$queue.add({
49+
type: TickerQueue.DURATION,
50+
duration: 5_000,
51+
onFunc(delta) {
52+
console.log("onFunc", delta);
53+
},
54+
onDone() {
55+
console.log("onDone", performance.now() - startTime);
56+
},
57+
});
58+
```

deno.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@oh/queue",
3+
"version": "0.0.0",
4+
"exports": "./mod.ts",
5+
"imports": {
6+
"std/": "https://deno.land/std@0.224.0/"
7+
},
8+
"tasks": {
9+
"start:example": "deno run -A ./example.ts"
10+
}
11+
}

example.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { queue, ticker, TickerQueue } from "./mod.ts";
2+
3+
const $ticker = ticker();
4+
const $queue = queue();
5+
6+
$ticker.onTick(({ delta }) => $queue.tick(delta));
7+
$ticker.load({ ticks: 60 });
8+
$ticker.start();
9+
10+
const startTime = performance.now();
11+
$queue.add({
12+
type: TickerQueue.DURATION,
13+
duration: 5_000,
14+
onFunc(delta) {
15+
console.log("onFunc", delta);
16+
},
17+
onDone() {
18+
console.log("onDone", performance.now() - startTime);
19+
},
20+
});

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./src/main.ts";

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"scripts": {
3+
"bundle": "esbuild --bundle mod.ts --outfile=./preview/bundle.js --format=esm",
4+
"prettier:check": "prettier -c ./",
5+
"prettier:write": "prettier --write ."
6+
},
7+
"devDependencies": {
8+
"prettier": "3.3.3",
9+
"esbuild": "0.23.0"
10+
}
11+
}

0 commit comments

Comments
 (0)