Skip to content

Commit

Permalink
fix(types): fix the type declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
run-nan committed Sep 2, 2021
1 parent 12ec4e3 commit f44f09a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 33 deletions.
9 changes: 4 additions & 5 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ declare global {
}
}
declare const Obvious: {
createBus: (name: string) => Bus;
getBus: (name: string) => Bus;
createBus: (name?: string) => Bus;
getBus: (name?: string) => Bus;
touchBus: (name?: string) => [Bus, boolean];
};
export { Bus } from './lib/bus';
export { Bus, createBus, getBus, touchBus } from './lib/bus';
export { App } from './lib/app';
export { Socket } from './lib/socket';
export { createBus } from './lib/createBus';
export { getBus } from './lib/createBus';
export default Obvious;
20 changes: 7 additions & 13 deletions dist/lib/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { CustomCtxType } from './types';
declare type CallbackType = (config?: any) => Promise<void>;
declare type DependenciesType = Array<{
ctx: CustomCtxType;
config: any;
} | string>;
import { CustomCtxType, LifecyleCallbackType, DependenciesType } from './types';
export declare class App {
name: string;
dependenciesReady: boolean;
bootstrapped: boolean;
dependencies: DependenciesType;
doBootstrap?: CallbackType;
doActivate?: CallbackType;
doDestroy?: CallbackType;
doBootstrap?: LifecyleCallbackType;
doActivate?: LifecyleCallbackType;
doDestroy?: LifecyleCallbackType;
constructor(name: string);
/**
* indicate the apps to be started before your app is bootstrapped
Expand All @@ -22,17 +17,16 @@ export declare class App {
* indicate the callback your app will run when it's activated the first time
* @param {function} callback
*/
bootstrap(callback: CallbackType): this;
bootstrap(callback: LifecyleCallbackType): this;
/**
* indicate the callback your app will run when it's activated after the first time
* @param callback
*/
activate(callback: CallbackType): this;
activate(callback: LifecyleCallbackType): this;
/**
* indicate the callback when your app is destroyed
* @param callback
*/
destroy(callback: CallbackType): this;
destroy(callback: LifecyleCallbackType): this;
activateDependenciesApp(activateApp: (ctx: CustomCtxType, config?: any) => Promise<void>): Promise<void>;
}
export {};
18 changes: 18 additions & 0 deletions dist/lib/bus.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,21 @@ export declare class Bus {
*/
destroyApp(name: string, config?: any): Promise<void>;
}
export declare const DEFAULT_BUS_NAME = "__DEFAULT_BUS__";
/**
* create a bus and record it on window.__Bus__
* @param name the name of the bus
*/
export declare const createBus: (name?: string) => Bus;
/**
* get the bus from window.__Bus__
* @param name the name of the bus
* @returns
*/
export declare const getBus: (name?: string) => Bus;
/**
* get the bus from window.__Bus__, if the bus is not created, then create it
* @param name the name of the bus
* @returns
*/
export declare const touchBus: (name?: string) => [Bus, boolean];
3 changes: 0 additions & 3 deletions dist/lib/createBus.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion dist/lib/event-emitter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export declare class EventEmitter {
removeBroadcastEventListener(event: string, callback: CallbackType): void;
removeUnicastEventListener(event: string, callback: CallbackType): void;
emitBroadcast(event: string, ...args: any[]): void;
emitUnicast(event: string, ...args: any[]): void;
emitUnicast(event: string, ...args: any[]): any;
}
12 changes: 10 additions & 2 deletions dist/lib/loader.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export declare const loadJs: (src: string) => Promise<void>;
export declare const loadCss: (href: string) => void;
import { ScriptType, LinkType } from './types';
export declare const loadJs: (scriptDeclare: ScriptType) => Promise<void>;
export declare const loadCss: (linkDeclare: LinkType) => void;
export declare const fetchJs: (src: string) => Promise<string>;
export declare const excuteCode: (code: string) => void;
declare const _default: {
loadJs: (scriptDeclare: ScriptType) => Promise<void>;
loadCss: (linkDeclare: LinkType) => void;
fetchJs: (src: string) => Promise<string>;
excuteCode: (code: string) => void;
};
export default _default;
2 changes: 1 addition & 1 deletion dist/lib/socket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export declare class Socket {
* @param eventName
* @param args
*/
unicast(eventName: string, ...args: any[]): void;
unicast(eventName: string, ...args: any[]): any;
/**
* judge if state has been initialized
* @param stateName
Expand Down
25 changes: 19 additions & 6 deletions dist/lib/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
export declare type CallbackType = (...args: any[]) => void;
export declare type CallbackType = (...args: any[]) => any;
export declare type ScriptType = {
src: string;
[attr: string]: any;
} | string;
export declare type LinkType = {
href: string;
[attr: string]: any;
} | string;
export declare type AssetsConfigType = Record<string, {
js?: string[];
css?: string[];
js?: ScriptType[];
css?: LinkType[];
isLib?: boolean;
}>;
export declare type ConfType = {
Expand All @@ -11,9 +19,9 @@ export declare type ConfType = {
};
export declare type ContextType = {
name: string;
loadJs: (src: string) => Promise<void>;
loadCss: (src: string) => void;
fetchJs: (src: string) => Promise<string>;
loadJs: (script: ScriptType) => Promise<void>;
loadCss: (link: LinkType) => void;
fetchJs: (script: ScriptType) => Promise<string>;
excuteCode: (code: string) => void;
conf: ConfType;
[key: string]: any;
Expand All @@ -24,3 +32,8 @@ export declare type CustomCtxType = {
} | string;
export declare type NextFnType = (ctx?: ContextType) => void | Promise<void>;
export declare type MiddlewareFnType = (ctx?: ContextType, next?: NextFnType) => void | Promise<void>;
export declare type LifecyleCallbackType = (config?: any) => Promise<void>;
export declare type DependenciesType = Array<{
ctx: CustomCtxType;
config: any;
} | string>;
2 changes: 1 addition & 1 deletion dist/lib/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export declare const get: (rootState: object | any[], stateLink: (string | numbe
export declare const set: (rootStateName: string, rootState: object, subStateLink: (string | number)[], value: any) => boolean;
export declare const getResolvedStates: (stateName: string, events: string[]) => any[];
/**
* the koa-compose function
* the compose function from koa-compose
* @param middlewares
* @returns
*/
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"allowJs": false, /* Allow javascript files to be compiled. */
// "checkJs": false, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": false, /* Generates corresponding '.d.ts' file. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationDir": "./types",
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down

0 comments on commit f44f09a

Please sign in to comment.