Skip to content

Commit

Permalink
Not logging restore sources
Browse files Browse the repository at this point in the history
  • Loading branch information
soxtoby committed Mar 24, 2024
1 parent cc92159 commit 63418eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 11 additions & 8 deletions packages/event-reduce/src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sendEvent } from "./devtools";
import { IObservable, Observable } from "./observable";
import { RestoreSubject } from "./reduction";

let loggingEnabled = false;

Expand Down Expand Up @@ -89,14 +90,16 @@ export interface ISourceInfo {

export function sourceTree(sources: readonly IObservable<any>[]): ISourceInfo[] {
if (process.env.NODE_ENV !== 'production')
return sources.map(s => {
let source = new WeakRef(s);
return {
name: s.displayName,
sources: (s as Observable<any>).sourceInfo,
get observable() { return source.deref() ?? "No longer in memory"; }
}
});
return sources
.filter(s => !(s instanceof RestoreSubject)) // Since every reduction has a restore source, this is just noise
.map(s => {
let source = new WeakRef(s);
return {
name: s.displayName,
sources: (s as Observable<any>).sourceInfo,
get observable() { return source.deref() ?? "No longer in memory"; }
}
});
else
return [];
}
4 changes: 3 additions & 1 deletion packages/event-reduce/src/reduction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface IBoundReduction<T, TEvents> extends IReduction<T> {

export class Reduction<T> extends ObservableValue<T> implements IReduction<T> {
private _sources = new Map<IObservable<any>, Unsubscribe>();
private _restore = new Subject<State<T>>(() => `${this.displayName}.restored`);
private _restore = new RestoreSubject<State<T>>(() => `${this.displayName}.restored`);

constructor(getDisplayName: () => string, initial: T) {
super(getDisplayName, initial);
Expand Down Expand Up @@ -103,6 +103,8 @@ class BoundReduction<TValue, TEvents> extends Reduction<TValue> implements IBoun
}
}

export class RestoreSubject<T> extends Subject<T> { }

export class CircularSubscriptionError extends Error {
constructor(
public reduction: IReduction<unknown>,
Expand Down

0 comments on commit 63418eb

Please sign in to comment.