Skip to content

Commit b1cce57

Browse files
attilahgalvesribeiro
authored andcommitted
Restructure Typescript project (#7)
Configure TS compile options Update dependencies Move JS initialization from global to extension specific namespace
1 parent 19fae8a commit b1cce57

File tree

16 files changed

+115
-59
lines changed

16 files changed

+115
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ bld/
2424
[Bb]in/
2525
[Oo]bj/
2626
[Ll]og/
27+
dist/
2728

2829
# Visual Studio 2015 cache/options directory
2930
.vs/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Blazor Extensions
3+
Copyright (c) 2018 Blazor Extensions Contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

global.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "2.1.302"
4+
}
5+
}

src/Blazor.Extensions.Storage.JS/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Blazor.Extensions.Storage.JS/package-lock.json

Lines changed: 33 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Blazor.Extensions.Storage.JS/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"devDependencies": {
1111
"@types/emscripten": "0.0.31",
12-
"webpack": "^4.16.0",
13-
"webpack-cli": "^3.0.8",
12+
"ts-loader": "^4.4.2",
1413
"typescript": "^2.9.2",
15-
"ts-loader": "^4.4.2"
14+
"webpack": "^4.16.3",
15+
"webpack-cli": "^3.1.0"
1616
}
1717
}
Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const blazorExtensions = 'BlazorExtensions';
2-
31
interface IBrowserStorage {
42
Length(storage: string): number;
53
Key(storage: string, index: number): any;
@@ -9,7 +7,7 @@ interface IBrowserStorage {
97
Clear(storage: string): void;
108
};
119

12-
class BrowserStorage implements IBrowserStorage {
10+
export class BrowserStorage implements IBrowserStorage {
1311
public Length(storage: string): number {
1412
return window[storage].length;
1513
};
@@ -19,10 +17,12 @@ class BrowserStorage implements IBrowserStorage {
1917
};
2018

2119
public GetItem(storage: string, key: string): any {
22-
let item = window[storage].getItem(key);
20+
const item = window[storage].getItem(key);
21+
2322
if (item) {
2423
return JSON.parse(item);
2524
}
25+
2626
return null;
2727
};
2828

@@ -38,23 +38,3 @@ class BrowserStorage implements IBrowserStorage {
3838
window[storage].clear();
3939
};
4040
};
41-
42-
43-
function initialize() {
44-
"use strict";
45-
46-
if (typeof window !== 'undefined' && !window[blazorExtensions]) {
47-
// When the library is loaded in a browser via a <script> element, make the
48-
// following APIs available in global scope for invocation from JS
49-
window[blazorExtensions] = {
50-
Storage: new BrowserStorage()
51-
};
52-
} else {
53-
window[blazorExtensions] = {
54-
...window[blazorExtensions],
55-
Storage: new BrowserStorage()
56-
};
57-
}
58-
}
59-
60-
initialize();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { BrowserStorage } from './BrowserStorage';
2+
3+
namespace Storage {
4+
const blazorExtensions: string = 'BlazorExtensions';
5+
// define what this extension adds to the window object inside BlazorExtensions
6+
const extensionObject = {
7+
Storage: new BrowserStorage()
8+
};
9+
10+
export function initialize(): void {
11+
if (typeof window !== 'undefined' && !window[blazorExtensions]) {
12+
// when the library is loaded in a browser via a <script> element, make the
13+
// following APIs available in global scope for invocation from JS
14+
window[blazorExtensions] = {
15+
...extensionObject
16+
};
17+
} else {
18+
window[blazorExtensions] = {
19+
...window[blazorExtensions],
20+
...extensionObject
21+
};
22+
}
23+
}
24+
}
25+
26+
Storage.initialize();

src/Blazor.Extensions.Storage.JS/tsconfig.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
"compilerOptions": {
33
"noImplicitAny": false,
44
"noEmitOnError": true,
5-
"removeComments": false,
5+
"removeComments": true,
66
"sourceMap": true,
7-
"target": "es5",
8-
"lib": ["es2015", "dom"],
9-
"strict": true
7+
"target": "es6",
8+
"module": "commonjs",
9+
"lib": ["es2016", "dom"],
10+
"strict": true,
11+
"alwaysStrict": true,
12+
"preserveConstEnums": true
1013
},
1114
"exclude": [
1215
"node_modules"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"tabSize": 2,
3+
"indentSize": 2,
4+
"convertTabsToSpaces": true,
5+
"insertSpaceAfterCommaDelimiter": true,
6+
"insertSpaceAfterSemicolonInForStatements": true,
7+
"insertSpaceBeforeAndAfterBinaryOperators": true,
8+
"insertSpaceAfterKeywordsInControlFlowStatements": true,
9+
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
10+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
11+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
12+
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
13+
"insertSpaceBeforeFunctionParenthesis": false,
14+
"placeOpenBraceOnNewLineForFunctions": false,
15+
"placeOpenBraceOnNewLineForControlBlocks": false
16+
}

0 commit comments

Comments
 (0)