本文整理汇总了TypeScript中es6-promise.Promise.resolve方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Promise.resolve方法的具体用法?TypeScript Promise.resolve怎么用?TypeScript Promise.resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类es6-promise.Promise
的用法示例。
在下文中一共展示了Promise.resolve方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
return function(dispatch: Dispatch<IStoreState>, getState: () => IStoreState): Promise<any> {
function onSuccess(rawItems: IMenuItemRaw[]) {
dispatch({
type: ActionType.FETCH_SUCCESS_REMOTE,
data: rawItems
} as IActionReceiveItemsFromAPI);
}
function onFailure(error: any) {
dispatch({
type: ActionType.FETCH_FAILURE,
message: error.message || 'Fetch error'
} as IActionFetchFailure)
}
let result: Promise<any>;
let localItems = loadLocalItems();
localItems = null;
if (getIsFetchingStatus(getState())) {
// If a fetch is already in progress, do not initiate another fetch. Once
// again, notice that we do not access the structure of the store directly
// even though we could:
result = Promise.resolve(null);
} else {
// Let the app know that fetching is about to start (show loading spinner):
dispatch({
type: ActionType.FETCH_BEGIN
} as IActionNotify);
if (doesExist(localItems)) {
// If local storage has stored data, load from it:
dispatch({
type: ActionType.FETCH_SUCESS_LOCAL,
data: localItems
} as IActionReceiveItemsFromLocal);
result = Promise.resolve(null);
} else {
// Otherwise, fetch data from the API and shows the loading spinner until
// the data has finished loading:
result = ajax({
url: dataFileURL,
dataType: 'json'
}).then(
// Here we use the two-callback form of `then` because we want `onFailure`
// to only handle errors from the API call and not some other internal
// errors. Internal errors are passed to the `catch` callback later:
onSuccess,
onFailure
).catch((error) => {
console.log(error);
});
}
}
return result;
}
示例2: get
get(path: string): Promise<Object> {
if (path.indexOf("/subscriptions?") === 0) {
return Promise.resolve({
value: [
{ subscriptionId: "6d867431-f573-4e78-b658-10896020cff7", displayName: "d2" }
]
});
} else if (path.indexOf("/subscriptions/") === 0) {
return Promise.resolve({ value: [{}, {}] });
}
return Promise.reject(404);
}
示例3: dispatch
.then((result) => {
dispatch({
type: UNLINK_USER,
data: result.data
})
return Promise.resolve(result.data);
})
开发者ID:Emunoz88,项目名称:node-hapi-react-redux-sass-typescript-mongo-webpack-hmr-gulp,代码行数:7,代码来源:actions.ts
示例4: executeQueries
executeQueries(queries: IMcQueryEntry[]): Promise<IMcResult> {
return Promise.resolve<IMcResult>({
list: [
{ name: "a1", value: 2 }
]
});
}
示例5: h
const h = (i: number)=>{
const f = files[i];
if (f == null){
if (nisFinite(mtime)){
target[mtimef] = mtime;
}
return Promise.resolve(target);
}
const pa = path.join(dir, f);
const base = path.basename(f, path.extname(f));
return this.fromFile1(pa, options, cache && cache[base]).then(v=>{
if (v !== void 0){
target[base] = v;
}
// ディレクトリ中で最大のmtimeを調べている
if (options.mtime){
if (v != null && nisFinite(v[mtimef])){
// 更新日時情報持ってる
if (mtime < v[mtimef]){
mtime = v[mtimef];
}
return h(i+1);
}else{
// 無いから取得しないと
return getMTime(pa).then(mt=>{
if (nisFinite(mt) && mtime < mt){
mtime = mt;
}
return h(i+1);
});
}
}
return h(i+1);
});
};
示例6: jsLoader
export default function jsLoader(path: string): Promise<any>{
try {
return Promise.resolve(require(path));
}catch (e){
return Promise.reject(e);
}
}
示例7: runPayload
function runPayload(payload:Payload) {
if (payload.isTarget()) {
return payload.run();
} else {
return Promise.resolve(false)
}
}
示例8: promptName
promptName(name: string = ''): Thenable<string> {
name = name.trim();
if (!this.utils.isEmpty(name)) {
this.title = name;
name = this.utils.kebabCase(name).toLowerCase();
let valid = validate(name);
if (this.utils.isArray(valid.errors) || this.utils.isArray(valid.warnings)) {
this.ui.warn('');
this.utils.forEach(valid.errors, (err: string) => {
this.ui.warn(err);
});
this.utils.forEach(valid.warnings, (err: string) => {
this.ui.warn(err);
});
this.ui.warn('');
} else {
return Promise.resolve(name);
}
}
return this.ui.prompt([
{ name: 'name', type: 'input', message: `What is the name of your app?` }
]).then((answer: { name: string; }) => {
return this.promptName(answer.name);
});
}
示例9: function
return function (dispatch: Dispatch, getState: () => any): any {
if (!getState().sandwiches.isShopOpen) {
// You don’t have to return Promises, but it’s a handy convention
// so the caller can always call .then() on async dispatch result.
return Promise.resolve();
}
// We can dispatch both plain object actions and other thunks,
// which lets us compose the asynchronous actions in a single flow.
return dispatch(
makeASandwichWithSecretSauce('My Grandma')
).then(() =>
Promise.all([
dispatch(makeASandwichWithSecretSauce('Me')),
dispatch(makeASandwichWithSecretSauce('My wife'))
])
).then(() =>
dispatch(makeASandwichWithSecretSauce('Our kids'))
).then(() =>
dispatch(getState().myMoney > 42 ?
withdrawMoney(42) :
apologize('Me', 'The Sandwich Shop')
)
);
};