Skip to content

Commit 43f714c

Browse files
committedNov 25, 2019
track sub-state backflow subs
1 parent fcdd20c commit 43f714c

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed
 

‎src/agent/keyed-deep.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PinLike } from "../pin/pin-like";
1212

1313
import { SimpleDeep, DeepAccessor, DeepChildFactory } from "./simple-deep";
1414
import { State, EqualityFunc } from "./state";
15+
import { TrackCallback } from "../shared/types";
1516

1617

1718
/**
@@ -79,7 +80,7 @@ export class KeyedDeep extends SimpleDeep {
7980
}
8081
} catch (err) {}
8182
}),
82-
bind() { return this.set.subscribe(); },
83+
bind(track: TrackCallback) { return track(this.set.subscribe()); },
8384
}, this.state.compare);
8485
}
8586

‎src/agent/simple-deep.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import createRandomTag from "../util/random-tag";
22
import { emission } from "../shared/emission";
3+
import { TrackCallback } from "../shared/types";
34

45
import { map } from "../pin/map";
56
import { sink } from "../pin/sink";
@@ -17,7 +18,7 @@ export interface DeepAccessor {
1718
initial: any;
1819
set: PinLike;
1920
get: PinLike;
20-
bind(): void;
21+
bind(track: TrackCallback): void;
2122
}
2223

2324

@@ -116,7 +117,7 @@ export class SimpleDeep extends Agent {
116117
}
117118
} catch(_) {}
118119
}),
119-
bind() { return this.set.subscribe(); },
120+
bind(track: TrackCallback) { return track(this.set.subscribe()); },
120121
}, this.state.compare);
121122
}
122123

@@ -161,7 +162,7 @@ export class SimpleDeep extends Agent {
161162
*/
162163
bind() {
163164
if (!this.bound) {
164-
if (this.accessor) this.accessor.bind();
165+
if (this.accessor) this.accessor.bind(sub => this.track(sub));
165166
else this.track(this.output.subscribe());
166167
this.bound = true;
167168
}

‎src/shared/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { Subscription } from "rxjs";
2+
13
export type ErrorCallback = (error: Error | string) => void;
24
export type ResolveCallback<T> = (value: T) => void;
35
export type NotifyCallback = () => void;
46
export type ContextType = {[keys: string]: any};
7+
export type TrackCallback = (sub: Subscription) => void;

0 commit comments

Comments
 (0)
Failed to load comments.