@effectionx/raf 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/esm/mod.d.ts +2 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +1 -0
- package/esm/package.json +3 -0
- package/esm/raf.d.ts +6 -0
- package/esm/raf.d.ts.map +1 -0
- package/esm/raf.js +19 -0
- package/package.json +30 -0
- package/script/mod.d.ts +2 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +17 -0
- package/script/package.json +3 -0
- package/script/raf.d.ts +6 -0
- package/script/raf.d.ts.map +1 -0
- package/script/raf.js +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# RAF: Request Animation Frame
|
|
2
|
+
|
|
3
|
+
Subscribe to a stream of
|
|
4
|
+
[Request Animation Frame](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame)
|
|
5
|
+
updates.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { each, main, suspend } from "effection";
|
|
11
|
+
import { raf } from "@effectionx/raf";
|
|
12
|
+
|
|
13
|
+
await main(function* () {
|
|
14
|
+
for (const timestamp of yield* each(raf)) {
|
|
15
|
+
// add your handler code here
|
|
16
|
+
console.log(timestamp);
|
|
17
|
+
yield* each.next();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
```
|
package/esm/mod.d.ts
ADDED
package/esm/mod.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/esm/mod.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./raf.js";
|
package/esm/package.json
ADDED
package/esm/raf.d.ts
ADDED
package/esm/raf.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raf.d.ts","sourceRoot":"","sources":["../src/raf.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAChE;;GAEG;AACH,eAAO,MAAM,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAerC,CAAC"}
|
package/esm/raf.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createSignal, resource } from "effection";
|
|
2
|
+
/**
|
|
3
|
+
* A stream that produces animation frames.
|
|
4
|
+
*/
|
|
5
|
+
export const raf = resource(function* (provide) {
|
|
6
|
+
let signal = createSignal();
|
|
7
|
+
let id = 0;
|
|
8
|
+
let callback = (timestamp) => {
|
|
9
|
+
signal.send(timestamp);
|
|
10
|
+
id = requestAnimationFrame(callback);
|
|
11
|
+
};
|
|
12
|
+
id = requestAnimationFrame(callback);
|
|
13
|
+
try {
|
|
14
|
+
yield* provide(yield* signal);
|
|
15
|
+
}
|
|
16
|
+
finally {
|
|
17
|
+
cancelAnimationFrame(id);
|
|
18
|
+
}
|
|
19
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effectionx/raf",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "engineering@frontside.com",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/thefrontside/effectionx.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/thefrontside/effectionx/issues"
|
|
12
|
+
},
|
|
13
|
+
"main": "./script/mod.js",
|
|
14
|
+
"module": "./esm/mod.js",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./esm/mod.js",
|
|
18
|
+
"require": "./script/mod.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">= 16"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"effection": "^3"
|
|
28
|
+
},
|
|
29
|
+
"_generatedBy": "dnt@dev"
|
|
30
|
+
}
|
package/script/mod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/script/mod.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./raf.js"), exports);
|
package/script/raf.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raf.d.ts","sourceRoot":"","sources":["../src/raf.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAChE;;GAEG;AACH,eAAO,MAAM,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAerC,CAAC"}
|
package/script/raf.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.raf = void 0;
|
|
4
|
+
const effection_1 = require("effection");
|
|
5
|
+
/**
|
|
6
|
+
* A stream that produces animation frames.
|
|
7
|
+
*/
|
|
8
|
+
exports.raf = (0, effection_1.resource)(function* (provide) {
|
|
9
|
+
let signal = (0, effection_1.createSignal)();
|
|
10
|
+
let id = 0;
|
|
11
|
+
let callback = (timestamp) => {
|
|
12
|
+
signal.send(timestamp);
|
|
13
|
+
id = requestAnimationFrame(callback);
|
|
14
|
+
};
|
|
15
|
+
id = requestAnimationFrame(callback);
|
|
16
|
+
try {
|
|
17
|
+
yield* provide(yield* signal);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
cancelAnimationFrame(id);
|
|
21
|
+
}
|
|
22
|
+
});
|