Skip to content

Commit

Permalink
Add API documentation generated by typedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-lozev committed Jun 8, 2018
1 parent 3fe2f33 commit 97cfef3
Show file tree
Hide file tree
Showing 46 changed files with 4,754 additions and 259 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class SearchModule {
## Core concepts

<p align="center">
<img alt="justcore flow" src="https://github.com/valentin-lozev/justcore/blob/master/docs/justcore-diagram.png" />
<img alt="justcore flow" src="https://github.com/valentin-lozev/justcore/blob/master/docs/assets/images/justcore-diagram.png" />
</p>

### Modules
Expand Down
44 changes: 43 additions & 1 deletion dist/justcore.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
declare global {
/**
* @module Core
*/

declare global {
namespace jc {

export interface Func<T = any> {
Expand Down Expand Up @@ -36,36 +40,74 @@
new(): Core;
}

/**
* A mediator object that hooks everything together and runs your application.
*/
export interface Core {
/** Returns current justcore's version. */
version: Readonly<string>;

/** Lists all installed extensions. */
extensions: Readonly<string[]>;

/** Lists all added module ids. */
modules: Readonly<string[]>;

/** Lists all running module instances by their id. */
runningModules: Readonly<{ [id: string]: string[]; }>;

/** The Sandbox class that will be used when core creates sandbox instances. */
Sandbox: SandboxClass;

/** Schedules a list of extensions for installation. */
use(extensions: Extension[]): void;

/** Creates a hook from given method. */
createHook<T extends Func>(type: HookType, method: T, context?: any): T & Hook;

/** Initializes the core. */
init(onInit?: Func<void>): void;

/** Adds a module. */
addModule(id: string, factory: ModuleFactory): void;

/** Starts an instance of given module and initializes it. */
startModule(id: string, options?: ModuleStartOptions): void;

/** Stops a given module instance. */
stopModule(id: string, instanceId?: string): void;

/** Subscribes for messages of given type. */
onMessage(type: string, handler: MessageHandler): Unsubscribe;

/** Publishes a message. */
publishAsync<T extends Message>(message: T): void;
}

export interface SandboxClass {
new(core: Core, moduleId: string, instanceId: string): Sandbox;
}

/**
* Connects the modules to the outside world. Facade of the core.
*/
export interface Sandbox {
/** Id of the module that it serves for. */
moduleId: Readonly<string>;

/** Instance id of the module that it serves for. */
instanceId: Readonly<string>;

/** A reference to the core. It should be used only by extensions. */
_extensionsOnlyCore: Readonly<Core>;

/** Starts an instance of given module and initializes it. */
startModule(id: string, options?: ModuleStartOptions): void;

/** Stops a given module instance. */
stopModule(id: string, instanceId?: string): void;

/** Publishes a message asynchronously. */
publishAsync<T extends Message>(message: T): void;
}

Expand Down
61 changes: 0 additions & 61 deletions dist/justcore.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ if (typeof Array.prototype.reduceRight !== "function") {
};
}

/**
* Encapsulates hooks behavior of the core.
*/
var HooksSystem = /** @class */ (function () {
function HooksSystem() {
this._plugins = Object.create(null);
Expand Down Expand Up @@ -201,9 +198,6 @@ var HooksSystem = /** @class */ (function () {
return HooksSystem;
}());

/**
* Encapsulates communication behavior of the core.
*/
var MessageBus = /** @class */ (function () {
function MessageBus() {
this._subscribers = Object.create(null);
Expand Down Expand Up @@ -251,9 +245,6 @@ var MessageBus = /** @class */ (function () {
return MessageBus;
}());

/**
* Connects the modules to the outside world. Facade of the core.
*/
var Sandbox = /** @class */ (function () {
function Sandbox(core, moduleId, instanceId) {
this._extensionsOnlyCore = core;
Expand All @@ -274,30 +265,18 @@ var Sandbox = /** @class */ (function () {
enumerable: true,
configurable: true
});
/**
* Starts an instance of given module and initializes it.
*/
Sandbox.prototype.startModule = function (id, options) {
this._extensionsOnlyCore.startModule(id, options);
};
/**
* Stops a given module instance.
*/
Sandbox.prototype.stopModule = function (id, instanceId) {
this._extensionsOnlyCore.stopModule(id, instanceId);
};
/**
* Publishes a message asynchronously.
*/
Sandbox.prototype.publishAsync = function (message) {
this._extensionsOnlyCore.publishAsync(message);
};
return Sandbox;
}());

/**
* A mediator between the modules.
*/
var Core = /** @class */ (function () {
function Core(hooksSystem, messageBus) {
if (hooksSystem === void 0) { hooksSystem = new HooksSystem(); }
Expand All @@ -318,39 +297,27 @@ var Core = /** @class */ (function () {
]);
}
Object.defineProperty(Core.prototype, "version", {
/**
* Returns current justcore's version.
*/
get: function () {
return VERSION;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Core.prototype, "extensions", {
/**
* Lists all installed extensions.
*/
get: function () {
return Object.keys(this._extensions);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Core.prototype, "modules", {
/**
* Lists all added module ids.
*/
get: function () {
return Object.keys(this._modules);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Core.prototype, "runningModules", {
/**
* Lists all running module instances by their id.
*/
get: function () {
var _this = this;
return this.modules
Expand All @@ -362,10 +329,6 @@ var Core = /** @class */ (function () {
enumerable: true,
configurable: true
});
/**
* Installs extensions.
* @param extensions
*/
Core.prototype.use = function (extensions) {
var _this = this;
guard
Expand All @@ -380,15 +343,9 @@ var Core = /** @class */ (function () {
_this._extensions[x.name] = x;
});
};
/**
* Creates a hook from given method.
*/
Core.prototype.createHook = function (type, method, context) {
return this._hooksSystem.createHook(type, method, context);
};
/**
* Initializes the core.
*/
Core.prototype.init = function (onInit) {
guard.false(this._isInitialized, "m7");
this._onInit = this.createHook("onCoreInit", onInit || function () { }, this);
Expand All @@ -402,9 +359,6 @@ var Core = /** @class */ (function () {
}
this._isInitialized = true;
};
/**
* Adds a module.
*/
Core.prototype.addModule = function (id, factory) {
guard
.nonEmptyString(id, "m8")
Expand All @@ -415,9 +369,6 @@ var Core = /** @class */ (function () {
instances: Object.create(null)
};
};
/**
* Starts an instance of given module and initializes it.
*/
Core.prototype.startModule = function (id, options) {
if (options === void 0) { options = {}; }
guard.true(this._isInitialized, "m11")
Expand All @@ -444,9 +395,6 @@ var Core = /** @class */ (function () {
console.error(err);
}
};
/**
* Stops a given module instance.
*/
Core.prototype.stopModule = function (id, instanceId) {
var moduleData = this._modules[id];
if (!moduleData) {
Expand All @@ -468,18 +416,9 @@ var Core = /** @class */ (function () {
console.error(err);
}
};
/**
* Subscribes for messages of given type.
* @param messageType
* @param handler
*/
Core.prototype.onMessage = function (type, handler) {
return this._messageBus.onMessage(type, handler);
};
/**
* Publishes a message.
* @param message
*/
Core.prototype.publishAsync = function (message) {
this._messageBus.publishAsync(message);
};
Expand Down
Loading

0 comments on commit 97cfef3

Please sign in to comment.