Skip to content

Commit

Permalink
Some initial bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Airblader committed Dec 14, 2018
1 parent 5620596 commit 2df99f3
Show file tree
Hide file tree
Showing 20 changed files with 639 additions and 309 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
indent_size = 4
insert_final_newline = false
trim_trailing_whitespace = true

[*.md]
Expand Down
80 changes: 40 additions & 40 deletions angular.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"@ngqp/core": {
"root": "projects/ngqp/core",
"sourceRoot": "projects/ngqp/core/src",
"projectType": "library",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/ngqp/core/tsconfig.lib.json",
"project": "projects/ngqp/core/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/ngqp/core/src/test.ts",
"tsConfig": "projects/ngqp/core/tsconfig.spec.json",
"karmaConfig": "projects/ngqp/core/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/ngqp/core/tsconfig.lib.json",
"projects/ngqp/core/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"@ngqp/core": {
"root": "projects/ngqp/core",
"sourceRoot": "projects/ngqp/core/src",
"projectType": "library",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/ngqp/core/tsconfig.lib.json",
"project": "projects/ngqp/core/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/ngqp/core/src/test.ts",
"tsConfig": "projects/ngqp/core/tsconfig.spec.json",
"karmaConfig": "projects/ngqp/core/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/ngqp/core/tsconfig.lib.json",
"projects/ngqp/core/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
}
}
},
"defaultProject": "@ngqp/core"
},
"defaultProject": "@ngqp/core"
}
54 changes: 27 additions & 27 deletions projects/ngqp/core/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
module.exports = function(config) {
config.set({
basePath: '',
frameworks: [ 'jasmine', '@angular-devkit/build-angular' ],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../../coverage'),
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
reporters: [ 'progress', 'kjhtml' ],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: [ 'Chrome' ],
singleRun: false
});
};
10 changes: 5 additions & 5 deletions projects/ngqp/core/ng-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/ngqp/core",
"lib": {
"entryFile": "src/public_api.ts"
}
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/ngqp/core",
"lib": {
"entryFile": "src/public_api.ts"
}
}
16 changes: 9 additions & 7 deletions projects/ngqp/core/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "@ngqp/core",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^7.x.x",
"@angular/core": "^7.x.x",
"@angular/router": "^7.x.x"
}
"name": "@ngqp/core",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^7.x.x",
"@angular/core": "^7.x.x",
"@angular/forms": "^7.x.x",
"@angular/router": "^7.x.x",
"rxjs": "^6.x.x"
}
}
9 changes: 0 additions & 9 deletions projects/ngqp/core/src/lib/core.module.ts

This file was deleted.

5 changes: 5 additions & 0 deletions projects/ngqp/core/src/lib/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { QueryParamGroup, QueryParamControl, QueryParamControlOpts } from './model';
export { QueryParamNameDirective } from './query-param-name.directive';
export { QueryParamGroupDirective } from './query-param-group.directive';
export { QueryParamBuilder } from './query-param-builder.service';
export { QueryParamModule } from './query-param.module';
101 changes: 101 additions & 0 deletions projects/ngqp/core/src/lib/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Observable, Subject } from 'rxjs';
import { isOptionalFunction } from './util';

/**
* TODO Documentation
*/
export class QueryParamGroup {

/** @internal Maps each control name to the corresponding control. */
public controls: {[controlName: string]: QueryParamControl<any>} = {};

constructor(controls: {[controlName: string]: QueryParamControl<any>}) {
this.controls = controls;
}

/**
* TODO Documentation
*/
public setValue(/* TODO { emitEvent? } */): void {
// TODO
}

/**
* TODO Documentation
*/
public patchValue(/* TODO { emitEvent? } */): void {
// TODO
}

/**
* TODO Documentation
*/
public get valueChanges(): Observable<any> {
// TODO Implement and turn into a property
return null;
}

}

/**
* TODO Documentation
*/
export class QueryParamControl<T> {

/** TODO Documentation */
public value: T = null;

/** TODO Documentation */
// @ts-ignore
public readonly valueChanges$ = this._valueChanges$.asObservable();

/** TODO Documentation */
public name: string | null = null;

/** TODO Documentation */
public initialValue!: T | null;

/** TODO Documentation */
public serialize: (model: T) => string;

/** TODO Documentation */
public deserialize: (value: string) => T;

// TODO Add combineWith(previousValue: T, currentValue: T): Params

// TODO Who completes this?
private _valueChanges$ = new Subject<T>();

constructor(config: QueryParamControlOpts<T>) {
const {
name = null,
initialValue = null,
serialize = model => '' + model,
deserialize = value => value as any,
} = config;

if (!isOptionalFunction(serialize)) {
throw new Error(`serialize must be a function, but received ${serialize}`);
}

if (!isOptionalFunction(deserialize)) {
throw new Error(`deserialize must be a function, but received ${deserialize}`);
}

this.name = name;
this.initialValue = initialValue;
this.serialize = serialize;
this.deserialize = deserialize;
}

}

/**
* TODO Documentation
*/
export interface QueryParamControlOpts<T> {
name?: string;
initialValue?: T;
serialize?: (model: T) => string;
deserialize?: (value: string) => T;
}
39 changes: 39 additions & 0 deletions projects/ngqp/core/src/lib/query-param-builder.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Injectable } from '@angular/core';
import { QueryParamControl, QueryParamControlOpts, QueryParamGroup } from './model';

/**
* TODO Documentation
*/
@Injectable({
providedIn: 'root'
})
export class QueryParamBuilder {

/**
* TODO Documentation
*/
public group(config: { [ name: string ]: QueryParamControl<any> | string }): QueryParamGroup {
const controls: { [ controlName: string ]: QueryParamControl<any> } = {};
Object.keys(config).forEach(controlName => {
controls[ controlName ] = this.createControl(config[ controlName ]);
});

return new QueryParamGroup(controls);
}

/**
* TODO Documentation
*/
public param<T>(config: QueryParamControlOpts<T> = {}): QueryParamControl<T> {
return new QueryParamControl(config);
}

private createControl<T>(controlConfig: QueryParamControl<T> | string): QueryParamControl<T> {
if (controlConfig instanceof QueryParamControl) {
return controlConfig;
}

return this.param();
}

}
Loading

0 comments on commit 2df99f3

Please sign in to comment.