Skip to content

Commit

Permalink
Merge pull request #13 from RobotlegsJS/improvements
Browse files Browse the repository at this point in the history
Improvements 🚀
  • Loading branch information
tiagoschenkel authored Sep 15, 2017
2 parents 82ec6e7 + bdb861a commit 8d82ca6
Show file tree
Hide file tree
Showing 21 changed files with 550 additions and 337 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.nyc_output
build
lib
node_modules
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea
/.nyc_output
/.vscode
/coverage
/dist
Expand Down Expand Up @@ -26,5 +27,6 @@ yarn.lock
.gitignore
.istanbul.yml
.npmignore
.prettierrc
.publishrc
.travis.yml
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "none",
"bracketSpacing": true
}
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
language: node_js
node_js:
- stable
env:
- CODECLIMATE_REPO_TOKEN=799dc304c4c444478251dbae6dcb20ec4cb68e46daebf2d08886c1dea12305e5
- CODECLIMATE_API_HOST=https://codebeat.co/webhooks/code_coverage CODECLIMATE_REPO_TOKEN=05eace5c-4cc7-45b6-a238-9d60a4c94cb5
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
Expand All @@ -11,11 +14,8 @@ before_install:
before_script:
- greenkeeper-lockfile-update
script:
- node_modules/karma/bin/karma start karma.conf.js --single-run
- yarn run test
after_script:
- greenkeeper-lockfile-upload
after_success:
- codeclimate-test-reporter < coverage/lcov.info
addons:
code_climate:
repo_token: 799dc304c4c444478251dbae6dcb20ec4cb68e46daebf2d08886c1dea12305e5
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ RobotlegsJS SignalCommandMap Extension

[![Gitter chat](https://badges.gitter.im/RobotlegsJS/RobotlegsJS.svg)](https://gitter.im/RobotlegsJS/RobotlegsJS)
[![Build Status](https://secure.travis-ci.org/RobotlegsJS/RobotlegsJS-SignalCommandMap.svg?branch=master)](https://travis-ci.org/RobotlegsJS/RobotlegsJS-SignalCommandMap)
[![Code Climate](https://codeclimate.com/github/RobotlegsJS/RobotlegsJS-SignalCommandMap/badges/gpa.svg)](https://codeclimate.com/github/RobotlegsJS/RobotlegsJS-SignalCommandMap)
[![codebeat badge](https://codebeat.co/badges/05eace5c-4cc7-45b6-a238-9d60a4c94cb5)](https://codebeat.co/projects/github-com-robotlegsjs-robotlegsjs-signalcommandmap-master)
[![Test Coverage](https://codeclimate.com/github/RobotlegsJS/RobotlegsJS-SignalCommandMap/badges/coverage.svg)](https://codeclimate.com/github/RobotlegsJS/RobotlegsJS-SignalCommandMap/coverage)
[![npm version](https://badge.fury.io/js/%40robotlegsjs%2Fsignalcommandmap.svg)](https://badge.fury.io/js/%40robotlegsjs%2Fsignalcommandmap)
[![Greenkeeper badge](https://badges.greenkeeper.io/RobotlegsJS/RobotlegsJS-SignalCommandMap.svg)](https://greenkeeper.io/)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

A port of Robotlegs Extensions SignalCommandMap to TypeScript.
52 changes: 38 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,34 @@
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"test": "karma start --single-run",
"mocha": "mocha test/**/*.test.ts --require ts-node/register",
"autoformat": "tsfmt -r --useTsconfig tsconfig.test.json",
"test": "nyc mocha",
"karma": "karma start --single-run",
"autoformat": "prettier --config .prettierrc --write {src,test}/**/*.ts",
"tslint-check": "tslint-config-prettier-check ./tslint.json",
"clean-up": "rm -rf coverage && rm -rf lib",
"prepublish": "tsc -d && publish-please guard",
"publish-please": "npm run autoformat && npm run clean-up && publish-please"
},
"nyc": {
"include": [
"src/**/*.ts"
],
"exclude": [
"test"
],
"extension": [
".ts"
],
"require": [
"ts-node/register"
],
"reporter": [
"text-summary",
"lcov"
],
"sourceMap": true,
"instrument": true
},
"repository": {
"type": "git",
"url": "[email protected]:RobotlegsJS/RobotlegsJS-SignalCommandMap.git"
Expand Down Expand Up @@ -39,13 +60,13 @@
"@robotlegsjs/signals": "^0.0.10"
},
"devDependencies": {
"@types/bluebird": "^3.5.8",
"@types/bluebird": "^3.5.11",
"@types/chai": "^4.0.4",
"@types/mocha": "^2.2.42",
"@types/sinon": "^2.3.3",
"@types/mocha": "^2.2.43",
"@types/sinon": "^2.3.4",
"bluebird": "^3.5.0",
"browserify-versionify": "^1.0.6",
"chai": "^4.1.1",
"chai": "^4.1.2",
"es6-map": "^0.1.5",
"es6-symbol": "^3.1.1",
"glslify": "^6.1.0",
Expand All @@ -67,20 +88,23 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-sourcemap-writer": "^0.1.2",
"karma-webpack": "^2.0.4",
"mocha": "^3.5.0",
"mocha": "^3.5.3",
"nyc": "^11.2.1",
"prettier": "^1.7.0",
"publish-please": "^2.3.1",
"reflect-metadata": "^0.1.10",
"remap-istanbul": "^0.9.5",
"rimraf": "^2.6.1",
"rimraf": "^2.6.2",
"sinon": "^3.2.1",
"sinon-chai": "^2.13.0",
"ts-loader": "^2.3.4",
"source-map-support": "^0.4.18",
"ts-loader": "^2.3.7",
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"typescript": "^2.5.1",
"typescript-formatter": "^6.0.0",
"webpack": "^3.5.5",
"webpack-dev-server": "^2.7.1"
"tslint-config-prettier": "^1.5.0",
"typescript": "^2.5.2",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.8.2"
},
"peerDependencies": {
"reflect-metadata": "^0.1.10"
Expand Down
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
/**
* SignalCommandMap Extension
*/
export { ISignalCommandMap } from "./robotlegs/bender/extensions/signalCommandMap/api/ISignalCommandMap";
export { SignalCommandMap } from "./robotlegs/bender/extensions/signalCommandMap/impl/SignalCommandMap";
export { SignalCommandTrigger } from "./robotlegs/bender/extensions/signalCommandMap/impl/SignalCommandTrigger";
export { SignalCommandMapExtension } from "./robotlegs/bender/extensions/signalCommandMap/SignalCommandMapExtension";
export {
ISignalCommandMap
} from "./robotlegs/bender/extensions/signalCommandMap/api/ISignalCommandMap";
export {
SignalCommandMap
} from "./robotlegs/bender/extensions/signalCommandMap/impl/SignalCommandMap";
export {
SignalCommandTrigger
} from "./robotlegs/bender/extensions/signalCommandMap/impl/SignalCommandTrigger";
export {
SignalCommandMapExtension
} from "./robotlegs/bender/extensions/signalCommandMap/SignalCommandMapExtension";
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import {
PrioritySignal
} from "@robotlegsjs/signals";

import {
injectable,
IContext,
IExtension,
UID
} from "@robotlegsjs/core";
import { injectable, IContext, IExtension, UID } from "@robotlegsjs/core";

import { ISignalCommandMap } from "./api/ISignalCommandMap";
import { SignalCommandMap } from "./impl/SignalCommandMap";
Expand All @@ -31,7 +26,6 @@ injectable()(DeluxeSignal);
injectable()(PrioritySignal);

export class SignalCommandMapExtension implements IExtension {

/*============================================================================*/
/* Private Properties */
/*============================================================================*/
Expand All @@ -43,7 +37,10 @@ export class SignalCommandMapExtension implements IExtension {
/*============================================================================*/

public extend(context: IContext): void {
context.injector.bind(ISignalCommandMap).to(SignalCommandMap).inSingletonScope();
context.injector
.bind(ISignalCommandMap)
.to(SignalCommandMap)
.inSingletonScope();
}

public toString(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import {
ICommandMapper,
ICommandUnmapper
} from "@robotlegsjs/core";
import { ICommandMapper, ICommandUnmapper } from "@robotlegsjs/core";

/**
* The Signal Command Map allows you to bind Signals to Commands
*/
export let ISignalCommandMap = Symbol("ISignalCommandMap");
export interface ISignalCommandMap {

/**
* Creates a mapping for a Signal based trigger
* @param signalClass The concrete Signal class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { SignalCommandTrigger } from "./SignalCommandTrigger";
*/
@injectable()
export class SignalCommandMap implements ISignalCommandMap {

/*============================================================================*/
/* Private Properties */
/*============================================================================*/
Expand All @@ -45,12 +44,13 @@ export class SignalCommandMap implements ISignalCommandMap {
/**
* @private
*/
constructor(
@inject(IContext) context: IContext
) {
constructor(@inject(IContext) context: IContext) {
this._injector = context.injector;
this._logger = context.getLogger(this);
this._triggerMap = new CommandTriggerMap(this.getKey, this.createTrigger.bind(this));
this._triggerMap = new CommandTriggerMap(
this.getKey,
this.createTrigger.bind(this)
);
}

/*============================================================================*/
Expand All @@ -72,8 +72,10 @@ export class SignalCommandMap implements ISignalCommandMap {
}

public addMappingProcessor(handler: Function): ISignalCommandMap {
if (this._mappingProcessors.indexOf(handler) === -1)
if (this._mappingProcessors.indexOf(handler) === -1) {
this._mappingProcessors.push(handler);
}

return this;
}

Expand All @@ -82,7 +84,11 @@ export class SignalCommandMap implements ISignalCommandMap {
/*============================================================================*/

private createTrigger(signalClass: Object): ICommandTrigger {
return new SignalCommandTrigger(this._injector, signalClass, this._mappingProcessors);
return new SignalCommandTrigger(
this._injector,
signalClass,
this._mappingProcessors
);
}

private getTrigger(signalClass: Object): SignalCommandTrigger {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { ISignal } from "@robotlegsjs/signals";
* @private
*/
export class SignalCommandTrigger implements ICommandTrigger {

/*============================================================================*/
/* Private Properties */
/*============================================================================*/
Expand All @@ -44,11 +43,19 @@ export class SignalCommandTrigger implements ICommandTrigger {
/**
* @private
*/
constructor(injector: IInjector, signalClass: any, processors?: Function[], logger?: ILogger) {
constructor(
injector: IInjector,
signalClass: any,
processors?: Function[],
logger?: ILogger
) {
this._injector = injector;
this._signalClass = signalClass;
this._mappings = new CommandMappingList(this, processors, logger);
this._executor = new CommandExecutor(injector, this._mappings.removeMapping);
this._executor = new CommandExecutor(
injector,
this._mappings.removeMapping
);
}

/*============================================================================*/
Expand All @@ -67,7 +74,10 @@ export class SignalCommandTrigger implements ICommandTrigger {
*/
public activate(): void {
if (!this._injector.isBound(this._signalClass)) {
this._injector.bind(this._signalClass).to(this._signalClass).inSingletonScope();
this._injector
.bind(this._signalClass)
.to(this._signalClass)
.inSingletonScope();
// this._injector.map(this._signalClass).asSingleton();
}
this._signal = this._injector.get<ISignal>(this._signalClass);
Expand All @@ -92,7 +102,10 @@ export class SignalCommandTrigger implements ICommandTrigger {
/*============================================================================*/

private routePayloadToCommands = (...valueObjects): void => {
let payload: CommandPayload = new CommandPayload(valueObjects, this._signal.valueClasses);
let payload: CommandPayload = new CommandPayload(
valueObjects,
this._signal.valueClasses
);
this._executor.executeCommands(this._mappings.getList(), payload);
}
};
}
6 changes: 6 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--compilers ts-node/register
--require source-map-support/register
--full-trace
--bail
node_modules/reflect-metadata/Reflect.js
test/**/*.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { TargetCommand } from "./support/TargetCommand";
import { TargetSignal } from "./support/TargetSignal";

describe("SignalCommandMapExtension", () => {

let context: Context;

beforeEach(() => {
Expand All @@ -47,7 +46,9 @@ describe("SignalCommandMapExtension", () => {
context.install(SignalCommandMapExtension);
context.initialize();

let instance: ISignalCommandMap = context.injector.get<ISignalCommandMap>(ISignalCommandMap);
let instance: ISignalCommandMap = context.injector.get<
ISignalCommandMap
>(ISignalCommandMap);

instance.map(RelaySignal).toCommand(RelayCommand);
instance.map(TargetSignal).toCommand(TargetCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { injectable } from "inversify";

@injectable()
export class Data {

protected _value: number;

constructor(value: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import { TargetSignal } from "./TargetSignal";

@injectable()
export class RelayCommand implements ICommand {
@inject(Data) private _data: Data;

@inject(Data)
private _data: Data;

@inject(TargetSignal)
private _targetSignal: TargetSignal;
@inject(TargetSignal) private _targetSignal: TargetSignal;

public execute(): void {
this._targetSignal.dispatch(this._data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Data } from "./Data";

@injectable()
export class RelaySignal extends Signal {

constructor() {
super(Data);
}
Expand Down
Loading

0 comments on commit 8d82ca6

Please sign in to comment.