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


TypeScript mobx.autorun函数代码示例

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


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

示例1: autorun

export function onMobxPromise<T>(promise:MobxPromise<T>|Array<MobxPromise<T>>,
                                         onComplete:(...results:T[])=>void,
                                         times:number = 1,
                                        onDispose?:()=>void):IReactionDisposer {
    let disposer:IReactionDisposer;
    let count:number = 0;
    let promiseArray:Array<MobxPromise<T>>;
    if (promise instanceof Array) {
        promiseArray = promise;
    } else {
        promiseArray = [promise];
    }
    disposer = autorun((reaction)=>{
        if (promiseArray.reduce((acc, next)=>(acc && next.isComplete), true)) {
            // if all complete
            onComplete(...promiseArray.map(x=>(x.result as T)));
            count += 1;
        }
        if (count >= times) {
            reaction.dispose();
            onDispose && onDispose();
        }
    });
    return disposer;
}
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:25,代码来源:onMobxPromise.ts

示例2: it

  it('should trigger autorun on change', (done) => {
    const store = new TestStore();
    store.sync({
      data: {
        attributes: {
          name: 'Demo',
        },
        id: 1,
        type: 'events',
      },
    });

    let name = 'Demo';

    const event = store.find<Event>('events', 1);
    expect(event.name).to.equal('Demo');

    autorun(() => {
      expect(event.name).to.equal(name);

      if (name === 'Foo') {
        done();
      }
    });

    name = 'Foo';
    event.name = 'Foo';
  });
开发者ID:DarkoKukovec,项目名称:mobx-jsonapi-store,代码行数:28,代码来源:general.ts

示例3: ensureValidConfig

    ensureValidConfig() {
        const {chart} = this

        // Validate the map variable id selection to something on the chart
        autorun(() => {
            const hasVariable = chart.map.variableId && chart.vardata.variablesById[chart.map.variableId]
            if (!hasVariable && chart.data.primaryVariable) {
                const variableId = chart.data.primaryVariable.id
                runInAction(() => chart.map.props.variableId = variableId)
            }
        })

        // When automatic classification is turned off, assign defaults
        reaction(
            () => this.map.props.isManualBuckets,
            () => {
                if (this.map.props.isManualBuckets) {
                    const { autoBinMaximums } = this
                    const colorSchemeValues = toJS(this.map.props.colorSchemeValues) || []
                    for (let i = 0; i < autoBinMaximums.length; i++) {
                        if (i >= colorSchemeValues.length)
                            colorSchemeValues.push(autoBinMaximums[i])
                    }
                    this.map.props.colorSchemeValues = colorSchemeValues
                }
            }
        )
    }
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:28,代码来源:MapData.ts

示例4: modelDriver

export function modelDriver(callback: (subject: Subject<any>) => void): Observable<any> {
    const result = new Subject();
    autorun(() => {
        callback(result); 
    });    
    return result;
};
开发者ID:pvasek,项目名称:mobx-app-model,代码行数:7,代码来源:modelDriver.ts

示例5: it

    it('Adding variable whose formula references a non-existent symbol', () => {
        const remath = new Remath();
        let view: ObservableMap<string> = observable.map<string>();
        const render = sinon.spy(() => {
            renderCells(remath, view);
        });
        autorun(render);

        // add a
        const a = remath.addCell({
            symbol: 'a',
            formula: '= b + 10'
        });
        expect(render.callCount).to.equal(2);
        expect(view.get('a')).to.equal('sym:a,formula:b + 10,val:NaN,disp:#REF?');

        // add b = 30
        runInAction(() => {
            const b = remath.addCell({
                symbol: 'b',
                formula: '=30'
            });
        });
        expect(view.get('b')).to.equal('sym:b,formula:30,val:30,disp:30');
        expect(view.get('a')).to.equal('sym:a,formula:b + 10,val:40,disp:40');
    });
开发者ID:trevorhanus,项目名称:reMath,代码行数:26,代码来源:Integration_1.test.ts

示例6: it

    it('loggedIn', () => {
      authStore.sessionToken = '';
      let ar: boolean[] = [];

      autorun(() => {
        ar.push(authStore.loggedIn);
      });
      expect(ar[ar.length-1]).to.equal(false);

      authStore.sessionToken = '#token';
      expect(ar[ar.length-1]).to.equal(true);
    });
开发者ID:AnuchitPrasertsang,项目名称:volunteers-nutrition,代码行数:12,代码来源:AuthStore.test.ts

示例7: it

 it('is observable', () => {
     const lock = new Lockable({locked: false});
     let v;
     const renderSpy = sinon.spy(() => {
         v = `${lock.locked}`;
     });
     autorun(renderSpy);
     expect(v).to.equal('false');
     lock.lock();
     expect(v).to.equal('true');
     lock.unlock();
     expect(v).to.equal('false');
 });
开发者ID:trevorhanus,项目名称:reMath,代码行数:13,代码来源:Lockable.test.ts

示例8: constructor

    constructor() {
        this.token = localStorage.getItem(AUTH_STORAGE_NAME) || "";

        if (this.token) {
            // Decode the token without verifying it. Verification will happen on the server.
            this.session = decode(this.token, undefined, true);
        }

        autorun("AuthStore-autorun", (runner) => {
            // Persist the auth changes to localstorage
            localStorage.setItem(AUTH_STORAGE_NAME, this.token);
        });
    }
开发者ID:nozzlegear,项目名称:Gearworks,代码行数:13,代码来源:auth.ts

示例9: it

 it("triggers any mobx reaction that touches the cache when its updated", (done)=>{
         let peekFn = sinon.spy(()=>{
             cache.peek({numAsString:"2"});
             if (peekFn.callCount === 2 && cacheFn.callCount === 2 && getFn.callCount === 2) {
                 peekReaction();
                 cacheReaction();
                 getReaction();
                 done();
             }
         });
         let cacheFn = sinon.spy(()=>{
             cache.cache;
             if (peekFn.callCount === 2 && cacheFn.callCount === 2 && getFn.callCount === 2) {
                 peekReaction();
                 cacheReaction();
                 getReaction();
                 done();
             }
         });
         let getFn = sinon.spy(()=>{
             cache.get({numAsString:"2"});
             if (peekFn.callCount === 2 && cacheFn.callCount === 2 && getFn.callCount === 2) {
                 peekReaction();
                 cacheReaction();
                 getReaction();
                 done();
             }
         });
         assert.equal(peekFn.callCount, 0);
         assert.equal(cacheFn.callCount, 0);
         assert.equal(getFn.callCount, 0);
         let peekReaction = mobx.autorun(peekFn);
         let cacheReaction = mobx.autorun(cacheFn);
         let getReaction = mobx.autorun(getFn);
         assert.equal(peekFn.callCount, 1);
         assert.equal(cacheFn.callCount, 1);
         assert.equal(getFn.callCount, 1);
 });
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:38,代码来源:LazyMobXCache.spec.ts


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