Skip to content

Commit

Permalink
Fix ts errors in lib/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
LabhanshAgrawal authored and Stanzilla committed Oct 13, 2019
1 parent 187897a commit d2a318d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {ipcRenderer, remote} from 'electron';

const plugins = remote.require('./plugins');
const plugins = remote.require('./plugins') as typeof import('../../app/plugins');

export function getConfig() {
return plugins.getDecoratedConfig();
}

export function subscribe(fn) {
export function subscribe(fn: (event: Electron.IpcRendererEvent, ...args: any[]) => void) {
ipcRenderer.on('config change', fn);
ipcRenderer.on('plugins change', fn);
return () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* as the result of an action being triggered.
*/

export default () => next => action => {
export default () => (next: (arg0: any) => any) => (action: {effect: () => void}) => {
const ret = next(action);
if (action.effect) {
action.effect();
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/notify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint no-new:0 */
export default function notify(title, body, details = {}) {
export default function notify(title: string, body: string, details: Record<string, any> = {}) {
//eslint-disable-next-line no-console
console.log(`[Notification] ${title}: ${body}`);
if (details.error) {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/object.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const valsCache = new WeakMap();

export function values(imm) {
export function values(imm: Record<string, any>) {
if (!valsCache.has(imm)) {
valsCache.set(imm, Object.values(imm));
}
return valsCache.get(imm);
}

const keysCache = new WeakMap();
export function keys(imm) {
export function keys(imm: Record<string, any>) {
if (!keysCache.has(imm)) {
keysCache.set(imm, Object.keys(imm));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/paste.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {clipboard} from 'electron';
import plist from 'plist';

const getPath = platform => {
const getPath = (platform: string) => {
switch (platform) {
case 'darwin': {
if (clipboard.has('NSFilenamesPboardType')) {
// Parse plist file containing the path list of copied files
const list = plist.parse(clipboard.read('NSFilenamesPboardType'));
const list = plist.parse(clipboard.read('NSFilenamesPboardType')) as plist.PlistArray;
return "'" + list.join("' '") + "'";
} else {
return null;
Expand Down
22 changes: 13 additions & 9 deletions lib/utils/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {EventEmitter} from 'events';
import {IpcRenderer, IpcRendererEvent} from 'electron';
import electron from 'electron';
export default class Client {
emitter: EventEmitter;
ipc: IpcRenderer;
id!: string;
constructor() {
const electron = window.require('electron');
const EventEmitter = window.require('events');
this.emitter = new EventEmitter();
this.ipc = electron.ipcRenderer;
this.ipcListener = this.ipcListener.bind(this);
Expand All @@ -12,7 +16,7 @@ export default class Client {
this.emitter.emit('ready');
}, 0);
} else {
this.ipc.on('init', (ev, uid) => {
this.ipc.on('init', (ev: IpcRendererEvent, uid: string) => {
// we cache so that if the object
// gets re-instantiated we don't
// wait for a `init` event
Expand All @@ -24,26 +28,26 @@ export default class Client {
}
}

ipcListener(event, {ch, data}) {
ipcListener(event: any, {ch, data}: {ch: string; data: any}) {
this.emitter.emit(ch, data);
}

on(ev, fn) {
on(ev: string, fn: (...args: any[]) => void) {
this.emitter.on(ev, fn);
}

once(ev, fn) {
once(ev: string, fn: (...args: any[]) => void) {
this.emitter.once(ev, fn);
}

emit(ev, data) {
emit(ev: string, data: any) {
if (!this.id) {
throw new Error('Not ready');
}
this.ipc.send(this.id, {ev, data});
}

removeListener(ev, fn) {
removeListener(ev: string, fn: (...args: any[]) => void) {
this.emitter.removeListener(ev, fn);
}

Expand All @@ -53,6 +57,6 @@ export default class Client {

destroy() {
this.removeAllListeners();
this.ipc.removeAllListeners();
this.ipc.removeAllListeners(this.id);
}
}
5 changes: 4 additions & 1 deletion lib/utils/term-groups.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default function findBySession(termGroupState, sessionUid) {
import {ITermState} from '../hyper';
import {Immutable} from 'seamless-immutable';

export default function findBySession(termGroupState: Immutable<ITermState>, sessionUid: string) {
const {termGroups} = termGroupState;
return Object.keys(termGroups)
.map(uid => termGroups[uid])
Expand Down

0 comments on commit d2a318d

Please sign in to comment.