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

Commit a8425bf

Browse files
author
Daniel Brain
committed
Add client and listener factories
1 parent 71a2543 commit a8425bf

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/interface/client.js

+11
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,16 @@ export function sendToParent(name, data, options, callback) {
140140
return send(win, name, data, options, callback);
141141
}
142142

143+
export function client(options = {}) {
143144

145+
if (!options.window) {
146+
throw new Error(`Expected options.window`);
147+
}
148+
149+
return {
150+
send(name, data, callback) {
151+
return send(options.window, name, data, options, callback);
152+
}
153+
};
154+
}
144155

src/interface/server.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,18 @@ export function once(name, options, handler, errorHandler) {
9191
options.errorHandler = options.errorHandler || reject;
9292
});
9393

94-
let listener = listen(options);
94+
let myListener = listen(options);
9595

96-
util.extend(prom, listener);
96+
util.extend(prom, myListener);
9797

9898
return prom;
9999
}
100+
101+
export function listener(options = {}) {
102+
103+
return {
104+
on(name, handler, errorHandler) {
105+
return on(name, options, handler, errorHandler);
106+
}
107+
};
108+
}

0 commit comments

Comments
 (0)