-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from microsoft/geguskov/fix/promise-finally-po…
…lyfill Update Promise polyfills
- Loading branch information
Showing
4 changed files
with
39 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@microsoft/objectstoreprovider", | ||
"version": "0.6.40", | ||
"version": "0.6.41", | ||
"description": "A cross-browser object store library", | ||
"author": "Mukundan Kavanur Kidambi <[email protected]>", | ||
"scripts": { | ||
|
@@ -30,7 +30,7 @@ | |
"sorted-btree": "^1.5.0" | ||
}, | ||
"sideEffects": [ | ||
"./src/Promise.ts" | ||
"./src/Promise.extensions.ts" | ||
], | ||
"devDependencies": { | ||
"@types/assert": "^1.5.4", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
// this is a module with side-effects that add polyfills for finally and always | ||
// methods of the Promise | ||
|
||
declare interface Promise<T> { | ||
finally: (onfinally?: (() => void) | null | undefined) => Promise<T>; | ||
always: <U>(func: (value: T | any) => U | PromiseLike<U>) => Promise<U>; | ||
} | ||
|
||
// polyfill for Promise.finally. It is part of ES6 spec now, but was not in it originally and has spotty support in older browsers: | ||
// https://caniuse.com/mdn-javascript_builtins_promise_finally | ||
|
||
if (typeof Promise.prototype.finally !== "function") { | ||
Promise.prototype.finally = function (onResolveOrReject) { | ||
const hasFunctionCallback = typeof onResolveOrReject === "function"; | ||
return this.catch(function (reason: any) { | ||
hasFunctionCallback && onResolveOrReject && onResolveOrReject(); | ||
return Promise.reject(reason); | ||
}).then(function (result: any) { | ||
hasFunctionCallback && onResolveOrReject && onResolveOrReject(); | ||
return result; | ||
}); | ||
}; | ||
} | ||
|
||
// always polyfill, not part of the ES spec | ||
if (typeof Promise.prototype.always !== "function") { | ||
Promise.prototype.always = function (onResolveOrReject) { | ||
return this.then(onResolveOrReject, function (reason: any) { | ||
onResolveOrReject(reason); | ||
throw reason; | ||
}); | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.