forked from angular/zone.js
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(patch): fix angular#758, patch cordova success/error with zone.wrap
- Loading branch information
1 parent
b92b6e3
commit 7820c7f
Showing
9 changed files
with
86 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
Zone.__load_patch('cordova', (global: any, Zone: ZoneType, api: _ZonePrivate) => { | ||
if (global.cordova) { | ||
const nativeExec: Function = api.patchMethod( | ||
global.cordova, 'exec', (delegate: Function) => function(self: any, args: any[]) { | ||
if (args.length > 0 && typeof args[0] === 'function') { | ||
args[0] = Zone.current.wrap(args[0], 'cordova.exec.success'); | ||
} | ||
if (args.length > 1 && typeof args[1] === 'function') { | ||
args[1] = Zone.current.wrap(args[1], 'cordova.exec.error'); | ||
} | ||
return nativeExec.apply(self, args); | ||
}); | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
describe('cordova test', () => { | ||
it('cordova.exec() should be patched as macroTask', (done) => { | ||
const scheduleSpy = jasmine.createSpy('scheduleTask'); | ||
const cordova = (window as any).cordova; | ||
|
||
const zone = Zone.current.fork({name: 'cordova'}); | ||
|
||
zone.run(() => { | ||
cordova.exec( | ||
() => { | ||
expect(Zone.current.name).toEqual('cordova'); | ||
done(); | ||
}, | ||
() => { | ||
fail('should not fail'); | ||
}, | ||
'service', 'successAction', ['arg0', 'arg1']); | ||
|
||
cordova.exec( | ||
() => { | ||
fail('should not success'); | ||
}, | ||
() => { | ||
expect(Zone.current.name).toEqual('cordova'); | ||
done(); | ||
}, | ||
'service', 'failAction', ['arg0', 'arg1']); | ||
}); | ||
}); | ||
}); |
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