Skip to content

Commit 24e6437

Browse files
committed
Initial commit - Added Global Store and common interfaces
1 parent 97c2ffd commit 24e6437

17 files changed

+1129
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,10 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
353+
# Build bits
354+
/lib/**/**.*
355+
356+
# Code Coverage
357+
/coverage/**/**.*

.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
registry:https://registry.npmjs.org/
2+
always-auth=true
3+
package-lock=false

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Contributing
2+
3+
This project welcomes contributions and suggestions. Most contributions require you to
4+
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
5+
and actually do, grant us the rights to use your contribution. For details, visit
6+
https://cla.microsoft.com.
7+
8+
When you submit a pull request, a CLA-bot will automatically determine whether you need
9+
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
10+
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
11+
12+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
13+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
14+
or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './src/actions';
2+
export * from './src/global.store';
3+
export * from './src/common/interfaces';
4+
export * from './src/common/abstract.logger';
5+
export * from './src/common/interfaces/global.store.interface';

karma.conf.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module.exports = function (config) {
2+
config.set({
3+
frameworks: ["jasmine", "karma-typescript"],
4+
files: [
5+
{ pattern: "src/**/*.ts" },
6+
{ pattern: "test/**/*.ts" }
7+
],
8+
preprocessors: {
9+
"src/**/*.ts": ["karma-typescript"],
10+
"test/**/*.ts": "karma-typescript"
11+
},
12+
reporters: ["progress", "karma-typescript"],
13+
browsers: ["Chrome"],
14+
karmaTypescriptConfig: {
15+
coverageReporter: {
16+
instrumenterOptions: {
17+
istanbul: { noCompact: true }
18+
}
19+
},
20+
bundlerOptions: {
21+
transforms: [
22+
require("karma-typescript-es6-transform")({
23+
presets: [
24+
["env", {
25+
targets: {
26+
chrome: "60"
27+
}
28+
}]
29+
]
30+
})
31+
]
32+
},
33+
compilerOptions: {
34+
module: "commonjs",
35+
sourceMap: true,
36+
target: "es6",
37+
allowJs: false,
38+
declaration: true,
39+
moduleResolution: "node",
40+
skipLibCheck: true,
41+
lib: ["es2017", "DOM"],
42+
downlevelIteration: true
43+
},
44+
typeRoots: [
45+
"node_modules/@types"
46+
],
47+
exclude: [
48+
"node_modules/**/*"
49+
]
50+
},
51+
plugins: ['karma-jasmine', 'karma-chrome-launcher', 'karma-typescript']
52+
});
53+
};

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "redux-micro-frontend",
3+
"version": "0.0.0",
4+
"license": "MIT",
5+
"description": "Light-weight FXP library for managing state using Redux",
6+
"scripts": {
7+
"build": "tsc",
8+
"test": "karma start karma.conf.js",
9+
"release:pre": "npm run build && npm version prerelease && npm run copyfiles:publish",
10+
"release:patch": "npm run build && npm version patch && npm run copyfiles:publish",
11+
"release:minor": "npm run build && npm version minor && npm run copyfiles:publish",
12+
"release:major": "npm run build && npm version major && npm run copyfiles:publish",
13+
"copyfiles:publish": "npm run copy:packagejson && npm run copy:npmrc && cd lib && npm publish",
14+
"copy:packagejson": "cpr package.json lib/package.json -o",
15+
"copy:npmrc": "cpr .npmrc lib/.npmrc -o",
16+
"clean": "rimraf node_modules",
17+
"rebuild": "npm run clean && npm i && npm build"
18+
},
19+
"private": false,
20+
"dependencies": {
21+
"flatted": "^2.0.2",
22+
"redux": "^4.0.5"
23+
},
24+
"devDependencies": {
25+
"@types/jasmine": "^3.5.14",
26+
"cpr": "^3.0.1",
27+
"jasmine": "^3.6.2",
28+
"karma": "^4.4.1",
29+
"karma-chrome-launcher": "^3.1.0",
30+
"karma-coverage": "^2.0.3",
31+
"karma-jasmine": "^3.3.1",
32+
"karma-typescript": "^4.1.1",
33+
"karma-typescript-es6-transform": "^4.1.1",
34+
"rimraf": "^3.0.2",
35+
"typescript": "^3.5.3"
36+
}
37+
}

src/actions/action.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface IAction<Payload = any> {
2+
type: string,
3+
payload: Payload,
4+
logEnabled?: Boolean
5+
}

src/actions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './action.interface';

src/common/abstract.logger.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Summary Logs data from application. Follows a Chain of Responsibility pattern where multiple loggers can be chained.
3+
*/
4+
export abstract class AbstractLogger {
5+
LoggerIdentity: String;
6+
NextLogger: AbstractLogger;
7+
8+
constructor(id: string) {
9+
this.LoggerIdentity = id;
10+
}
11+
12+
/**
13+
* Summary Logs an event
14+
* @param source Location from where the log is sent
15+
* @param eventName Name of the event that has occurred
16+
* @param properties Properties (KV pair) associated with the event
17+
*/
18+
LogEvent(source: string, eventName: string, properties: any) {
19+
try {
20+
this.processEvent(source, eventName, properties);
21+
if (this.NextLogger !== undefined && this.NextLogger !== null) {
22+
this.NextLogger.LogEvent(source, eventName, properties);
23+
}
24+
}
25+
catch {
26+
// DO NOT THROW AN EXCEPTION WHEN LOGGING FAILS
27+
}
28+
}
29+
30+
/**
31+
* Summary Logs an error in the system
32+
* @param source Location where the error has occurred
33+
* @param error Error
34+
* @param properties Custom properties (KV pair)
35+
*/
36+
LogException(source: string, error: Error, properties: any) {
37+
try {
38+
this.processException(source, error, properties);
39+
if (this.NextLogger !== undefined && this.NextLogger !== null) {
40+
this.NextLogger.LogException(source, error, properties);
41+
}
42+
}
43+
catch {
44+
// DO NOT THROW AN EXCEPTION WHEN LOGGING FAILS
45+
}
46+
}
47+
48+
/**
49+
* Summary Sets the next logger in the chain. If the next logger is already filled then its chained to the last logger of the chain
50+
* @param nextLogger Next Logger to be set in the chain
51+
*/
52+
SetNextLogger(nextLogger: AbstractLogger) {
53+
if (nextLogger === undefined || nextLogger === null)
54+
return;
55+
if (!this.isLoggerLoopCreated(nextLogger)) {
56+
if (this.NextLogger === undefined || this.NextLogger === null) {
57+
this.NextLogger = nextLogger;
58+
} else {
59+
this.NextLogger.SetNextLogger(nextLogger);
60+
}
61+
}
62+
}
63+
64+
private isLoggerLoopCreated(nextLogger: AbstractLogger) {
65+
let tmpLogger = {...nextLogger};
66+
do {
67+
if (tmpLogger.LoggerIdentity === this.LoggerIdentity)
68+
return true;
69+
tmpLogger = tmpLogger.NextLogger;
70+
} while (tmpLogger !== null || tmpLogger !== undefined)
71+
return false;
72+
}
73+
74+
abstract processEvent(source: string, eventName: string, properties: any);
75+
abstract processException(source, error: Error, properties: any);
76+
}

src/common/console.logger.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { AbstractLogger } from "./abstract.logger";
2+
3+
export class ConsoleLogger extends AbstractLogger {
4+
constructor(private _debugMode: boolean = false) {
5+
super("DEFAULT_CONSOLE_LOGGER");
6+
this.NextLogger = null;
7+
}
8+
9+
processEvent(source: string, eventName: string, properties: any) {
10+
try {
11+
if (!this._debugMode)
12+
return;
13+
console.log(`EVENT : ${eventName}. (${source})`);
14+
} catch {
15+
// DO NOT THROW AN EXCEPTION WHEN LOGGING FAILS
16+
}
17+
}
18+
19+
processException(source: string, error: Error, properties: any) {
20+
try {
21+
if (!this._debugMode)
22+
return;
23+
console.error(error);
24+
} catch {
25+
// DO NOT THROW AN EXCEPTION WHEN LOGGING FAILS
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)