Skip to content

Commit af164e1

Browse files
committed
Added first event - instance.new - with documentation on README
Issue play-with-docker#3
1 parent d5ee1e6 commit af164e1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ Clone this repo and run `npm install && npm run build`
2929

3030
## Development
3131

32-
To make development easier, run `npm install && npm run dev`. All file changes will automatically trigger a Webpack build.
32+
To make development easier, run `npm install && npm run dev`. All file changes will automatically trigger a Webpack build.
33+
34+
35+
## Events
36+
37+
The SDK provides the ability to listen to various events. The events are outlined below
38+
39+
| Event Name | Arguments | Description |
40+
|--------------------|-----------------|----------------------------------------|
41+
| `instance.new` | instanceDetails | Invoked when a new instance is created |

index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ import * as Emitter from 'tiny-emitter';
120120
} else {
121121
console.warn('No terms specified, nothing to do.');
122122
}
123+
return this;
123124
};
124125

125126
// your sdk init function
@@ -160,7 +161,7 @@ import * as Emitter from 'tiny-emitter';
160161
var i = session.instances[name];
161162
// Setup empty terms
162163
i.terms = [];
163-
self.instances[name] = i;
164+
registerInstance(self, name, i);
164165
}
165166
!callback || callback();
166167
});
@@ -227,14 +228,19 @@ import * as Emitter from 'tiny-emitter';
227228
}
228229
};
229230

231+
function registerInstance(pwd, name, instanceMetadata) {
232+
pwd.instances[name] = instanceMetadata;
233+
pwd.eventEmitter.emit("instance.new", instanceMetadata);
234+
}
235+
230236
pwd.prototype.createInstance = function(callback) {
231237
var self = this;
232238
//TODO handle http connection errors
233239
sendRequest('POST', self.opts.baseUrl + '/sessions/' + this.sessionId + '/instances', {headers:{'Content-type':'application/json'}}, {ImageName: self.opts.ImageName}, function(response) {
234240
if (response.status == 200) {
235241
var i = JSON.parse(response.responseText);
236242
i.terms = [];
237-
self.instances[i.name] = i;
243+
registerInstance(self, i.name, i);
238244
callback(undefined, i);
239245
} else if (response.status == 409) {
240246
var err = new Error();

0 commit comments

Comments
 (0)