-
Notifications
You must be signed in to change notification settings - Fork 3
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 #33 from npetillon/master
Bug fix: `optionalParams` not being destructured properly in logLevel
- Loading branch information
Showing
7 changed files
with
960 additions
and
1,788 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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": "ngx-toolkit", | ||
"version": "9.0.1", | ||
"version": "9.0.4", | ||
"license": "MIT", | ||
"scripts": { | ||
"ng": "ng", | ||
|
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
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
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,7 +1,69 @@ | ||
import {Queue} from './queue.decorator'; | ||
import {Subscription} from 'rxjs'; | ||
import {Deferred, isPromise} from './functions'; | ||
|
||
export interface WaitData { | ||
wait?: Function; | ||
promise: Promise<any>; | ||
} | ||
|
||
/** | ||
* Wait for a Promise / Subscription before to be re-executed | ||
* /!\ the method result is modified => Return a Promise | ||
*/ | ||
export const Wait = (name?: string) => Queue.bind(this, 1, name); | ||
export function Wait(name?: string): MethodDecorator { | ||
return function( | ||
target: Object, | ||
propertyKey: string | symbol, | ||
descriptor: TypedPropertyDescriptor<any> | ||
): TypedPropertyDescriptor<any> | void { | ||
// Init | ||
name = name || propertyKey.toString(); | ||
const data: WaitData = (target[`_ngxWait_${name}`] = target[`_ngxWait_${name}`] || { | ||
promise: Promise.resolve() | ||
}); | ||
const originalMethod = descriptor.value; | ||
|
||
// Change method | ||
descriptor.value = function(...args: any[]) { | ||
// Push Future call | ||
const deferred: Deferred<any> = new Deferred<any>(); | ||
|
||
// Ignore next call | ||
if (!data.wait) { | ||
data.wait = () => { | ||
try { | ||
const result: any = originalMethod.apply(this, args); | ||
|
||
if (isPromise(result)) { | ||
result.then(r => deferred.resolve(r), e => deferred.reject(e)); | ||
} else if (result instanceof Subscription) { | ||
result.add(() => deferred.resolve()); | ||
} else { | ||
deferred.resolve(result); | ||
} | ||
} catch (e) { | ||
deferred.reject(e); | ||
} | ||
|
||
return deferred.promise; | ||
}; | ||
|
||
// Execute | ||
data.promise = data.promise | ||
|
||
// Call | ||
.then(() => data.wait.apply(this)) | ||
// Pop | ||
.then(() => data.wait = null, () => data.wait = null); | ||
} else { | ||
deferred.reject('Wait: Function is running'); | ||
} | ||
|
||
// Return promise | ||
return deferred.promise; | ||
}; | ||
|
||
return descriptor; | ||
}; | ||
} | ||
|