Skip to content

Commit d7d3dad

Browse files
authored
Merge pull request #172 from RobinCK/refactoring-watch-example
Refactoring watch example
2 parents 18ce3ac + 20e1209 commit d7d3dad

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

examples/typescript/watch/watch-example.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
import k8s = require('@kubernetes/client-node');
1+
import * as k8s from '@kubernetes/client-node';
22

3-
let kc = new k8s.KubeConfig();
3+
const kc = new k8s.KubeConfig();
44
kc.loadFromDefault();
55

6-
let watch = new k8s.Watch(kc);
7-
let req = watch.watch('/api/v1/namespaces',
6+
const watch = new k8s.Watch(kc);
7+
const req = watch.watch('/api/v1/namespaces',
88
// optional query parameters can go here.
9-
{},
9+
{},
1010
// callback is called for each received object.
1111
(type, obj) => {
12-
if (type == 'ADDED') {
12+
if (type === 'ADDED') {
1313
console.log('new object:');
14-
} else if (type == 'MODIFIED') {
15-
console.log('changed object:')
16-
} else if (type == 'DELETED') {
14+
} else if (type === 'MODIFIED') {
15+
console.log('changed object:');
16+
} else if (type === 'DELETED') {
1717
console.log('deleted object:');
1818
} else {
1919
console.log('unknown type: ' + type);
2020
}
21+
2122
console.log(obj);
2223
},
2324
// done callback is called if the watch terminates normally
2425
(err) => {
25-
if (err) {
26-
console.log(err);
27-
}
26+
console.log(err);
2827
});
2928

3029
// watch returns a request object which you can use to abort the watch.

0 commit comments

Comments
 (0)