Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 0b7a54c

Browse files
author
Daniel Brain
committed
Remove callback support
1 parent 1ee6963 commit 0b7a54c

File tree

4 files changed

+9
-70
lines changed

4 files changed

+9
-70
lines changed

src/drivers/receive/types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export let RECEIVE_MESSAGE_TYPES = {
5858

5959
let data = message.data;
6060

61-
return promise.deNodeify(options.handler, { source, origin, data });
61+
return options.handler({ source, origin, data });
6262

6363
}).then(data => {
6464

src/lib/promise.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,6 @@ export let promise = {
3939
});
4040
},
4141

42-
deNodeify(method, ...args) {
43-
return new Promise((resolve, reject) => {
44-
try {
45-
if (args.length < method.length) {
46-
return method(...args, (err, result) => {
47-
return err ? reject(err) : resolve(result);
48-
});
49-
}
50-
51-
return promise.run(() => {
52-
return method(...args);
53-
}).then(resolve, reject);
54-
55-
} catch (err) {
56-
return reject(err);
57-
}
58-
});
59-
},
60-
6142
map(items, method) {
6243

6344
let results = [];
@@ -68,4 +49,4 @@ export let promise = {
6849
}
6950
return Promise.all(results);
7051
}
71-
};
52+
};

src/public/client.js

+6-18
Original file line numberDiff line numberDiff line change
@@ -149,40 +149,28 @@ export function request(options) {
149149
return requestPromise;
150150
});
151151

152-
return promise.nodeify(prom, options.callback);
152+
return prom;
153153
}
154154

155-
export function send(window, name, data, options, callback) {
156-
157-
if (!callback) {
158-
if (!options && typeof data === 'function') {
159-
callback = data;
160-
options = {};
161-
data = {};
162-
} else if (typeof options === 'function') {
163-
callback = options;
164-
options = {};
165-
}
166-
}
155+
export function send(window, name, data, options) {
167156

168157
options = options || {};
169158
options.window = window;
170159
options.name = name;
171160
options.data = data;
172-
options.callback = callback;
173161

174162
return request(options);
175163
}
176164

177-
export function sendToParent(name, data, options, callback) {
165+
export function sendToParent(name, data, options) {
178166

179167
let win = getAncestor();
180168

181169
if (!win) {
182170
return new promise.Promise((resolve, reject) => reject(new Error('Window does not have a parent')));
183171
}
184172

185-
return send(win, name, data, options, callback);
173+
return send(win, name, data, options);
186174
}
187175

188176
export function client(options = {}) {
@@ -192,8 +180,8 @@ export function client(options = {}) {
192180
}
193181

194182
return {
195-
send(name, data, callback) {
196-
return send(options.window, name, data, options, callback);
183+
send(name, data) {
184+
return send(options.window, name, data, options);
197185
}
198186
};
199187
}

test/test.js

+1-31
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,6 @@ describe('[post-robot] happy cases', function() {
102102
});
103103
});
104104

105-
it('should message a child and expect a response with a callback', function(done) {
106-
107-
postRobot.send(childFrame, 'setupListener', {
108-
109-
messageName: 'foo',
110-
data: {
111-
foo: 'bar2'
112-
}
113-
114-
}).then(function() {
115-
116-
return postRobot.send(childFrame, 'foo', function(err, event) {
117-
assert.equal(event.data.foo, 'bar2');
118-
done();
119-
});
120-
121-
}).catch(done);
122-
});
123-
124105
it('should pass a function across windows and be able to call it later', function(done) {
125106

126107
postRobot.send(childFrame, 'setupListener', {
@@ -331,18 +312,7 @@ describe('[post-robot] error cases', function() {
331312
assert.ok(err);
332313
});
333314
});
334-
335-
it('should get a callback error when messaging with an unknown name', function(done) {
336-
337-
postRobot.send(childFrame, 'doesntexist', function(err, event) {
338-
assert.ok(err);
339-
if (event) {
340-
throw new Error('Expected event to be blank');
341-
}
342-
done();
343-
});
344-
});
345-
315+
346316
it('should error out if you try to register the same listener name twice', function() {
347317

348318
postRobot.on('onceonly', function() {

0 commit comments

Comments
 (0)