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


TypeScript rsvp.resolve函數代碼示例

本文整理匯總了TypeScript中rsvp.resolve函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript resolve函數的具體用法?TypeScript resolve怎麽用?TypeScript resolve使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: testAsyncAwait

async function testAsyncAwait() {
    const awaitedNothing = await RSVP.resolve();
    const awaitedValue = await RSVP.resolve('just a value');

    async function returnsAPromise(): RSVP.Promise<string> {
        return RSVP.resolve('look, a string');
    }

    assertType<RSVP.Promise<string>>(returnsAPromise());
    assertType<string>(await returnsAPromise());
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:rsvp-tests.ts

示例2: testRace

function testRace() {
    const imported = race([]);
    const firstPromise = RSVP.race([{ notAPromise: true }, RSVP.resolve({ some: 'value' })]);
    assertType<RSVP.Promise<{ notAPromise: boolean } | { some: string }>>(firstPromise);

    let promise1 = RSVP.resolve(1);
    let promise2 = RSVP.resolve('2');
    RSVP.Promise.race([promise1, promise2], 'my label').then(function(result) {
        assertType<string | number>(result);
    });
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:rsvp-tests.ts

示例3: testHash

function testHash() {
    let promises = {
        myPromise: RSVP.resolve(1),
        yourPromise: RSVP.resolve('2'),
        theirPromise: RSVP.resolve({ key: 3 }),
        notAPromise: 4,
    };
    RSVP.hash(promises, 'my label').then(function(hash) {
        assertType<number>(hash.myPromise);
        assertType<string>(hash.yourPromise);
        assertType<{ key: number }>(hash.theirPromise);
        assertType<number>(hash.notAPromise);
    });
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:14,代碼來源:rsvp-tests.ts

示例4: testMap

function testMap() {
    RSVP.map([RSVP.resolve(1), RSVP.resolve(2)], item => item + 1, 'add one').then(results => {
        assertType<number[]>(results);
        assertType<{ length: 2 }>(results);
    });

    RSVP.map([RSVP.resolve('a string'), RSVP.resolve(112233)], String).then(results => {
        assertType<string[]>(results);
        assertType<{ length: 2 }>(results);
    });

    // This is the best we can do: we can't actually write the full type here,
    // which would be `assertType<never>(results)`, but TS can't infer that.
    RSVP.map([RSVP.reject('for any reason')], String).then(results => {
        assertType<{}>(results);
    });
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:17,代碼來源:rsvp-tests.ts

示例5: testAllSettled

function testAllSettled() {
    const resolved1 = RSVP.resolve(1);
    const resolved2 = RSVP.resolve('wat');
    const rejected = RSVP.reject(new Error('oh teh noes'));
    const pending = new RSVP.Promise<{ neato: string }>((resolve, reject) => {
        if ('something') {
            resolve({ neato: 'yay' });
        } else {
            reject('nay');
        }
    });

    // Types flow into resolution properly
    RSVP.allSettled([resolved1, resolved2, rejected, pending]).then(states => {
        assertType<RSVP.PromiseState<number>>(states[0]);
        assertType<RSVP.PromiseState<string>>(states[1]);
        assertType<RSVP.PromiseState<never>>(states[2]);
        assertType<RSVP.PromiseState<{ neato: string }>>(states[3]);
    });

    // Switching on state gives the correctly available items.
    RSVP.allSettled([resolved1, resolved2, rejected, pending]).then(states => {
        states.forEach(element => {
            switch (element.state) {
                case RSVP.State.fulfilled:
                    assertType<RSVP.Resolved<typeof element.value>>(element);
                    break;

                case RSVP.State.rejected:
                    assertType<RSVP.Rejected<typeof element.reason>>(element);
                    break;

                case RSVP.State.pending:
                    assertType<RSVP.Pending>(element);
                    break;

                default:
                    // Someday maybe TS will have exhaustiveness checks.
                    break;
            }
        });
    });
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:43,代碼來源:rsvp-tests.ts

示例6: testFilter

function testFilter() {
    RSVP.filter([RSVP.resolve(1), RSVP.resolve(2)], item => item > 1, 'over one').then(results => {
        assertType<number[]>(results);
    });

    RSVP.filter(
        [RSVP.resolve('a string'), RSVP.resolve(112233)],
        item => String(item).length < 10,
        'short string'
    ).then(results => {
        assertType<Array<string | number>>(results);
    });

    // This is the best we can do: we can't actually write the full type here,
    // which would be `assertType<never>(results)`, but TS can't infer that.
    const isString = (item: any): item is string => typeof item === 'string';
    RSVP.filter([RSVP.reject('for any reason')], isString).then(results => {
        assertType<{}>(results);
    });
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:20,代碼來源:rsvp-tests.ts

示例7: testResolve

function testResolve() {
    assertType<RSVP.Promise<void>>(RSVP.resolve());
    assertType<RSVP.Promise<string>>(RSVP.resolve('this is a string'));
    assertType<RSVP.Promise<string>>(RSVP.resolve(RSVP.resolve('nested')));
    assertType<RSVP.Promise<string>>(RSVP.resolve(Promise.resolve('nested')));

    let promise = RSVP.Promise.resolve(1);
    let imported = resolve(1);
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:9,代碼來源:rsvp-tests.ts

示例8: testAll

function testAll() {
    const imported = all([]);
    const empty = RSVP.Promise.all([]);

    const everyPromise = RSVP.all([
        'string',
        RSVP.resolve(42),
        RSVP.resolve({ hash: 'with values' }),
    ]);

    assertType<RSVP.Promise<[string, number, { hash: string }]>>(everyPromise);

    const anyFailure = RSVP.all([12, 'strings', RSVP.reject('anywhere')]);
    assertType<RSVP.Promise<{}>>(anyFailure);

    let promise1 = RSVP.resolve(1);
    let promise2 = RSVP.resolve('2');
    let promise3 = RSVP.resolve({ key: 13 });
    RSVP.Promise.all([promise1, promise2, promise3], 'my label').then(function(array) {
        assertType<number>(array[0]);
        assertType<string>(array[1]);
        assertType<{ key: number }>(array[2]);
    });
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:24,代碼來源:rsvp-tests.ts

示例9: function

export default function(name: string, options: Hooks = {}) {
  module(name, {
    beforeEach(this: TestContext) {
      this.application = startApp();

      if (options.beforeEach) {
        return options.beforeEach.apply(this, arguments);
      }
    },

    afterEach(this: TestContext) {
      let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
      return resolve(afterEach).then(() => destroyApp(this.application));
    },
  });
}
開發者ID:salsify,項目名稱:ember-debug-logger,代碼行數:16,代碼來源:module-for-acceptance.ts

示例10: test

test('Integration w/ HandlerInfos', function(assert) {
  assert.expect(4);

  let state = new TransitionState();
  let router = new TestRouter();
  let fooModel = {};
  let barModel = {};
  let transition = {};

  state.routeInfos = [
    new UnresolvedRouteInfoByParam(
      router,
      'foo',
      ['foo_id'],
      { foo_id: '123' },
      createHandler('foo', {
        model: function(params: Dict<unknown>, payload: Dict<unknown>) {
          assert.equal(payload, transition);
          assert.equal(params.foo_id, '123', 'foo#model received expected params');
          return resolve(fooModel);
        },
      })
    ),
    new UnresolvedRouteInfoByObject(router, 'bar', ['bar_id'], resolve(barModel)),
  ];

  function noop() {
    return Promise.resolve(false);
  }

  state
    .resolve(noop, transition as Transition)
    .then(function(result: TransitionState<Route>) {
      let models = [];
      for (let i = 0; i < result.routeInfos.length; i++) {
        models.push(result.routeInfos[i].context);
      }

      assert.equal(models[0], fooModel);
      assert.equal(models[1], barModel);
      return Promise.resolve(new TransitionState());
    })
    .catch(function(error: Error) {
      assert.ok(false, 'Caught error: ' + error);
    });
});
開發者ID:tildeio,項目名稱:router.js,代碼行數:46,代碼來源:transition_state_test.ts


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