@effectionx/raf 1.0.0-alpha.0

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 ADDED
@@ -0,0 +1,19 @@
1
+ # RAF: Request Animation Frame
2
+
3
+ Subscribe to a stream of Request Animation Frame updates with an Effection
4
+ resource.
5
+
6
+ ---
7
+
8
+ ```ts
9
+ import { each, main, suspend } from "effection";
10
+ import { raf } from "@effectionx/raf";
11
+
12
+ await main(function* () {
13
+ for (const frame of yield* each(raf)) {
14
+ // add your handler code here
15
+ console.log(frame);
16
+ yield* each.next();
17
+ }
18
+ });
19
+ ```
package/esm/mod.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./raf.js";
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -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";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/esm/raf.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { type Stream } from "effection";
2
+ /**
3
+ * Consume RAF's as a Stream.
4
+ */
5
+ export declare const raf: Stream<number, never>;
6
+ //# sourceMappingURL=raf.d.ts.map
@@ -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
+ * Consume RAF's as a Stream.
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,26 @@
1
+ {
2
+ "name": "@effectionx/raf",
3
+ "version": "1.0.0-alpha.0",
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
+ "engines": {
22
+ "node": ">= 16"
23
+ },
24
+ "sideEffects": false,
25
+ "_generatedBy": "dnt@dev"
26
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./raf.js";
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -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);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,6 @@
1
+ import { type Stream } from "effection";
2
+ /**
3
+ * Consume RAF's as a Stream.
4
+ */
5
+ export declare const raf: Stream<number, never>;
6
+ //# sourceMappingURL=raf.d.ts.map
@@ -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
+ * Consume RAF's as a Stream.
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
+ });