Improved the readability of the all operator as well as added memory …#98
Conversation
📝 WalkthroughWalkthroughReimplements all(...) to iterate a bounded iterable directly, track per-inner first-value and active subscriptions, buffer and snapshot values with Object.is checks, handle empty and aborted cases, add tests for undefined aggregation and empty inputs, and bump package version to 0.20.0. ChangesCore all(...) Operator Refactor
Sequence Diagram(s)sequenceDiagram
participant Subscriber
participant all_op as all(...)
participant Inner as InnerObservable
participant Observer
Subscriber->>all_op: subscribe(iterable of InnerObservable)
all_op->>Inner: subscribe each inner from BoundedIterable
Inner->>all_op: emit first value / subsequent next
all_op->>all_op: increment receivedFirstValueCount, update buffer snapshot (Object.is check)
all_op->>Observer: emit frozen snapshot when all first values received
Inner->>all_op: complete -> finalize -> decrement activeInnerSubscriptions
all_op->>Observer: complete when all inner completed
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@all/mod.test.ts`:
- Line 2: The import of Observable in all/mod.test.ts is treated as a runtime
value but is only used in type positions (Observable at lines referencing its
type and Observer), so change the import to a type-only import: replace the
current import of Observable (and Observer if it’s only used as a type) with an
"import type" form to satisfy Deno's verbatim-module-syntax; locate the import
statement that currently reads "import { Observable, Observer } from
'`@observable/core`'" and update it to import type for the symbols used only as
types while leaving any runtime imports untouched.
In `@all/mod.ts`:
- Around line 203-208: The current Object.is(buffer[indexSnapshot], value) check
skips storing the first undefined because sparse buffer slots read as undefined;
instead add per-index receipt tracking (e.g., a boolean array like hasValue) and
use that to decide updates: only treat values as "unchanged" when
hasValue[indexSnapshot] is true and Object.is(buffer[indexSnapshot], value) is
true; otherwise assign buffer[indexSnapshot] = value, set
hasValue[indexSnapshot] = true, and reset snapshot = undefined. Ensure hasValue
is initialized alongside buffer and updated wherever values are written.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ceb265bc-e442-4d09-922a-5f821c539f63
📒 Files selected for processing (3)
all/deno.jsonall/mod.test.tsall/mod.ts
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@all/mod.ts`:
- Around line 233-236: The bound() function must snapshot mutable inputs and
return a frozen BoundedIterable: instead of returning the original Set or an
unfrozen literal, create an immutable snapshot array (use value instanceof Set ?
Array.from(value) : Array.isArray(value) ? value.slice() : Array.from(value)),
build the iterable whose [Symbol.iterator]() iterates over that snapshot and
whose size is snapshot.length, then wrap the returned object with
Object.freeze(...) before returning; update references to the bound function and
BoundedIterable to use this frozen snapshot so live iterator mutations cannot
desynchronize counts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d9652af9-794a-4b3a-bd4f-3ea32d9dfc58
📒 Files selected for processing (2)
all/mod.test.tsall/mod.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- all/mod.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
all/mod.test.ts (1)
129-129: ⚡ Quick winConsider explicit type parameter for consistency.
Line 129 uses
Set<Observable>()while line 138 usesObservable<unknown>. For consistency and explicitness, consider using the full type annotation.♻️ Suggested change for consistency
- const observable = all(new Set<Observable>()); + const observable = all(new Set<Observable<unknown>>());🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@all/mod.test.ts` at line 129, Change the ambiguous generic usage to an explicit unknown type for consistency: update the call site using all and the Set instantiation so they reference Observable<unknown> (e.g., construct new Set<Observable<unknown>>() and/or call all<unknown>(...) ), ensuring both the Set and the all invocation use the Observable<unknown> type instead of bare Observable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@all/mod.test.ts`:
- Line 129: Change the ambiguous generic usage to an explicit unknown type for
consistency: update the call site using all and the Set instantiation so they
reference Observable<unknown> (e.g., construct new Set<Observable<unknown>>()
and/or call all<unknown>(...) ), ensuring both the Set and the all invocation
use the Observable<unknown> type instead of bare Observable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7503fe3c-3db3-4b7e-9f1c-48a6360c11e9
📒 Files selected for processing (3)
all/deno.jsonall/mod.test.tsall/mod.ts
…optimizations.
Summary by CodeRabbit
Chores
Tests
Refactor