Skip to content

Commit

Permalink
refactor: store AsyncAF instance data in a WeakMap for privacy
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the inner promise within AsyncAF instances can no longer be accessed at, e.g., AsyncAF().data
  • Loading branch information
ScottRudiger committed Aug 1, 2018
1 parent 7f0aa86 commit 36cbaf6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/classes/AsyncAfWrapper.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import createNewlessClass from '../methods/_internal/createNewlessClass';
import use from '../methods/other/use';

const dataStore = new WeakMap();

class AsyncAfWrapperProto {
constructor(data) {
this.data = Promise[Array.isArray(data) ? 'all' : 'resolve'](data);
dataStore.set(this, Promise[Array.isArray(data) ? 'all' : 'resolve'](data));
}
then(resolve, reject) {
return new (this.constructor)(this.data.then(resolve, reject));
return new (this.constructor)(dataStore.get(this).then(resolve, reject));
}
catch(reject) {
return this.then(null, reject);
}
finally(onFinally) {
return this.data.finally(onFinally);
return dataStore.get(this).finally(onFinally);
}
}

Expand Down

0 comments on commit 36cbaf6

Please sign in to comment.