Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions demos/vanilla-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/wwwroot/lib/*
**/wwwroot/dist/*
**/app/**/*.js
**/app/**/*.js.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
<PackageId>Divergent.Frontend</PackageId>
</PropertyGroup>

<ItemGroup>
<Content Include="wwwroot\index.html" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="app\branding\" />
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions demos/vanilla-typescript/Divergent.Frontend/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <binding AfterBuild="run:webpack" Clean="clean" />
/*
This file in the main entry point for defining grunt tasks and using grunt plugins.
Click here to learn more. http://go.microsoft.com/fwlink/?LinkID=513275&clcid=0x409
*/
module.exports = function (grunt) {
grunt.initConfig({
run: {
webpack: {
cmd: "node.exe",
args: ["node_modules\\webpack\\bin\\webpack.js", "--colors"]
}, "webpack-watch": {
cmd: "node.exe",
args: ["node_modules\\webpack\\bin\\webpack.js", "--colors", "--watch"]
}
},
clean: {
build: {
src: ["Scripts/dist"]
}
}
});

grunt.loadNpmTasks("grunt-run");
grunt.loadNpmTasks("grunt-contrib-clean");

grunt.registerTask("dev", [
"clean:build",
"run:webpack"
]);
grunt.registerTask("watch", [
"clean:build",
"run:webpack-watch"
]);
};
21 changes: 21 additions & 0 deletions demos/vanilla-typescript/Divergent.Frontend/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Hosting;
using System.IO;

namespace Divergent.Frontend
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();

host.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:3046/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Backoffice": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:3047"
}
}
}
34 changes: 34 additions & 0 deletions demos/vanilla-typescript/Divergent.Frontend/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Divergent.Frontend
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}

public IConfigurationRoot Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddRouting();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseDefaultFiles();
app.UseStaticFiles();
}
}
}
12 changes: 12 additions & 0 deletions demos/vanilla-typescript/Divergent.Frontend/app/ModulesConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IModule } from "./it-ops/IModule";
import SalesModules from "./modules/sales/__module";

const modules: Array<IModule> = [
new SalesModules()
];

export default class ModulesConfig {
static GetModules(): Array<IModule> {
return modules;
}
};
14 changes: 14 additions & 0 deletions demos/vanilla-typescript/Divergent.Frontend/app/http.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as $ from "jquery";

export async function httpGetRequest<T>(url: string): Promise<T> {

const promise = new Promise<T>((resolve, reject) => {
$.ajax(url, {
method: "GET",
success: (data: T, _1: string, _2: any) => resolve(data),
error: (_1: any, _2: string, errorThrown: string) => reject(errorThrown)
});
});

return promise;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IViewModelAppender } from "./IViewModelAppender";
import { ISubscribeToCompositionEvents } from "./ISubscribeToCompositionEvents";
import { IRegisterComponents } from "./IRegisterComponents";
import { IRequestsGateway } from "./IRequestsGateway";

export default class CompositionEngine
implements IRegisterComponents, IRequestsGateway {

private appendersRegistry: { [id: string]: IViewModelAppender[]; } = {};
private subscribersRegistry: { [id: string]: ISubscribeToCompositionEvents[]; } = {};

registerAppender(appender: IViewModelAppender): void {

let appenders = this.appendersRegistry[appender.requestIdentifier];
if (appenders == null) {
appenders = [];
this.appendersRegistry[appender.requestIdentifier] = appenders;
}

appenders.push(appender);

window.console.debug("Registered appender:", this.appendersRegistry);
}

registerSubscriber(subscriber: ISubscribeToCompositionEvents): void {

let subscribers = this.subscribersRegistry[subscriber.requestIdentifier];
if (subscribers == null) {
subscribers = [];
this.subscribersRegistry[subscriber.requestIdentifier] = subscribers;
}

subscribers.push(subscriber);

window.console.debug("Registered subscriber:", this.subscribersRegistry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IRegisterComponents } from "./IRegisterComponents";
import { IRequestsGateway } from "./IRequestsGateway";

export interface IModule {
init(componentsRegistry: IRegisterComponents, requestsGateway: IRequestsGateway): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IViewModelAppender } from "./IViewModelAppender";
import { ISubscribeToCompositionEvents } from "./ISubscribeToCompositionEvents";

export interface IRegisterComponents {
registerAppender(appender: IViewModelAppender): void,
registerSubscriber(subscriber: ISubscribeToCompositionEvents): void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface IRequestsGateway { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ISubscribeToCompositionEvents {
requestIdentifier: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IViewModelAppender {
readonly requestIdentifier: string,
append(viewModel: any, requestArgs: any): Promise<void>
}
16 changes: 16 additions & 0 deletions demos/vanilla-typescript/Divergent.Frontend/app/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ModulesConfig from "./ModulesConfig";
import * as $ from "jquery";
import CompositionEngine from "./it-ops/CompositionEngine";

$(async () => {

const engine = new CompositionEngine();

const modules = ModulesConfig.GetModules();
for (let i = 0; i < modules.length; i++) {
const mod = modules[i];
mod.init(engine, engine);
}

window.console.log("Init...");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IViewModelAppender } from "../../it-ops/IViewModelAppender";
import { httpGetRequest } from "../../http";

export default class OrderDetailsAppender implements IViewModelAppender {

get requestIdentifier(): string {
return "Order/Details";
}

async append(viewModel: any, requestArgs: any): Promise<void> {

const id = requestArgs.id;
const data = await httpGetRequest<any>("http://localhost:20395/api/orders/" + id);

viewModel.orderNumber = data.number;
viewModel.orderItemsCount = data.itemsCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import OrderDetailsAppender from "./OrderDetailsAppender";
import { IModule } from "../../it-ops/IModule";
import { IRegisterComponents } from "../../it-ops/IRegisterComponents";
import { IRequestsGateway } from "../../it-ops/IRequestsGateway";

export default class SalesModule implements IModule {

init(componentsRegistry: IRegisterComponents, requestsGateway: IRequestsGateway) {

componentsRegistry.registerAppender(new OrderDetailsAppender());

window.console.debug("Sales module...");

}

}
25 changes: 25 additions & 0 deletions demos/vanilla-typescript/Divergent.Frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "1.0.0",
"private": true,
"devDependencies": {
"@types/moment": "2.13.0",
"@types/underscore": "1.7.36",
"grunt": "1.0.1",
"grunt-contrib-clean": "1.0.0",
"grunt-run": "0.6.0",
"grunt-shell": "2.1.0",
"install": "0.8.8",
"ts-loader": "1.3.3",
"tslint": "4.2.0",
"tslint-loader": "3.3.0",
"typescript": "2.2.2",
"webpack": "1.14.0",
"webpack-uglify-js-plugin": "1.1.9"
},
"dependencies": {
"jquery": "3.1.1",
"jquery-validation": "1.16.0",
"moment": "2.17.1",
"underscore": "1.8.3"
}
}
21 changes: 21 additions & 0 deletions demos/vanilla-typescript/Divergent.Frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"noImplicitAny": true,
"noImplicitReturns": true,
"noEmitOnError": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"strictNullChecks": true,
"lib": [ "dom", "es2015.promise", "es5" ]
},
"exclude": [
"./Scripts/dist",
"./node_modules"
],
"typescript.tsdk": "./node_modules/bin/tsc",
"compileOnSave": false
}
Loading