refactor: extract types that are shared

This commit is contained in:
Anthony Laibe 2018-11-22 10:46:10 +00:00 committed by Iuri Matias
parent db35d7f573
commit 8f59647f36
5 changed files with 31 additions and 27 deletions

View File

@ -6,26 +6,13 @@ const EmbarkJS = require("embarkjs");
const IpfsApi = require("ipfs-api");
const stringify = require("json-stringify-safe");
import Web3 from "web3";
import { Embark, Events } from "../../../typings/embark";
import Suggestions from "./suggestions";
declare const __: any;
interface Events {
on: any;
request: any;
emit: any;
once: any;
setCommandHandler: any;
}
interface EmbarkApi {
events: Events;
registerAPICall: any;
registerConsoleCommand: any;
}
class Console {
private embark: EmbarkApi;
private embark: Embark;
private events: Events;
private plugins: any;
private version: string;
@ -36,7 +23,7 @@ class Console {
private cmdHistoryFile: string;
private suggestions: Suggestions;
constructor(embark: any, options: any) {
constructor(embark: Embark, options: any) {
this.embark = embark;
this.events = options.events;
this.plugins = options.plugins;

View File

@ -1,14 +1,6 @@
const fuzzySearch = require("../../utils/utils").fuzzySearch;
interface Events {
on: any;
request: any;
}
interface EmbarkApi {
events: Events;
registerAPICall: any;
}
import { Embark, Events } from "../../../typings/embark";
interface ContractsManager {
[key: string]: any;
@ -23,11 +15,11 @@ interface Suggestion {
type SuggestionsList = Suggestion[];
export default class Suggestions {
private embark: EmbarkApi;
private embark: Embark;
private events: Events;
private contracts: ContractsManager;
constructor(embark: EmbarkApi, options?: object) {
constructor(embark: Embark, options?: object) {
this.embark = embark;
this.events = embark.events;
this.contracts = {};

18
src/typings/embark.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
import { Logger } from "./logger";
export interface Events {
on: any;
request: any;
emit: any;
once: any;
setCommandHandler: any;
}
export interface Embark {
events: Events;
registerAPICall: any;
registerConsoleCommand: any;
logger: Logger;
config: {};
registerActionForEvent(name: string, action: (callback: () => void) => void): void;
}

3
src/typings/embarkConfig.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export interface EmbarkConfig {
contracts: [string];
}

4
src/typings/logger.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
export interface Logger {
info(text: string): void;
error(text: string): void;
}