Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Prettier Rules #40

Merged
merged 3 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 80,
"printWidth": 140,
"tabWidth": 4,
"useTabs": false,
"semi": true,
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- [ ] Update **Prettier** rules:

- [ ] **printWidth** should be around **140** characters per line.
- [x] **printWidth** should be around **140** characters per line.

- [ ] Find a way to keep a new line between **@inject** anotation and property declarations.

Expand All @@ -18,6 +18,8 @@

### v0.1.1

- Update Prettier rules (see #40).

- Update CODEBEAT project UUID (see #39).

- Update codeclimate settings (see #38).
Expand Down
32 changes: 8 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,13 @@
/**
* Macrobot Utility
*/
export {
IAsyncCommand
} from "./robotlegs/bender/utilities/macrobot/api/IAsyncCommand";
export { IAsyncCommand } from "./robotlegs/bender/utilities/macrobot/api/IAsyncCommand";
export { IMacro } from "./robotlegs/bender/utilities/macrobot/api/IMacro";
export {
ISubCommandMapping
} from "./robotlegs/bender/utilities/macrobot/api/ISubCommandMapping";
export {
ISubCommandPayload
} from "./robotlegs/bender/utilities/macrobot/api/ISubCommandPayload";
export { ISubCommandMapping } from "./robotlegs/bender/utilities/macrobot/api/ISubCommandMapping";
export { ISubCommandPayload } from "./robotlegs/bender/utilities/macrobot/api/ISubCommandPayload";

export {
AbstractMacro
} from "./robotlegs/bender/utilities/macrobot/impl/AbstractMacro";
export {
AsyncCommand
} from "./robotlegs/bender/utilities/macrobot/impl/AsyncCommand";
export {
ParallelMacro
} from "./robotlegs/bender/utilities/macrobot/impl/ParallelMacro";
export {
SequenceMacro
} from "./robotlegs/bender/utilities/macrobot/impl/SequenceMacro";
export {
SubCommandPayload
} from "./robotlegs/bender/utilities/macrobot/impl/SubCommandPayload";
export { AbstractMacro } from "./robotlegs/bender/utilities/macrobot/impl/AbstractMacro";
export { AsyncCommand } from "./robotlegs/bender/utilities/macrobot/impl/AsyncCommand";
export { ParallelMacro } from "./robotlegs/bender/utilities/macrobot/impl/ParallelMacro";
export { SequenceMacro } from "./robotlegs/bender/utilities/macrobot/impl/SequenceMacro";
export { SubCommandPayload } from "./robotlegs/bender/utilities/macrobot/impl/SubCommandPayload";
5 changes: 1 addition & 4 deletions src/robotlegs/bender/utilities/macrobot/api/IMacro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { ICommand } from "@robotlegsjs/core";
import { ISubCommandMapper } from "../dsl/ISubCommandMapper";
import { ISubCommandUnMapper } from "../dsl/ISubCommandUnMapper";

export interface IMacro
extends ICommand,
ISubCommandMapper,
ISubCommandUnMapper {
export interface IMacro extends ICommand, ISubCommandMapper, ISubCommandUnMapper {
prepare(): void;
}
53 changes: 16 additions & 37 deletions src/robotlegs/bender/utilities/macrobot/impl/AbstractMacro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@

import { interfaces, ContainerModule } from "inversify";

import {
inject,
injectable,
IClass,
ICommand,
IInjector,
IContext,
applyHooks,
guardsApprove
} from "@robotlegsjs/core";
import { inject, injectable, IClass, ICommand, IInjector, IContext, applyHooks, guardsApprove } from "@robotlegsjs/core";

import { IAsyncCommand } from "../api/IAsyncCommand";
import { IMacro } from "../api/IMacro";
Expand All @@ -35,10 +26,7 @@ export abstract class AbstractMacro extends AsyncCommand implements IMacro {
protected _mappings: SubCommandMappingList;
protected _payloadsModule: ContainerModule;

constructor(
@inject(IContext) context: IContext,
@inject(IInjector) injector: IInjector
) {
constructor(@inject(IContext) context: IContext, @inject(IInjector) injector: IInjector) {
super(context);

this._injector = injector.createChild();
Expand Down Expand Up @@ -68,10 +56,7 @@ export abstract class AbstractMacro extends AsyncCommand implements IMacro {
this.mapPayloads(payloads);
}

if (
mapping.guards.length === 0 ||
guardsApprove(mapping.guards, this._injector)
) {
if (mapping.guards.length === 0 || guardsApprove(mapping.guards, this._injector)) {
command = mapping.getOrCreateCommandInstance(this._injector);

if (mapping.hooks.length > 0) {
Expand All @@ -86,14 +71,10 @@ export abstract class AbstractMacro extends AsyncCommand implements IMacro {
}

if (command) {
let isAsync: boolean =
command.constructor.prototype.registerCompleteCallback !==
undefined;
let isAsync: boolean = command.constructor.prototype.registerCompleteCallback !== undefined;

if (isAsync) {
(<IAsyncCommand>command).registerCompleteCallback(
this.commandCompleteHandler.bind(this)
);
(<IAsyncCommand>command).registerCompleteCallback(this.commandCompleteHandler.bind(this));
}

command.execute();
Expand All @@ -107,19 +88,17 @@ export abstract class AbstractMacro extends AsyncCommand implements IMacro {
}

protected mapPayloads(payloads: Array<ISubCommandPayload<any>>): void {
this._payloadsModule = new ContainerModule(
(bind: interfaces.Bind, unbind: interfaces.Unbind) => {
payloads.forEach((payload: ISubCommandPayload<any>) => {
if (payload.name.length > 0) {
bind(payload.type)
.toConstantValue(payload.data)
.whenTargetNamed(payload.name);
} else {
bind(payload.type).toConstantValue(payload.data);
}
});
}
);
this._payloadsModule = new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind) => {
payloads.forEach((payload: ISubCommandPayload<any>) => {
if (payload.name.length > 0) {
bind(payload.type)
.toConstantValue(payload.data)
.whenTargetNamed(payload.name);
} else {
bind(payload.type).toConstantValue(payload.data);
}
});
});
this._injector.load(this._payloadsModule);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ export abstract class ParallelMacro extends AbstractMacro implements IMacro {
this._executionCount++;
this._success = this._success && success;

if (
this._running &&
(!this._success || this._executionCount === this._commands.length)
) {
if (this._running && (!this._success || this._executionCount === this._commands.length)) {
this.dispatchComplete(this._success);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export abstract class SequenceMacro extends AbstractMacro implements IMacro {

protected executeNext(): void {
if (this.hasCommands) {
let mapping: ISubCommandMapping = this._commands[
this._executionIndex++
];
let mapping: ISubCommandMapping = this._commands[this._executionIndex++];
this.executeCommand(mapping);
} else {
this.dispatchComplete(this._success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import {
IClass,
ICommand,
IInjector,
instantiateUnmapped
} from "@robotlegsjs/core";
import { IClass, ICommand, IInjector, instantiateUnmapped } from "@robotlegsjs/core";

import { ISubCommandPayload } from "../api/ISubCommandPayload";
import { ISubCommandMapping } from "../api/ISubCommandMapping";
import { ISubCommandConfigurator } from "../dsl/ISubCommandConfigurator";

import { SubCommandPayload } from "./SubCommandPayload";

export class SubCommandMapping
implements ISubCommandMapping, ISubCommandConfigurator {
export class SubCommandMapping implements ISubCommandMapping, ISubCommandConfigurator {
private _commandClass: IClass<ICommand>;

private _guards: any[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import { ISubCommandMappingList } from "../dsl/ISubCommandMappingList";

export class SubCommandMappingList implements ISubCommandMappingList {
private _mappings: ISubCommandMapping[] = [];
private _mappingsByCommand: Map<
IClass<ICommand>,
ISubCommandMapping[]
> = new Map<IClass<ICommand>, ISubCommandMapping[]>();
private _mappingsByCommand: Map<IClass<ICommand>, ISubCommandMapping[]> = new Map<IClass<ICommand>, ISubCommandMapping[]>();

public getList(): ISubCommandMapping[] {
return this._mappings.concat();
Expand All @@ -31,9 +28,7 @@ export class SubCommandMappingList implements ISubCommandMappingList {

public removeMappingsFor(commandClass: IClass<ICommand>): void {
if (this._mappingsByCommand.has(commandClass)) {
let subCommandList: ISubCommandMapping[] = this._mappingsByCommand
.get(commandClass)
.concat();
let subCommandList: ISubCommandMapping[] = this._mappingsByCommand.get(commandClass).concat();
while (subCommandList.length > 0) {
this.deleteMapping(subCommandList.pop());
}
Expand Down Expand Up @@ -66,9 +61,7 @@ export class SubCommandMappingList implements ISubCommandMappingList {

private deleteMapping(mapping: ISubCommandMapping): void {
if (this._mappingsByCommand.has(mapping.commandClass)) {
let subCommandList: ISubCommandMapping[] = this._mappingsByCommand.get(
mapping.commandClass
);
let subCommandList: ISubCommandMapping[] = this._mappingsByCommand.get(mapping.commandClass);

// Ensure that duplicates are removed
subCommandList.concat().forEach((m: ISubCommandMapping) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ describe("ParallelMacro", () => {
});

it("removed_commands_are_not_executed", (done: Function) => {
eventCommandMap
.map("trigger", Event)
.toCommand(TestAddAndRemoveParallelCommand);
eventCommandMap.map("trigger", Event).toCommand(TestAddAndRemoveParallelCommand);
dispatcher.dispatchEvent(new Event("trigger"));
setTimeout(() => {
assert.deepEqual(reported, [
Expand All @@ -104,12 +102,8 @@ describe("ParallelMacro", () => {
}, 250);
});

it("commands_are_executed_in_parallel_and_complete_callback_is_called", (
done: Function
) => {
eventCommandMap
.map("trigger", Event)
.toCommand(TestParallelWithCompleteCallbackCommand);
it("commands_are_executed_in_parallel_and_complete_callback_is_called", (done: Function) => {
eventCommandMap.map("trigger", Event).toCommand(TestParallelWithCompleteCallbackCommand);
dispatcher.dispatchEvent(new Event("trigger"));

setTimeout(() => {
Expand All @@ -130,9 +124,7 @@ describe("ParallelMacro", () => {
});

it("empty_parallel_command_is_still_executed", (done: Function) => {
eventCommandMap
.map("trigger", Event)
.toCommand(TestEmptyParallelCommand);
eventCommandMap.map("trigger", Event).toCommand(TestEmptyParallelCommand);
dispatcher.dispatchEvent(new Event("trigger"));

setTimeout(() => {
Expand Down
Loading