• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript mobx.observable函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中mobx.observable函数的典型用法代码示例。如果您正苦于以下问题:TypeScript observable函数的具体用法?TypeScript observable怎么用?TypeScript observable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: observable

export function model<TState, TTargets>(
    template: IModelTemplate<TState>, 
    options?: IModelOptions): IModel<TState, TTargets> {
        
    options = options || { key: 'model' };
    const state = observable(Object.assign({}, template.state));
    
    const services = Object.assign({}, defaultServices, options.services);
    
    const result = Object.assign({ 
        key: options.key,
        state, 
        targets: null,
        template,
        services,
    }, template.extensions);
    
    if (template.actions || options.actions) {
        result.targets = actionsToTargets(result, Object.assign({}, template.actions, options.actions));
    }        
    
    if (template.inputs) {        
        const inputs = template.inputs(result, services);
        result.outputs = inputs;
        result.targets = Object.assign(result.targets, inputToTargets(inputs));
    }
    
    if (template.init) {
        template.init(result, template);
    }
    
    return result;
}
开发者ID:pvasek,项目名称:mobx-app-model,代码行数:33,代码来源:model.ts


示例2: it

    it('handles nested undo windows called out of order', () => {
        let array = observable([1, 2, 3, 4, 5]);

        let innerUndo: Function;
        let outerUndo = createUndo('outerUndo')(
            action('outerUndo')(() => {
                array[0] = 0;

                expect(array.slice(0)).toEqual([0, 2, 3, 4, 5]);

                innerUndo = createUndo('innerUndo')(
                    action('innerUndo')(() => {
                        array[1] = 0;
                    })
                );

                array[2] = 0;

                expect(array.slice(0)).toEqual([0, 0, 0, 4, 5]);
            })
        );

        outerUndo();

        expect(array.slice(0)).toEqual([1, 2, 3, 4, 5]);

        innerUndo && innerUndo();

        expect(array.slice(0)).toEqual([1, 2, 3, 4, 5]);
    });
开发者ID:Microsoft,项目名称:satcheljs,代码行数:30,代码来源:createUndoTests.ts


示例3: observable

export function makeValidator<T extends Rules>(rules: T) {
    type Errors = Partial<{ [ruleName in keyof T]: string[] }>;

    const self = observable({
        errors: {} as Errors,

        checkValidity(object: any) {
            return new Promise<boolean>(resolve => {
                let isValid = true;
                let errors = {} as Errors;

                let promises: Promise<void>[] = [];

                function setError(ruleName: string, error: string | null) {
                    if (error !== null) {
                        isValid = false;
                        const existingError = errors[ruleName];
                        if (existingError) {
                            existingError.push(error);
                        } else {
                            errors[ruleName] = [error] as any;
                        }
                    }
                }

                function checkRule(ruleName: string, rule: Rule) {
                    const error = rule(object, ruleName);
                    if (error instanceof Promise) {
                        promises.push(
                            new Promise(resolve => {
                                error.then(error => {
                                    setError(ruleName, error);
                                    resolve();
                                });
                            })
                        );
                    } else {
                        setError(ruleName, error);
                    }
                }

                Object.keys(rules).forEach(ruleName => {
                    const rule = rules[ruleName];
                    if (Array.isArray(rule)) {
                        rule.forEach(rule => checkRule(ruleName, rule));
                    } else {
                        checkRule(ruleName, rule);
                    }
                });

                Promise.all(promises).then(() => {
                    runInAction(() => (self.errors = errors));
                    resolve(isValid);
                });
            });
        }
    });

    return self;
}
开发者ID:eez-open,项目名称:studio,代码行数:60,代码来源:validation.ts


示例4: test

test("it should support observable arrays", t => {
    const TestArray = types.array(types.number)
    const testArray = TestArray.create(observable([1, 2]))
    t.true(testArray[0] === 1)
    t.true(testArray.length === 2)
    t.true(Array.isArray(testArray.slice()))
})
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:7,代码来源:array.ts


示例5: initDriverAnnotationSettings

export function initDriverAnnotationSettings(store:OncoprinterStore) {
    return observable({
        cbioportalCount: false,
        cbioportalCountThreshold: 0,
        _oncoKb:true,
        _ignoreUnknown: false,
        hotspots: false, // for now

        set oncoKb(val:boolean) {
            this._oncoKb = val;
        },
        get oncoKb() {
            return AppConfig.serverConfig.show_oncokb && this._oncoKb && !store.didOncoKbFail;
        },
        set ignoreUnknown(val:boolean) {
            this._ignoreUnknown = val;
        },
        get ignoreUnknown() {
            return this._ignoreUnknown && this.driversAnnotated;
        },
        get driversAnnotated() {
            const anySelected = this.oncoKb ||
                this.cbioportalCount || this.hotspots;

            return anySelected;
        }
    });
}
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:28,代码来源:OncoprinterUtils.ts


示例6: it

    it('executes immediately if the promise is already resolved, does not execute again', (done)=>{

        let handlerInvokeCount = 0;
        let promiseResult = observable(0);
        let lastInvokedPromiseResult = 0;
        let promiseResultIncrementerDisposer:IReactionDisposer;
        let promise = remoteData({
            invoke:async ()=>{
                lastInvokedPromiseResult = promiseResult.get();
                return lastInvokedPromiseResult;
            }
        });
        onMobxPromise(promise, ()=>{
            // ensure the promise is already resolved by this point
            onMobxPromise(promise, (result:number)=>{
                assert.equal(result, 0, "promise invoked with result = 0");
                handlerInvokeCount += 1;
                promiseResult.set(promiseResult.get() + 1);
            }, 1, ()=>{
                promiseResultIncrementerDisposer = onMobxPromise(promise, ()=>{
                    assert.equal(handlerInvokeCount, 1, "never invoked again");
                    promiseResult.set(promiseResult.get() + 1);
                }, 10, ()=>{
                    done();
                });
            });
        });
    });
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:28,代码来源:onMobxPromise.spec.ts


示例7: mobxArrayPush

function mobxArrayPush() {
    console.time("Mobx push 1000 empty objects into array");
    let a = mobx.observable([]);
    for (let i = 0; i < 1000; i++) {
        a.push({ b: i });
    }
    console.timeEnd("Mobx push 1000 empty objects into array");
}
开发者ID:Bobris,项目名称:Bobril,代码行数:8,代码来源:app.ts


示例8: observable

 const A = types.model({}).extend(self => {
     const localState = observable(3)
     return {
         views: {
             get x() {
                 return localState.get()
             }
         },
         actions: {
             setX(value) {
                 localState.set(value)
             }
         }
     }
 })
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:15,代码来源:object.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mobx.reaction函数代码示例发布时间:2022-05-25
下一篇:
TypeScript mobx.extendObservable函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap