Skip to content

Commit

Permalink
Make pipe work with PromiseProxies
Browse files Browse the repository at this point in the history
- Relaxed the `instanceof` check to duck type if the object implements
  Promise-like methods to work with Objects that include the
  PromiseProxy mixin
  • Loading branch information
poteto committed Mar 5, 2016
1 parent 574623c commit 08305b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions addon/utils/is-promise.js
@@ -1,7 +1,13 @@
import Ember from 'ember';

const { RSVP: { Promise }, isPresent } = Ember;
const { typeOf } = Ember;

function isPromiseLike(obj = {}) {
return typeOf(obj.then) === 'function' &&
typeOf(obj.catch) === 'function' &&
typeOf(obj.finally) === 'function';
}

export default function isPromise(obj) {
return isPresent(obj) && obj instanceof Promise;
return typeOf(obj) === 'object' && isPromiseLike(obj);
}
8 changes: 8 additions & 0 deletions tests/unit/utils/is-promise-test.js
Expand Up @@ -18,6 +18,10 @@ let testData = [
value: new Promise((resolve) => resolve('blah')),
expected: true
},
{
value: { then: K, catch: K, finally: K },
expected: true
},
{
value: { then: K },
expected: false
Expand All @@ -33,6 +37,10 @@ let testData = [
{
value: ['meow'],
expected: false
},
{
value: null,
expected: false
}
];

Expand Down

0 comments on commit 08305b4

Please sign in to comment.