| @@ -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,26 +97,29 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 }) => { | 
| 
             | 
        106 | const result = store.get(id); | |
| 
             | 
        104 | try { | |
| 
             | 
        105 | const result = store.get(id); | |
| 
             | 
        107 | 106 | |
| 
             | 
        108 | const handle = (x: T | null | undefined) => { | |
| 
             | 
        109 | if (x !== null && x !== undefined) | |
| 
             | 
        110 | next(x); | |
| 
             | 
        111 | complete(); | |
| 
             | 
        112 | }; | |
| 
             | 
        107 | const handle = (x: T | null | undefined) => { | |
| 
             | 
        108 | if (x !== null && x !== undefined) | |
| 
             | 
        109 | next(x); | |
| 
             | 
        110 | complete(); | |
| 
             | 
        111 | }; | |
| 
             | 
        113 | 112 | |
| 
             | 
        114 | if (isPromise(result)) { | |
| 
             | 
        115 | result.then(handle, error); | |
| 
             | 
        113 | if (isPromise(result)) { | |
| 
             | 
        114 | result.then(handle).then(undefined, error); | |
| 
             | 
        116 | 115 | |
| 
             | 
        117 | if (isCancellable(result)) | |
| 
             | 
        118 | return () => result.cancel(); | |
| 
             | 
        119 | } else { | |
| 
             | 
        120 | handle(result); | |
| 
             | 
        116 | if (isCancellable(result)) | |
| 
             | 
        117 | return () => result.cancel(); | |
| 
             | 
        118 | } else { | |
| 
             | 
        119 | handle(result); | |
| 
             | 
        120 | } | |
| 
             | 
        121 | } catch (e) { | |
| 
             | 
        122 | error(e); | |
| 
             | 
        121 | 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
                    
                