added example files
This commit is contained in:
35
dist/adapters/music/VinylCatalog.js
vendored
Normal file
35
dist/adapters/music/VinylCatalog.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Track_1 = require("../../domain/models/Track");
|
||||
var VinylCatalog = /** @class */ (function () {
|
||||
function VinylCatalog() {
|
||||
this.vinylList = new Array(new Track_1.Track(1, "DNA.", "Kendrick Lamar", 340), new Track_1.Track(2, "Come Down", "Anderson Paak.", 430), new Track_1.Track(3, "DNA.", "Kendrick Lamar", 340), new Track_1.Track(4, "DNA.", "Kendrick Lamar", 340), new Track_1.Track(5, "DNA.", "Kendrick Lamar", 340));
|
||||
}
|
||||
VinylCatalog.prototype.get = function () {
|
||||
return this.vinylList;
|
||||
};
|
||||
VinylCatalog.prototype.getById = function (id) {
|
||||
return this.vinylList.filter(function (track) { return track.Id == id; }).pop();
|
||||
};
|
||||
VinylCatalog.prototype.add = function (track) {
|
||||
return this.vinylList.push(track);
|
||||
};
|
||||
VinylCatalog.prototype.edit = function (id, track) {
|
||||
var existingTrack = this.getById(id);
|
||||
existingTrack.Artist = track.Artist;
|
||||
existingTrack.Title = track.Title;
|
||||
existingTrack.Duration = track.Duration;
|
||||
return existingTrack;
|
||||
};
|
||||
VinylCatalog.prototype.delete = function (id) {
|
||||
var track = this.getById(id);
|
||||
if (track) {
|
||||
var targetIndex = this.vinylList.indexOf(track);
|
||||
if (targetIndex < -1)
|
||||
return null;
|
||||
return this.vinylList.splice(targetIndex, 1)[0];
|
||||
}
|
||||
};
|
||||
return VinylCatalog;
|
||||
}());
|
||||
exports.VinylCatalog = VinylCatalog;
|
||||
2
dist/domain/factories/IPortProvider.js
vendored
Normal file
2
dist/domain/factories/IPortProvider.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
12
dist/domain/models/Track.js
vendored
Normal file
12
dist/domain/models/Track.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Track = /** @class */ (function () {
|
||||
function Track(id, title, artist, duration) {
|
||||
this.Id = id;
|
||||
this.Title = title;
|
||||
this.Artist = artist;
|
||||
this.Duration = duration;
|
||||
}
|
||||
return Track;
|
||||
}());
|
||||
exports.Track = Track;
|
||||
2
dist/domain/ports/IMusicRepository.js
vendored
Normal file
2
dist/domain/ports/IMusicRepository.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
24
dist/domain/services/MusicCatalogService.js
vendored
Normal file
24
dist/domain/services/MusicCatalogService.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var MusicCatalogService = /** @class */ (function () {
|
||||
function MusicCatalogService(repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
MusicCatalogService.prototype.get = function () {
|
||||
return this.repository.get();
|
||||
};
|
||||
MusicCatalogService.prototype.getById = function (id) {
|
||||
return this.repository.getById(id);
|
||||
};
|
||||
MusicCatalogService.prototype.add = function (track) {
|
||||
return this.repository.add(track);
|
||||
};
|
||||
MusicCatalogService.prototype.edit = function (id, track) {
|
||||
return this.repository.edit(id, track);
|
||||
};
|
||||
MusicCatalogService.prototype.delete = function (id) {
|
||||
return this.repository.delete(id);
|
||||
};
|
||||
return MusicCatalogService;
|
||||
}());
|
||||
exports.MusicCatalogService = MusicCatalogService;
|
||||
20
dist/view/MusicComponent.js
vendored
Normal file
20
dist/view/MusicComponent.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var MusicCatalogService_1 = require("../domain/services/MusicCatalogService");
|
||||
var VinylCatalog_1 = require("../adapters/music/VinylCatalog");
|
||||
var MusicComponent = /** @class */ (function () {
|
||||
function MusicComponent() {
|
||||
var container = {
|
||||
IMusicRepository: function () { return new VinylCatalog_1.VinylCatalog(); }
|
||||
};
|
||||
var inject = function (name) {
|
||||
if (container[name]) {
|
||||
return container[name];
|
||||
}
|
||||
throw new Error("Failed to resolve " + name);
|
||||
};
|
||||
var musicCatalogService = new MusicCatalogService_1.MusicCatalogService(inject("IMusicRepository"));
|
||||
}
|
||||
return MusicComponent;
|
||||
}());
|
||||
exports.MusicComponent = MusicComponent;
|
||||
9
dist/view/MusicComponent.spec.js
vendored
Normal file
9
dist/view/MusicComponent.spec.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var MusicComponent_1 = require("./MusicComponent");
|
||||
describe("MusicComponent", function () {
|
||||
it('should create a new MusicComponent', function (done) {
|
||||
var musicComponent = new MusicComponent_1.MusicComponent();
|
||||
done();
|
||||
});
|
||||
});
|
||||
20
karma.conf.js
Normal file
20
karma.conf.js
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
module.exports = function(config) {
|
||||
config.set({
|
||||
frameworks: ["jasmine", "karma-typescript"],
|
||||
files: [
|
||||
{ pattern: "src/**/*.spec.ts" }
|
||||
],
|
||||
karmaTypescriptConfig: {
|
||||
compilerOptions: {
|
||||
module: "commonjs"
|
||||
},
|
||||
tsconfig: "./tsconfig.json",
|
||||
},
|
||||
preprocessors: {
|
||||
"**/*.ts": ["karma-typescript"]
|
||||
},
|
||||
reporters: ["progress", "karma-typescript"],
|
||||
browsers: ["Chrome"]
|
||||
});
|
||||
};
|
||||
33
package.json
Normal file
33
package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "typescript-starter",
|
||||
"version": "1.0.0",
|
||||
"description": "Starter project for a typescript app",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc --listEmittedFiles",
|
||||
"_install": "tsc --listEmittedFiles",
|
||||
"test": "karma start karma.conf.js -sm=false",
|
||||
"test-build": "karma start karma.conf.js -sm=false --watch=false --single-run=true --reporters=junit,progress --browsers=Chrome"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://niels.kooiman@solidt.eu/git/niels.kooiman/typescript-starter.git"
|
||||
},
|
||||
"author": "Niels Kooiman <niels.kooiman@gmail.com>",
|
||||
"license": "UNLICENCED",
|
||||
"devDependencies": {
|
||||
"@types/jasmine": "^2.8.6",
|
||||
"diff": "^3.4.0",
|
||||
"handlebars": "^4.0.11",
|
||||
"jasmine-core": "^2.99.1",
|
||||
"karma": "^1.7.1",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-cli": "^1.0.1",
|
||||
"karma-jasmine": "^1.1.1",
|
||||
"karma-typescript": "^3.0.12",
|
||||
"socket.io": "^2.0.4",
|
||||
"typescript": "^2.7.2"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
39
src/adapters/music/VinylCatalog.ts
Normal file
39
src/adapters/music/VinylCatalog.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Track } from "../../domain/models/Track";
|
||||
import { IMusicRepository } from "../../domain/ports/IMusicRepository";
|
||||
|
||||
export class VinylCatalog implements IMusicRepository {
|
||||
|
||||
private vinylList: Track[] = new Array(
|
||||
new Track(1, "DNA.", "Kendrick Lamar", 340),
|
||||
new Track(2, "Come Down", "Anderson Paak.", 430),
|
||||
new Track(3, "DNA.", "Kendrick Lamar", 340),
|
||||
new Track(4, "DNA.", "Kendrick Lamar", 340),
|
||||
new Track(5, "DNA.", "Kendrick Lamar", 340)
|
||||
);
|
||||
|
||||
get(): Track[] {
|
||||
return this.vinylList;
|
||||
}
|
||||
getById(id: number): Track {
|
||||
return this.vinylList.filter(track => track.Id == id).pop();
|
||||
}
|
||||
add(track: Track): number {
|
||||
return this.vinylList.push(track);
|
||||
}
|
||||
edit(id: number, track: Track): Track {
|
||||
var existingTrack = this.getById(id);
|
||||
existingTrack.Artist = track.Artist;
|
||||
existingTrack.Title = track.Title;
|
||||
existingTrack.Duration = track.Duration;
|
||||
return existingTrack;
|
||||
|
||||
}
|
||||
delete(id: number): Track {
|
||||
var track = this.getById(id);
|
||||
if (track) {
|
||||
var targetIndex = this.vinylList.indexOf(track);
|
||||
if (targetIndex < -1) return null;
|
||||
return this.vinylList.splice(targetIndex, 1)[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
4
src/domain/factories/IPortProvider.ts
Normal file
4
src/domain/factories/IPortProvider.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
export interface IPortProvider {
|
||||
|
||||
}
|
||||
15
src/domain/models/Track.ts
Normal file
15
src/domain/models/Track.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
export class Track{
|
||||
|
||||
constructor(id: number, title: string, artist: string, duration:number){
|
||||
this.Id= id;
|
||||
this.Title= title;
|
||||
this.Artist= artist;
|
||||
this.Duration= duration;
|
||||
}
|
||||
|
||||
public Id : number;
|
||||
public Title: string;
|
||||
public Artist: string;
|
||||
public Duration: number;
|
||||
}
|
||||
10
src/domain/ports/IMusicRepository.ts
Normal file
10
src/domain/ports/IMusicRepository.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Track } from "../models/Track";
|
||||
|
||||
|
||||
export interface IMusicRepository {
|
||||
get() : Track[];
|
||||
getById(id: number) : Track;
|
||||
add(track: Track) : number;
|
||||
edit(id: number, track: Track) : Track;
|
||||
delete(id: number) : Track;
|
||||
}
|
||||
27
src/domain/services/MusicCatalogService.ts
Normal file
27
src/domain/services/MusicCatalogService.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { IMusicRepository } from "../../domain/ports/IMusicRepository";
|
||||
import { Track } from "../../domain/models/Track";
|
||||
|
||||
|
||||
export class MusicCatalogService {
|
||||
private repository: IMusicRepository;
|
||||
|
||||
constructor(repository:IMusicRepository){
|
||||
this.repository= repository;
|
||||
}
|
||||
|
||||
get(): Track[] {
|
||||
return this.repository.get();
|
||||
}
|
||||
getById(id: number): Track {
|
||||
return this.repository.getById(id);
|
||||
}
|
||||
add(track: Track): number {
|
||||
return this.repository.add(track);
|
||||
}
|
||||
edit(id: number, track: Track): Track {
|
||||
return this.repository.edit(id, track);
|
||||
}
|
||||
delete(id: number): Track {
|
||||
return this.repository.delete(id);
|
||||
}
|
||||
}
|
||||
10
src/view/MusicComponent.spec.ts
Normal file
10
src/view/MusicComponent.spec.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { MusicComponent } from "./MusicComponent";
|
||||
|
||||
describe("MusicComponent", () => {
|
||||
|
||||
it('should create a new MusicComponent', (done) => {
|
||||
let musicComponent = new MusicComponent();
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
23
src/view/MusicComponent.ts
Normal file
23
src/view/MusicComponent.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
import { MusicCatalogService } from "../domain/services/MusicCatalogService"
|
||||
import { IMusicRepository } from "../domain/ports/IMusicRepository";
|
||||
|
||||
import { VinylCatalog } from "../adapters/music/VinylCatalog"
|
||||
|
||||
export class MusicComponent {
|
||||
constructor() {
|
||||
|
||||
let container = {
|
||||
IMusicRepository: () => new VinylCatalog()
|
||||
};
|
||||
|
||||
let inject = (name : string) : any => {
|
||||
if (container[name]) {
|
||||
return container[name];
|
||||
}
|
||||
throw new Error(`Failed to resolve ${name}`)
|
||||
};
|
||||
let musicCatalogService = new MusicCatalogService(inject("IMusicRepository") as IMusicRepository);
|
||||
|
||||
}
|
||||
}
|
||||
57
tsconfig.json
Normal file
57
tsconfig.json
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user