Skip to content

Commit

Permalink
feat(patch): fix angular#828, patch socket.io client
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Jan 21, 2018
1 parent fd91152 commit 85e737c
Show file tree
Hide file tree
Showing 4 changed files with 970 additions and 363 deletions.
20 changes: 19 additions & 1 deletion NON-STANDARD-APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,23 @@ add following line into `polyfill.ts` after load zone-mix.
import 'zone.js/dist/zone-patch-electron';
```

there is a sampel repo [zone-electron](https://github.com/JiaLiPassion/zone-electron) here
there is a sample repo [zone-electron](https://github.com/JiaLiPassion/zone-electron) here

* socket.io-client

user need to patch `io` themselves just like following code.

```javascript
<script src="socket.io-client/dist/socket.io.js"></script>
<script src="zone.js/dist/zone.js"></script>
<script src="zone.js/dist/zone-patch-socket-io.js"></script>
<script>
// patch io here
Zone[Zone.__symbol__('socketio')](io);
</script>
```


please reference the sample repo [zone-socketio](https://github.com/JiaLiPassion/zone-socketio) about
detail usage.

10 changes: 10 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ gulp.task('build/zone-patch-user-media.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-user-media.ts', 'zone-patch-user-media.min.js', true, cb);
});

gulp.task('build/zone-patch-socket-io.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/socket-io.ts', 'zone-patch-socket-io.js', false, cb);
});

gulp.task('build/zone-patch-socket-io.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/socket-io.ts', 'zone-patch-socket-io.min.js', true, cb);
});

gulp.task('build/bluebird.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.js', false, cb);
});
Expand Down Expand Up @@ -297,6 +305,8 @@ gulp.task('build', [
'build/zone-patch-electron.min.js',
'build/zone-patch-user-media.js',
'build/zone-patch-user-media.min.js',
'build/zone-patch-socket-io.js',
'build/zone-patch-socket-io.min.js',
'build/zone-mix.js',
'build/bluebird.js',
'build/bluebird.min.js',
Expand Down
24 changes: 24 additions & 0 deletions lib/extra/socket-io.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @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('socketio', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
(Zone as any)[Zone.__symbol__('socketio')] = function patchSocketIO(io: any) {
// patch io.Socket.prototype event listener related method
api.patchEventTarget(global, [io.Socket.prototype], {
useG: false,
chkDup: false,
rt: true,
diff: (task: any, delegate: any) => {
return task.callback === delegate;
}
});
// also patch io.Socket.prototype.on/off/removeListener/removeAllListeners
io.Socket.prototype.on = io.Socket.prototype.addEventListener;
io.Socket.prototype.off = io.Socket.prototype.removeListener =
io.Socket.prototype.removeAllListeners = io.Socket.prototype.removeEventListener;
};
});
Loading

0 comments on commit 85e737c

Please sign in to comment.