From 1985eaebd1b576e47e74ae4f4dc1dfd866e64d15 Mon Sep 17 00:00:00 2001 From: remojansen Date: Tue, 28 Jun 2016 23:42:16 +0100 Subject: [PATCH] clear log based on setting --- gulpfile.js | 16 +++--- src/actions/logger_actions.ts | 2 +- src/components/binding_explorer.tsx | 2 +- src/components/request_log.tsx | 2 +- src/components/settings.tsx | 2 +- src/core/logger.ts | 30 +++++------ src/main.tsx | 58 -------------------- src/reducers/log_reducer.ts | 5 ++ test/actions/app_actions.test.ts | 1 - test/components/binding_explorer.test.ts | 1 - test/core/selectable_log_entry.test.ts | 1 - test/reducers/app_reducer.test.ts | 1 - test/stubs.ts | 68 ++++++++++++++++++++++++ test/utils/utils.test.ts | 1 - 14 files changed, 100 insertions(+), 90 deletions(-) delete mode 100644 test/actions/app_actions.test.ts delete mode 100644 test/components/binding_explorer.test.ts delete mode 100644 test/core/selectable_log_entry.test.ts delete mode 100644 test/reducers/app_reducer.test.ts create mode 100644 test/stubs.ts delete mode 100644 test/utils/utils.test.ts diff --git a/gulpfile.js b/gulpfile.js index 3d254c6..2a5e3e1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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) { diff --git a/src/actions/logger_actions.ts b/src/actions/logger_actions.ts index c746031..600dada 100644 --- a/src/actions/logger_actions.ts +++ b/src/actions/logger_actions.ts @@ -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); diff --git a/src/components/binding_explorer.tsx b/src/components/binding_explorer.tsx index 95069c5..50b2a7d 100644 --- a/src/components/binding_explorer.tsx +++ b/src/components/binding_explorer.tsx @@ -51,7 +51,7 @@ class BindingExplorer extends React.Component {
IMPLEMENTATIONS: {keyVal.value.length}
-

{keyVal.serviceIdentifier}

+

{keyVal.serviceIdentifier.toString()}

diff --git a/src/components/request_log.tsx b/src/components/request_log.tsx index c96f72f..2c1cae0 100644 --- a/src/components/request_log.tsx +++ b/src/components/request_log.tsx @@ -20,7 +20,7 @@ class RequestLog extends React.Component { } 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); }); diff --git a/src/components/settings.tsx b/src/components/settings.tsx index 4682aa3..4e3647d 100644 --- a/src/components/settings.tsx +++ b/src/components/settings.tsx @@ -39,7 +39,7 @@ class SettingsEditor extends React.Component { private _handleSaveClick() { let settings = getDefaultSettings(); - settings.size = this.state.size; + settings.size = parseInt(this.state.size, null); this.props.saveSettingsAsync(settings); } diff --git a/src/core/logger.ts b/src/core/logger.ts index 5ee1ab9..042bb4d 100644 --- a/src/core/logger.ts +++ b/src/core/logger.ts @@ -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"); @@ -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 }; diff --git a/src/main.tsx b/src/main.tsx index c00fa13..f6813a2 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -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").to(Ninja); -kernel.bind("Weapon").to(Katana).whenTargetNamed("katana"); -kernel.bind("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; diff --git a/src/reducers/log_reducer.ts b/src/reducers/log_reducer.ts index 8432cca..060a8c9 100644 --- a/src/reducers/log_reducer.ts +++ b/src/reducers/log_reducer.ts @@ -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); } diff --git a/test/actions/app_actions.test.ts b/test/actions/app_actions.test.ts deleted file mode 100644 index 70b786d..0000000 --- a/test/actions/app_actions.test.ts +++ /dev/null @@ -1 +0,0 @@ -// TODO diff --git a/test/components/binding_explorer.test.ts b/test/components/binding_explorer.test.ts deleted file mode 100644 index 70b786d..0000000 --- a/test/components/binding_explorer.test.ts +++ /dev/null @@ -1 +0,0 @@ -// TODO diff --git a/test/core/selectable_log_entry.test.ts b/test/core/selectable_log_entry.test.ts deleted file mode 100644 index 70b786d..0000000 --- a/test/core/selectable_log_entry.test.ts +++ /dev/null @@ -1 +0,0 @@ -// TODO diff --git a/test/reducers/app_reducer.test.ts b/test/reducers/app_reducer.test.ts deleted file mode 100644 index 70b786d..0000000 --- a/test/reducers/app_reducer.test.ts +++ /dev/null @@ -1 +0,0 @@ -// TODO diff --git a/test/stubs.ts b/test/stubs.ts new file mode 100644 index 0000000..ef250f3 --- /dev/null +++ b/test/stubs.ts @@ -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(TYPES.Warrior).to(Ninja); +kernel.bind(TYPES.Weapon).to(Katana).whenTargetNamed(TAGS.katana); +kernel.bind(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 }; diff --git a/test/utils/utils.test.ts b/test/utils/utils.test.ts deleted file mode 100644 index 70b786d..0000000 --- a/test/utils/utils.test.ts +++ /dev/null @@ -1 +0,0 @@ -// TODO