Skip to content

Commit

Permalink
Added the ability to omit the empty componentWillUnmount method whi…
Browse files Browse the repository at this point in the history
…le still being able to automatically cancel async routines on unmount;
  • Loading branch information
DigitalBrainJS committed May 1, 2021
1 parent c90a0b4 commit d5685d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ Returns a single CPromise that resolves to an array of the results of the input

| Param | Type |
| --- | --- |
| iterable | <code>Iterable</code> \| <code>Generator</code> \| <code>GeneratorFunction</code> |
| iterable | <code>Iterable</code> \| <code>Generator</code> \| <code>GeneratorFunction</code> \| <code>array</code> |
| [options] | <code>AllOptions</code> |

**Example**
Expand Down
29 changes: 23 additions & 6 deletions lib/c-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ const CPromise= class CPromise extends Promise {
/**
* Returns a single CPromise that resolves to an array of the results of the input promises.
* If one fails then other promises will be canceled immediately
* @param {Iterable|Generator|GeneratorFunction} iterable
* @param {Iterable|Generator|GeneratorFunction|array} iterable
* @param {AllOptions} [options]
* @returns {CPromise}
* @example
Expand All @@ -1187,15 +1187,17 @@ const CPromise= class CPromise extends Promise {
concurrency: numberFinitePositive,
ignoreResults: boolean,
signatures: boolean,
mapper: validators.function
mapper: validators.function,
args: array()
})
}

let {
concurrency = 0,
ignoreResults,
signatures,
mapper
mapper,
args= null
} = options || {}

const cancel = (reason) => {
Expand Down Expand Up @@ -1269,7 +1271,7 @@ const CPromise= class CPromise extends Promise {
return super.all(pending).then(resolve, _reject);
}

generator = toGenerator(iterable) || throwConvertError();
generator = toGenerator(iterable, args, scope) || throwConvertError();

pending = [];
!ignoreResults && (results = []);
Expand Down Expand Up @@ -2417,13 +2419,13 @@ const decorators = {
const bindAll= bindMethods && bindListeners;
const bind= bindMethods || bindListeners;


return {
kind: 'class',
finisher(constructor) {
const {prototype} = constructor;

Object.getOwnPropertyNames(prototype).forEach(prop => {
if (prop === 'constructor' || prop === 'render') return;
const decorate= (prop)=>{
const method = prototype[prop];
if (typeof method !== 'function') return;

Expand Down Expand Up @@ -2478,8 +2480,23 @@ const decorators = {
}
propsChanged = true
}
};

Object.getOwnPropertyNames(prototype).forEach(prop => {
if (prop === 'constructor' || prop === 'render') return;
decorate(prop);
});

if(!('componentWillUnmount' in prototype)){
descriptors.componentWillUnmount= {
value: function(){
cancelContext(this, '', E_REASON_UNMOUNTED);
},
configurable: true
};
propsChanged = true;
}

propsChanged && Object.defineProperties(prototype, descriptors);

return constructor;
Expand Down

0 comments on commit d5685d3

Please sign in to comment.