use callbag-pipe

This commit is contained in:
Tangent Wantwight 2020-04-03 18:35:23 -04:00
parent 48940e1073
commit 33eb28e338
4 changed files with 745 additions and 637 deletions

1353
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -23,6 +23,7 @@
"callbag": "^1.2.0", "callbag": "^1.2.0",
"callbag-animation-frames": "^2.1.0", "callbag-animation-frames": "^2.1.0",
"callbag-map": "^1.1.0", "callbag-map": "^1.1.0",
"callbag-pipe": "^1.2.0",
"callbag-subscribe": "^1.5.1" "callbag-subscribe": "^1.5.1"
} }
} }

View file

@ -1,3 +1,4 @@
import pipe from "callbag-pipe";
import subscribe from "callbag-subscribe"; import subscribe from "callbag-subscribe";
import { KeyControl, KeyName } from "../Applet/Keyboard"; import { KeyControl, KeyName } from "../Applet/Keyboard";
@ -20,6 +21,8 @@ export class Main extends LockstepClient<KeyName[], Data> {
this.connect(Loopback); this.connect(Loopback);
pipe(
this.renderFrames,
subscribe((frame: Data) => { subscribe((frame: Data) => {
const drawSet = new DrawSet(); const drawSet = new DrawSet();
cx.fillStyle = "#000"; cx.fillStyle = "#000";
@ -28,7 +31,8 @@ export class Main extends LockstepClient<KeyName[], Data> {
RunRenderBounds(frame, drawSet); RunRenderBounds(frame, drawSet);
drawSet.draw(cx, 0); drawSet.draw(cx, 0);
})(this.renderFrames); })
);
} }
gatherInput() { gatherInput() {

View file

@ -2,6 +2,7 @@
import { Callbag } from "callbag"; import { Callbag } from "callbag";
import animationFrames from "callbag-animation-frames"; import animationFrames from "callbag-animation-frames";
import map from "callbag-map"; import map from "callbag-map";
import pipe from "callbag-pipe";
import { INPUT_FREQUENCY, LockstepProcessor, LockstepState } from "../Ecs/Lockstep"; import { INPUT_FREQUENCY, LockstepProcessor, LockstepState } from "../Ecs/Lockstep";
@ -88,5 +89,8 @@ export abstract class LockstepClient<Input, State> {
}; };
} }
public renderFrames = map((ms: number) => this.state.getStateToRender())(animationFrames); public renderFrames = pipe(
animationFrames,
map(_ms => this.state.getStateToRender())
);
} }