當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript CompositeDisposable.add方法代碼示例

本文整理匯總了TypeScript中rx.CompositeDisposable.add方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CompositeDisposable.add方法的具體用法?TypeScript CompositeDisposable.add怎麽用?TypeScript CompositeDisposable.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rx.CompositeDisposable的用法示例。


在下文中一共展示了CompositeDisposable.add方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: createConnection

	private createConnection(socket: SocketImpl, sessionId: string) {
		const disposable = new CompositeDisposable();
		const conn = new MessageConnection(socket);
		let handler: ConnectionHandler = null;
		this.diposable_.add(disposable);

		[	conn.onMessage().subscribeOnNext((x) => {
				handler.onMessage(x);
			}),
			conn.onClose().subscribeOnNext(() => {
				this.destroyConnection(conn);
			}),
			conn.onError().subscribeOnNext((err) => {
				this.destroyConnection(conn);
			})
		].forEach(x => { disposable.add(x) });

		handler = this.app_.createConnectionHandler(conn, sessionId);

		this.connections_.push({
			connection: conn,
			handler: handler,
			disposable: disposable,
			sessionId: sessionId
		});
	}
開發者ID:omochi,項目名稱:national-economy,代碼行數:26,代碼來源:Engine.ts

示例2: spawn

        bag.add(s1.subscribeOnCompleted(() => {
          if (start) {
            let s2: Observable<string>;

            if (readyActionObservables) {
              s2 = Observable
                .merge
                .apply(null, readyActionObservables)
                .startWith(null)
                .flatMapLatest(() => spawn(start));
            } else {
              s2 = spawn(start);
            }

            let d: Disposable;

            if (match) {
              d = s2.subscribeOnNext((val) => {
                const action = match(val);
                if (action) {
                  observer.onNext(action);
                }
              });
            } else {
              d = s2.subscribe(() => {});
            }

            bag.add(d);
          } else { // "process"
            input = new EventEmitter();
            output = new EventEmitter();

            output.on('action', (obj: Object) => {
              observer.onNext(obj);
            });

            process(input, output);

            const d = Observable.merge.apply(null, connectables)
              .subscribeOnNext((action: Object) => input.emit('action', action));

            bag.add(d);
          }
        }));
開發者ID:d6u,項目名稱:dev-runner,代碼行數:44,代碼來源:utils.ts

示例3: setupState

    private setupState() {
        this._disposable.add(Omni.activeModel
            .subscribe(newModel => {
                // Update on change
                _.each(statefulProperties, property => { this[property] = newModel[property] });
            }));

        this._disposable.add(Omni.activeModel
            .flatMapLatest(newModel =>
                newModel.observe.updates// Track changes to the model
                    .buffer(newModel.observe.updates.throttle(100), () => Observable.timer(100)) // Group the changes so that we capture all the differences at once.
                    .map(items => _.filter(items, item => _.contains(statefulProperties, item.name)))
                    .where(z => z.length > 0)
                    .map(items => ({ items, newModel })))
            .subscribe(ctx => {
                var {items, newModel} = ctx;
                // Apply the updates if found
                _.each(items, item => {
                    this[item.name] = newModel[item.name];
                })
            }));
    }
開發者ID:RichiCoder1,項目名稱:omnisharp-atom,代碼行數:22,代碼來源:world.ts

示例4: constructor

	constructor(socket: Socket) {
		this.socket_ = socket;
		this.disposable_ = new CompositeDisposable();
		this.onMessage_ = new Subject<Message>();
		this.onClose_ = new Subject<void>();
		this.onError_ = new Subject<Error>();
		this.messageDecoder_ = new MessageDecoder();

		let sub: Disposable = null;

		sub = this.socket_.onMessage().subscribeOnNext((message: SocketMessage) => {
			if (message.string != null) {
				try {
					const json = Json.parse(message.string);
					const msg = this.messageDecoder_.decode(json);
					this.onMessage_.onNext(msg);
				} catch (e) {
					this.handleError(toError(e));
				}
			} else {
				this.handleError(new Error(`invalid message`));
			}
		});
		this.disposable_.add(sub);

		sub = this.socket_.onClose().subscribeOnNext((_: void) => {
			this.onClose_.onNext(null);
			this.close();
		});
		this.disposable_.add(sub);

		sub = this.socket_.onError().subscribeOnNext((error: Error) => {
			this.handleError(error);
		});
		this.disposable_.add(sub);
	}
開發者ID:omochi,項目名稱:national-economy,代碼行數:36,代碼來源:Message.ts

示例5: it

    it("formats code", () => {
        const d = restoreBuffers();
        const disposable = new CompositeDisposable();
        disposable.add(d);

        let tries = 5;
        return atom.workspace.open("simple/code-format/UnformattedClass.cs")
            .then((editor) => {
                return execute(editor);
            });

        function execute(editor: Atom.TextEditor): any {
            const promise = Omni.listener.formatRange
                .take(1)
                .toPromise()
                .then(({request}) => {
                    expect(editor.getPath()).to.be.eql(request.FileName);
                    const expected = `public class UnformattedClass{    public const int TheAnswer = 42;}`;
                    const result = editor.getText().replace(/\r|\n/g, "");
                    try {
                        expect(result).to.contain(expected);
                        tries = 0;
                    } catch (e) {
                        if (tries > 0) {
                            return execute(editor);
                        } else {
                            tries = -1;
                            throw e;
                        }
                    } finally {
                        if (tries === -1) {
                            disposable.dispose();
                            throw new Error("Failed!");
                        } else if (tries === 0) {
                            disposable.dispose();
                        }
                        tries--;
                    }
                });
            codeFormat.format();
            return promise;
        }
    });
開發者ID:Coohack,項目名稱:omnisharp-atom,代碼行數:43,代碼來源:code-format-spec.ts

示例6: it

    it('formats code', () => {
        var d = restoreBuffers();
        var disposable = new CompositeDisposable();
        disposable.add(d);
        var e: Atom.TextEditor;
        var request: OmniSharp.Models.FormatRangeRequest;
        var response: OmniSharp.Models.FormatRangeResponse;

        var responsePromise = Omni.listener.observeFormatRange
            .tapOnNext(r => request = r.request)
            .tapOnNext(r => response = r.response)
            .take(1)
            .toPromise();

        waitsForPromise(() => atom.workspace.open('simple/code-format/UnformattedClass.cs')
            .then((editor) => {
                e = editor;
                codeFormat.format();

                var observable = Omni.listener.observeFormatRange
                    .tapOnNext(r =>
                        request = r.request)
                    .take(1)
                    .delay(400);

                return observable.toPromise();
            }));

        runs(() => {
            expect(e.getPath()).toEqual(request.FileName);
            var expected = `public class UnformattedClass
{
    public const int TheAnswer = 42;
}
`.replace(/\r|\n/g, '');
            var result = e.getText().replace(/\r|\n/g, '');
            expect(result).toContain(expected);
            disposable.dispose();
        });
    });
開發者ID:RichiCoder1,項目名稱:omnisharp-atom,代碼行數:40,代碼來源:code-format-spec.ts

示例7: matchEvents

      return Observable.create((observer: Observer<Object>) => {
        const match = events ? matchEvents(events) : null;
        const bag = new CompositeDisposable();
        const observerables: Observable<any>[] = values(tasks);

        let s1: Observable<any>;
        let connectables: ConnectableObservable<any>[];
        let readyActionObservables: Observable<{type: 'ready'}>[];

        if (observerables.length) {
          connectables = observerables.map((s) => s.publish());
          readyActionObservables =
            connectables.map((s) => s.filter(propEq('type', 'ready')));

          const allParentsReady: Observable<{type: 'ready'}[]> =
            Observable.combineLatest.apply(null, readyActionObservables).take(1);

          s1 = allParentsReady;
        } else {
          s1 = Observable.just(null);
        }

        if (preStart) {
          s1 = s1.flatMap(() => spawn(preStart));

          if (match) {
            s1 = s1.doOnNext((val: string) => {
              const action = match(val);
              if (action) {
                observer.onNext(action);
              }
            });
          }
        }

        let input: EventEmitter;
        let output: EventEmitter;

        bag.add(s1.subscribeOnCompleted(() => {
          if (start) {
            let s2: Observable<string>;

            if (readyActionObservables) {
              s2 = Observable
                .merge
                .apply(null, readyActionObservables)
                .startWith(null)
                .flatMapLatest(() => spawn(start));
            } else {
              s2 = spawn(start);
            }

            let d: Disposable;

            if (match) {
              d = s2.subscribeOnNext((val) => {
                const action = match(val);
                if (action) {
                  observer.onNext(action);
                }
              });
            } else {
              d = s2.subscribe(() => {});
            }

            bag.add(d);
          } else { // "process"
            input = new EventEmitter();
            output = new EventEmitter();

            output.on('action', (obj: Object) => {
              observer.onNext(obj);
            });

            process(input, output);

            const d = Observable.merge.apply(null, connectables)
              .subscribeOnNext((action: Object) => input.emit('action', action));

            bag.add(d);
          }
        }));

        if (connectables) {
          connectables.forEach((s) => bag.add(s.connect()));
        }

        return () => {
          bag.dispose();
          if (input) {
            input.removeAllListeners();
          }
          if (output) {
            output.removeAllListeners();
          }
        };
      });
開發者ID:d6u,項目名稱:dev-runner,代碼行數:97,代碼來源:utils.ts

示例8:

 connectables.forEach((s) => bag.add(s.connect()));
開發者ID:d6u,項目名稱:dev-runner,代碼行數:1,代碼來源:utils.ts

示例9:

		].forEach(x => { this.disposable_.add(x); });
開發者ID:omochi,項目名稱:national-economy,代碼行數:1,代碼來源:Engine.ts


注:本文中的rx.CompositeDisposable.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。