Skip to content

Commit

Permalink
make "registerApi" methods accept "logger" parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Oct 22, 2018
1 parent fa26c68 commit 5c4cc82
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-rpc-api",
"version": "3.1.0",
"version": "3.2.0",
"description": "Wrapper around the Electron's IPC for building type-safe API based RPC-like interactions",
"author": "Vladimir Yakovlev <[email protected]> (https://github.com/vladimiry)",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ipc-main-api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {AnyType} from "./model";
export class IpcMainApiService<Api extends Model.ActionsRecord<Extract<keyof Api, string>>> extends Service<Api> {
public registerApi(
actions: Api,
{ipcMain: instance}: { ipcMain?: Pick<IpcMain, "addListener" | "removeListener" | "emit"> } = {},
{ipcMain: instance, logger}: { ipcMain?: Pick<IpcMain, "addListener" | "removeListener" | "emit">; logger?: Model.Logger } = {},
) {
const ipcMain = instance || require("electron").ipcMain;
const em: Model.CombinedEventEmitter = {
Expand All @@ -16,7 +16,7 @@ export class IpcMainApiService<Api extends Model.ActionsRecord<Extract<keyof Api
};
const requestResolver: Model.RequestResolver = ({sender}, payload) => ({payload, emitter: {emit: sender.send.bind(sender)}});

return this.register(actions, em, {requestResolver});
return this.register(actions, em, {requestResolver, logger});
}

public buildClient(
Expand Down
7 changes: 5 additions & 2 deletions src/lib/webview-api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {AnyType} from "./model";
export class WebViewApiService<Api extends Model.ActionsRecord<Extract<keyof Api, string>>> extends Service<Api> {
public registerApi(
actions: Api,
{ipcRenderer: instance}: { ipcRenderer?: Pick<IpcRenderer, "on" | "removeListener" | "sendToHost">; } = {},
{ipcRenderer: instance, logger}: {
ipcRenderer?: Pick<IpcRenderer, "on" | "removeListener" | "sendToHost">;
logger?: Model.Logger;
} = {},
) {
const ipcRenderer = instance || require("electron").ipcRenderer;
const em: Model.CombinedEventEmitter = {
Expand All @@ -21,7 +24,7 @@ export class WebViewApiService<Api extends Model.ActionsRecord<Extract<keyof Api
},
};

return this.register(actions, em);
return this.register(actions, em, {logger});
}

public buildClient(webView: Electron.WebviewTag, {options}: { options?: Model.CallOptions } = {}) {
Expand Down

0 comments on commit 5c4cc82

Please sign in to comment.