當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。