foldkit 0.82.6 → 0.82.7
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.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Effect, SubscriptionRef } from 'effect';
|
|
2
|
+
export type RenderLoopConfig = Readonly<{
|
|
3
|
+
/** SubscriptionRef holding the dirty bit. The loop subscribes to its changes
|
|
4
|
+
* Stream so it can suspend entirely when the bit stays false. */
|
|
5
|
+
pendingRef: SubscriptionRef.SubscriptionRef<boolean>;
|
|
6
|
+
/** Effect that yields once the next animation frame fires. */
|
|
7
|
+
awaitNextFrame: Effect.Effect<void>;
|
|
8
|
+
/** Effect that returns whether the runtime is paused (e.g. via DevTools
|
|
9
|
+
* time-travel). When true, the body skips render but still clears the bit. */
|
|
10
|
+
isPaused: Effect.Effect<boolean>;
|
|
11
|
+
/** Effect that performs one render with the latest model. */
|
|
12
|
+
render: Effect.Effect<void>;
|
|
13
|
+
}>;
|
|
14
|
+
/** Builds an idle-suspending render loop driven by a SubscriptionRef of
|
|
15
|
+
* "render is pending."
|
|
16
|
+
*
|
|
17
|
+
* The loop subscribes to the ref's changes Stream and runs the body once per
|
|
18
|
+
* false-to-true transition. Stream.changes filters consecutive equals so a
|
|
19
|
+
* burst of `set(true)` calls inside one frame produces a single body run.
|
|
20
|
+
*
|
|
21
|
+
* The body waits for the next animation frame, clears the dirty bit, then
|
|
22
|
+
* renders if not paused. The bit is cleared on every body run (including
|
|
23
|
+
* paused early-returns) so the next dispatch is always a real false-to-true
|
|
24
|
+
* transition. This makes the loop self-recovering even when paused state
|
|
25
|
+
* flips externally without a synchronous render. */
|
|
26
|
+
export declare const makeRenderLoop: ({ pendingRef, awaitNextFrame, isPaused, render, }: RenderLoopConfig) => Effect.Effect<void>;
|
|
27
|
+
//# sourceMappingURL=renderLoop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderLoop.d.ts","sourceRoot":"","sources":["../../src/runtime/renderLoop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,eAAe,EAAE,MAAM,QAAQ,CAAA;AAExD,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC;sEACkE;IAClE,UAAU,EAAE,eAAe,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IACpD,8DAA8D;IAC9D,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACnC;mFAC+E;IAC/E,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAChC,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CAC5B,CAAC,CAAA;AAEF;;;;;;;;;;;qDAWqD;AACrD,eAAO,MAAM,cAAc,GAAI,mDAK5B,gBAAgB,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAgBvC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Effect, Stream, SubscriptionRef } from 'effect';
|
|
2
|
+
/** Builds an idle-suspending render loop driven by a SubscriptionRef of
|
|
3
|
+
* "render is pending."
|
|
4
|
+
*
|
|
5
|
+
* The loop subscribes to the ref's changes Stream and runs the body once per
|
|
6
|
+
* false-to-true transition. Stream.changes filters consecutive equals so a
|
|
7
|
+
* burst of `set(true)` calls inside one frame produces a single body run.
|
|
8
|
+
*
|
|
9
|
+
* The body waits for the next animation frame, clears the dirty bit, then
|
|
10
|
+
* renders if not paused. The bit is cleared on every body run (including
|
|
11
|
+
* paused early-returns) so the next dispatch is always a real false-to-true
|
|
12
|
+
* transition. This makes the loop self-recovering even when paused state
|
|
13
|
+
* flips externally without a synchronous render. */
|
|
14
|
+
export const makeRenderLoop = ({ pendingRef, awaitNextFrame, isPaused, render, }) => {
|
|
15
|
+
const tick = Effect.gen(function* () {
|
|
16
|
+
yield* awaitNextFrame;
|
|
17
|
+
yield* SubscriptionRef.set(pendingRef, false);
|
|
18
|
+
const paused = yield* isPaused;
|
|
19
|
+
if (paused) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
yield* render;
|
|
23
|
+
});
|
|
24
|
+
return SubscriptionRef.changes(pendingRef).pipe(Stream.changes, Stream.filter(isPending => isPending), Stream.runForEach(() => tick));
|
|
25
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,OAAO,EACP,MAAM,EAGN,KAAK,EAEL,MAAM,EAON,MAAM,EAIP,MAAM,QAAQ,CAAA;AAGf,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAIlD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,GAAG,EAA+B,MAAM,iBAAiB,CAAA;AAalE,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,OAAO,EACP,MAAM,EAGN,KAAK,EAEL,MAAM,EAON,MAAM,EAIP,MAAM,QAAQ,CAAA;AAGf,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAIlD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,GAAG,EAA+B,MAAM,iBAAiB,CAAA;AAalE,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAO5C,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,YAAY,GACZ,UAAU,GACV,SAAS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,EACP,aAAa,EACb,KAAK,EACL,SAAS,EACT,uBAAuB,CACxB,GACA,iBAAiB,CAAA;AAEpB,wBAAgB,WAAW,CACzB,KAAK,EACL,OAAO,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAChC,aAAa,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EACzD,SAAS,GAAG,KAAK,EACjB,uBAAuB,GAAG,KAAK,EAE/B,MAAM,EAAE,aAAa,CACnB,KAAK,EACL,OAAO,EACP,aAAa,EACb,SAAS,EACT,uBAAuB,CACxB,GACA,iBAAiB,CAAA;AAqNpB,kEAAkE;AAClE,eAAO,MAAM,GAAG,GAAI,SAAS,iBAAiB,KAAG,IA4ChD,CAAA"}
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -11,6 +11,7 @@ import { defaultCrashView, noOpDispatch } from './crashUI.js';
|
|
|
11
11
|
import { deepFreeze } from './deepFreeze.js';
|
|
12
12
|
import { PreserveModelMessage, RequestModelMessage, RestoreModelMessage, } from './hmrProtocol.js';
|
|
13
13
|
import { orderByPriority } from './messagePriority.js';
|
|
14
|
+
import { makeRenderLoop } from './renderLoop.js';
|
|
14
15
|
const DEFAULT_DEV_TOOLS_SHOW = 'Development';
|
|
15
16
|
const DEFAULT_DEV_TOOLS_POSITION = 'BottomRight';
|
|
16
17
|
const DEFAULT_DEV_TOOLS_MODE = 'TimeTravel';
|
|
@@ -246,27 +247,16 @@ const makeRuntime = ({ Model, flags: resolveFlags, init, update, view, subscript
|
|
|
246
247
|
// view past threshold. Acceptable for a debug callback; full
|
|
247
248
|
// attribution would require correlating each message with its render
|
|
248
249
|
// contribution, which isn't worth the complexity.
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
yield* render(model, maybeMessage);
|
|
250
|
+
const renderLoop = makeRenderLoop({
|
|
251
|
+
pendingRef: isRenderPendingRef,
|
|
252
|
+
awaitNextFrame,
|
|
253
|
+
isPaused: isPausedEffect,
|
|
254
|
+
render: Effect.gen(function* () {
|
|
255
|
+
const model = yield* Ref.get(modelRef);
|
|
256
|
+
const maybeMessage = yield* Ref.get(lastDirtyMessageRef);
|
|
257
|
+
yield* render(model, maybeMessage);
|
|
258
|
+
}),
|
|
259
259
|
});
|
|
260
|
-
// NOTE: The loop suspends on the SubscriptionRef's changes Stream when
|
|
261
|
-
// isRenderPending stays false, so an idle app schedules zero rAF
|
|
262
|
-
// callbacks. Stream.changes filters consecutive equals so multiple
|
|
263
|
-
// dispatches inside one frame produce a single render. The bit is
|
|
264
|
-
// cleared on every body run, including the paused early-return, so
|
|
265
|
-
// any future false-to-true transition wakes the loop again. This
|
|
266
|
-
// self-recovery covers indirect unpause paths in the DevTools store
|
|
267
|
-
// (rolling-buffer eviction past pausedAtIndex, and the clear action)
|
|
268
|
-
// that bypass bridge.render.
|
|
269
|
-
const renderLoop = SubscriptionRef.changes(isRenderPendingRef).pipe(Stream.changes, Stream.filter(isPending => isPending), Stream.runForEach(() => renderAtNextFrame));
|
|
270
260
|
yield* Effect.forkDetach(renderLoop);
|
|
271
261
|
addBfcacheRestoreListener();
|
|
272
262
|
if (subscriptions) {
|
|
@@ -333,8 +323,23 @@ const makeRuntime = ({ Model, flags: resolveFlags, init, update, view, subscript
|
|
|
333
323
|
const processBatch = (batch) => Effect.forEach(orderByPriority(batch), processWithBudget, {
|
|
334
324
|
discard: true,
|
|
335
325
|
});
|
|
326
|
+
// NOTE: Effect 4's `Queue.takeAll` blocks until at least one message
|
|
327
|
+
// arrives (it's `takeBetween(self, 1, ∞)`, not a non-blocking
|
|
328
|
+
// snapshot). For batching we want "give me whatever is currently in
|
|
329
|
+
// the queue, possibly nothing" so we drain via repeated `Queue.poll`
|
|
330
|
+
// until it returns `None`.
|
|
331
|
+
const pollAvailable = Effect.gen(function* () {
|
|
332
|
+
const accumulated = [];
|
|
333
|
+
while (true) {
|
|
334
|
+
const next = yield* Queue.poll(messageQueue);
|
|
335
|
+
if (Option.isNone(next)) {
|
|
336
|
+
return accumulated;
|
|
337
|
+
}
|
|
338
|
+
accumulated.push(next.value);
|
|
339
|
+
}
|
|
340
|
+
});
|
|
336
341
|
const drainQueue = Effect.gen(function* () {
|
|
337
|
-
const batch = yield*
|
|
342
|
+
const batch = yield* pollAvailable;
|
|
338
343
|
if (Array.isReadonlyArrayEmpty(batch)) {
|
|
339
344
|
return;
|
|
340
345
|
}
|
|
@@ -343,7 +348,7 @@ const makeRuntime = ({ Model, flags: resolveFlags, init, update, view, subscript
|
|
|
343
348
|
});
|
|
344
349
|
yield* pipe(Effect.forever(Effect.gen(function* () {
|
|
345
350
|
const first = yield* Queue.take(messageQueue);
|
|
346
|
-
const rest = yield*
|
|
351
|
+
const rest = yield* pollAvailable;
|
|
347
352
|
yield* Ref.set(burstStartedAtRef, performance.now());
|
|
348
353
|
yield* processBatch(Array.prepend(rest, first));
|
|
349
354
|
yield* drainQueue;
|