当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.trigger方法代码示例

本文整理汇总了TypeScript中src/observer/Observable.Observable.trigger方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.trigger方法的具体用法?TypeScript Observable.trigger怎么用?TypeScript Observable.trigger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在src/observer/Observable.Observable的用法示例。


在下文中一共展示了Observable.trigger方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

    it('Should be able to unregister all listeners to a specific event', (): void => {
        let count1: number = 0;
        let count2: number = 0;

        const listener1: Function = (): void => {
            count1 += 1;
        };

        const listener2: Function = (): void => {
            count2 += 1;
        };

        o.on('change', listener1);
        o.on('change', listener2);

        expect(count1).toBe(0);
        expect(count2).toBe(0);

        o.trigger('change');
        expect(count1).toBe(1);
        expect(count2).toBe(1);

        o.off('change');

        o.trigger('change');
        expect(count1).toBe(1);
        expect(count2).toBe(1);
    });
开发者ID:joppe,项目名称:aap,代码行数:28,代码来源:Observable.spec.ts

示例2: Observable

export const watcher: IWatcher = ((): IWatcher => {
    const observable: Observable = new Observable();
    let count: number = 0;
    let invoked: IWatchableRegistry = {};

    return {
        /**
         * Register a key.
         *
         * @param {string} key
         * @returns {IWatchable}
         */
        register(key: string): IWatchable {
            count += 1;

            return {
                identifier: `observable-${count}-${key}`,
                key
            };
        },

        /**
         * @param {IWatchable} watchable
         */
        invoke(watchable: IWatchable): void {
            invoked[watchable.identifier] = watchable;
        },

        /**
         * Trigger a change.
         *
         * @param {IWatchable} watchable
         */
        trigger(watchable: IWatchable): void {
            observable.trigger(`change:${watchable.identifier}`);
        },

        /**
         * @param {IWatchable} watchable
         * @param {Function} callback
         */
        listen(watchable: IWatchable, callback: Function): void {
            observable.on(`change:${watchable.identifier}`, callback);
        },

        /**
         * @param {Function} callback
         * @returns {IWatchableRegistry}
         */
        capture(callback: Function): {[id: string]: IWatchable} {
            invoked = {};

            callback();

            return invoked;
        }
    };
})();
开发者ID:joppe,项目名称:aap,代码行数:58,代码来源:watcher.ts

示例3: it

    it('Should unregister a specific listener with "stopListening"', (): void => {
        let count: number = 0;
        const increment1: Function = (): void => {
            count += 1;
        };
        const increment10: Function = (): void => {
            count += 10;
        };

        observer.listenTo(observable, 'inc', increment1);
        observer.listenTo(observable, 'inc', increment10);

        observable.trigger('inc');
        expect(count).toBe(11);

        observer.stopListening(observable, 'inc', increment10);
        observable.trigger('inc');
        expect(count).toBe(12);
    });
开发者ID:joppe,项目名称:aap,代码行数:19,代码来源:Observer.spec.ts


注:本文中的src/observer/Observable.Observable.trigger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。