@@ -1,7 +1,11 | |||
|
1 | import { id as mid} from "module"; | |
|
1 | 2 | import { Cancellation } from "@implab/core-amd/Cancellation"; |
|
2 | 3 | import { ICancellation } from "@implab/core-amd/interfaces"; |
|
4 | import { TraceSource } from "@implab/core-amd/log/TraceSource"; | |
|
3 | 5 | import { isPromise } from "@implab/core-amd/safe"; |
|
4 | 6 | |
|
7 | const trace = TraceSource.get(mid); | |
|
8 | ||
|
5 | 9 | /** |
|
6 | 10 | * The interface for the consumer of an observable sequence |
|
7 | 11 | */ |
@@ -148,11 +152,13 export interface Observable<T> extends S | |||
|
148 | 152 | |
|
149 | 153 | const noop = () => { }; |
|
150 | 154 | |
|
155 | const errorFallback = (e: unknown) => trace.error("Unhandled observable error: {0}", e); | |
|
156 | ||
|
151 | 157 | const sink = <T>(consumer: Observer<T>) => { |
|
152 | 158 | const { next, error, complete } = consumer; |
|
153 | 159 | return { |
|
154 | 160 | next: next ? next.bind(consumer) : noop, |
|
155 |
error: error ? error.bind(consumer) : |
|
|
161 | error: error ? error.bind(consumer) : errorFallback, | |
|
156 | 162 | complete: complete ? complete.bind(consumer) : noop, |
|
157 | 163 | isClosed: () => false |
|
158 | 164 | }; |
@@ -2,7 +2,6 import { PromiseOrValue } from "@implab/ | |||
|
2 | 2 | import { isCancellable, isPromise } from "@implab/core-amd/safe"; |
|
3 | 3 | import { observe, Observable, empty } from "./observable"; |
|
4 | 4 | import { after } from "dojo/aspect"; |
|
5 | import { subject } from "./operators/subject"; | |
|
6 | 5 | |
|
7 | 6 | export interface OrderedUpdate<T> { |
|
8 | 7 | /** The item is being updated */ |
@@ -98,11 +97,11 export const get = <T>(store: IndexedSto | |||
|
98 | 97 | observe<Change<T>>(({ next }) => { |
|
99 | 98 | const handle = after(store, "notify", (...args: Change<T>) => next(args), true); |
|
100 | 99 | return () => handle.remove(); |
|
101 |
} |
|
|
102 | ||
|
100 | }) : empty; | |
|
103 | 101 | |
|
104 | 102 | return (id: string | number, opts: GetOpts = {}) => |
|
105 | 103 | observe<T>(({ next, complete, error }) => { |
|
104 | try { | |
|
106 | 105 | const result = store.get(id); |
|
107 | 106 | |
|
108 | 107 | const handle = (x: T | null | undefined) => { |
@@ -112,12 +111,15 export const get = <T>(store: IndexedSto | |||
|
112 | 111 | }; |
|
113 | 112 | |
|
114 | 113 | if (isPromise(result)) { |
|
115 | result.then(handle, error); | |
|
114 | result.then(handle).then(undefined, error); | |
|
116 | 115 | |
|
117 | 116 | if (isCancellable(result)) |
|
118 | 117 | return () => result.cancel(); |
|
119 | 118 | } else { |
|
120 | 119 | handle(result); |
|
121 | 120 | } |
|
121 | } catch (e) { | |
|
122 | error(e); | |
|
123 | } | |
|
122 | 124 | }).cat(opts.observe !== false ? changes.pipe(filterItem(id)) : empty); |
|
123 | 125 | }; No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now