Skip to content

Commit

Permalink
clear log based on setting
Browse files Browse the repository at this point in the history
  • Loading branch information
remojansen committed Jun 28, 2016
1 parent 3d635f6 commit 1985eae
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 90 deletions.
16 changes: 8 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ var tsLibProject = tsc.createProject("tsconfig.json");

gulp.task("build", function() {
return gulp.src([
"./typings/index.d.ts",
"./node_modules/immutable/dist/immutable.d.ts",
"./node_modules/redux-bootstrap/type_definitions/redux-bootstrap/redux-bootstrap.d.ts",
"./node_modules/inversify/type_definitions/inversify/inversify.d.ts",
"./node_modules/inversify-dts/inversify-logger-middleware/inversify-logger-middleware.d.ts",
"./src/interfaces/interfaces.d.ts",
"./src/**/**.ts",
"./src/**/**.tsx"
"typings/index.d.ts",
"node_modules/immutable/dist/immutable.d.ts",
"node_modules/redux-bootstrap/type_definitions/redux-bootstrap/redux-bootstrap.d.ts",
"node_modules/inversify/type_definitions/inversify/inversify.d.ts",
"node_modules/inversify-dts/inversify-logger-middleware/inversify-logger-middleware.d.ts",
"src/interfaces/interfaces.d.ts",
"src/**/**.ts",
"src/**/**.tsx"
])
.pipe(tsc(tsLibProject))
.on("error", function (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/logger_actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeActionCreator } from "../utils/utils";
import ACTION_TYPES from "../constants/action_types";

let addLogEntry = makeActionCreator(ACTION_TYPES.ADD_LOG_ENTRY, "entry");
let addLogEntry = makeActionCreator(ACTION_TYPES.ADD_LOG_ENTRY, "entry", "logSize");
let selectRequest = makeActionCreator(ACTION_TYPES.SELECT_LOG_ENTRY, "entry");
let filterRequests = makeActionCreator(ACTION_TYPES.FILTER_LOG_ENTRIES, "filterBy");
let clearRequests = makeActionCreator(ACTION_TYPES.CLEAR_LOG);
Expand Down
2 changes: 1 addition & 1 deletion src/components/binding_explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BindingExplorer extends React.Component<any, any> {

<div class="title">
<h6>IMPLEMENTATIONS: {keyVal.value.length}</h6>
<h2>{keyVal.serviceIdentifier}</h2>
<h2>{keyVal.serviceIdentifier.toString()}</h2>
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/request_log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RequestLog extends React.Component<any, any> {
}

private _render() {
if (this.props.log.length > 0) {
if (this.props.log.size > 0) {
let entries = this.props.log.map((entry: interfaces.SelectableLogEntry, i: number) => {
return this._renderEntry(entry, i);
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SettingsEditor extends React.Component<any, any> {

private _handleSaveClick() {
let settings = getDefaultSettings();
settings.size = this.state.size;
settings.size = parseInt(this.state.size, null);
this.props.saveSettingsAsync(settings);
}

Expand Down
30 changes: 15 additions & 15 deletions src/core/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ import SelectableLogEntry from "./selectable_log_entry";
import getDefaultSettings from "./default_settings";
import interfaces from "../interfaces/interfaces";

function getUserSettings(): interfaces.UserSettings {
return null;
}

function setUserSettings(settings: interfaces.UserSettings, cb: (e: boolean) => void): void {
return null;
}

function getLogger(
addLogEntry: (entry: interfaces.SelectableLogEntry) => void,
initSettings: (settings: interfaces.UserSettings) => void,
dispatch: Redux.Dispatch
): inversify.interfaces.Middleware {
function getSettings() {

let settings: any = window.localStorage.getItem("inversify_settings");

Expand All @@ -26,14 +14,26 @@ function getLogger(
settings = JSON.parse(settings);
}

return settings;

}

function getLogger(
addLogEntry: (entry: interfaces.SelectableLogEntry, logSize: number) => void,
initSettings: (settings: interfaces.UserSettings) => void,
dispatch: Redux.Dispatch
): inversify.interfaces.Middleware {

let settings = getSettings();

dispatch(initSettings(settings));

let reduxRenderer = function(entry: inversifyLoggerMiddleware.interfaces.LogEntry) {
dispatch(addLogEntry(new SelectableLogEntry(entry)));
dispatch(addLogEntry(new SelectableLogEntry(entry), getSettings().size));
};

let middleware = makeLoggerMiddleware(settings, reduxRenderer);
return middleware;
}

export { getUserSettings, setUserSettings, getLogger };
export { getLogger };
58 changes: 0 additions & 58 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,4 @@ function render(container: string) {
});
}

// TEMP
import "reflect-metadata";
import * as inversify from "inversify";
let win: any = window;
win.inversify = inversify;

interface Weapon {}

@inversify.injectable()
class Katana implements Weapon {}

@inversify.injectable()
class Shuriken implements Weapon {}

interface Warrior {
katana: Weapon;
shuriken: Weapon;
}

@inversify.injectable()
class Ninja implements Warrior {

public katana: Weapon;
public shuriken: Weapon;

public constructor(
@inversify.inject("Weapon") @inversify.named("katana") katana: Weapon,
@inversify.inject("Weapon") @inversify.named("shuriken") shuriken: Weapon
) {
this.katana = katana;
this.shuriken = shuriken;
}
}

let kernel = new inversify.Kernel();

kernel.bind<Warrior>("Warrior").to(Ninja);
kernel.bind<Weapon>("Weapon").to(Katana).whenTargetNamed("katana");
kernel.bind<Weapon>("Weapon").to(Shuriken).whenTargetNamed("shuriken");

win.kernel = kernel;

function demo() {
if (win.__inversifyDevtools__) {
win.__inversifyDevtools__(kernel);
}
kernel.get("ninja");
kernel.get("Warrior");
kernel.get("Weapon");
kernel.getNamed("Weapon", "shuriken");
kernel.getNamed("Weapon", "katana");
}

// setTimeout(function() { demo(); }, 1000);

render("root");
// END TEMP

export default render;
5 changes: 5 additions & 0 deletions src/reducers/log_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const defaultWindowState = Immutable.fromJS({

function addLogEntry(previousState: any, action: any) {
let entries = previousState.get("entries");
if (entries.size === action.logSize) {
let indexToRemove = 0;
let numberToRemove = 1;
entries = entries.splice(indexToRemove, numberToRemove);
}
let updatedEntries = entries.push(action.entry);
return previousState.set("entries", updatedEntries);
}
Expand Down
1 change: 0 additions & 1 deletion test/actions/app_actions.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/components/binding_explorer.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/core/selectable_log_entry.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/reducers/app_reducer.test.ts

This file was deleted.

68 changes: 68 additions & 0 deletions test/stubs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Kernel, injectable, named, inject } from "inversify";
import "reflect-metadata";

let TYPES = {
Warrior: Symbol("Warrior"),
Weapon: Symbol("Weapon")
};

let TAGS = {
katana: "katana",
shuriken: "shuriken",
};

interface Weapon {}

interface Warrior {
katana: Weapon;
shuriken: Weapon;
}

@injectable()
class Katana implements Weapon {}

@injectable()
class Shuriken implements Weapon {}

@injectable()
class Ninja implements Warrior {

public katana: Weapon;
public shuriken: Weapon;

public constructor(
@inject(TYPES.Weapon) @named(TAGS.katana) katana: Weapon,
@inject(TYPES.Weapon) @named(TAGS.shuriken) shuriken: Weapon
) {
this.katana = katana;
this.shuriken = shuriken;
}
}

let kernel = new Kernel();

kernel.bind<Warrior>(TYPES.Warrior).to(Ninja);
kernel.bind<Weapon>(TYPES.Weapon).to(Katana).whenTargetNamed(TAGS.katana);
kernel.bind<Weapon>(TYPES.Weapon).to(Shuriken).whenTargetNamed(TAGS.shuriken);

function useDevtools() {

let win: any = window;
win.kernel = kernel;

if (win.__inversifyDevtools__) {
win.__inversifyDevtools__(kernel);
}

kernel.get("ninja");
kernel.get(TYPES.Warrior);
kernel.get(TYPES.Weapon);
kernel.getNamed(TYPES.Weapon, TAGS.shuriken);
kernel.getNamed(TYPES.Weapon, TAGS.katana);

}

// render("root");
// setTimeout(() => { useDevtools(); }, 1000);

export { useDevtools };
1 change: 0 additions & 1 deletion test/utils/utils.test.ts

This file was deleted.

0 comments on commit 1985eae

Please sign in to comment.