Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsisexistence committed Sep 8, 2019
2 parents 2a5a82f + c21258e commit 14c53dd
Show file tree
Hide file tree
Showing 14 changed files with 588 additions and 1,408 deletions.
1,663 changes: 376 additions & 1,287 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 15 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,41 @@
"contributors:generate": "npx all-contributors generate"
},
"dependencies": {
"@angular/animations": "8.2.4",
"@angular/common": "8.2.4",
"@angular/compiler": "8.2.4",
"@angular/core": "8.2.4",
"@angular/forms": "8.2.4",
"@angular/platform-browser": "8.2.4",
"@angular/platform-browser-dynamic": "8.2.4",
"@angular/router": "8.2.4",
"@angular/animations": "8.2.5",
"@angular/common": "8.2.5",
"@angular/compiler": "8.2.5",
"@angular/core": "8.2.5",
"@angular/forms": "8.2.5",
"@angular/platform-browser": "8.2.5",
"@angular/platform-browser-dynamic": "8.2.5",
"@angular/router": "8.2.5",
"hammerjs": "2.0.8",
"routeshub": "3.0.1",
"rxjs": "6.5.2",
"zone.js": "0.10.2"
},
"devDependencies": {
"@angular-builders/jest": "8.2.0",
"@angular-devkit/build-angular": "0.803.2",
"@angular-devkit/build-ng-packagr": "0.803.2",
"@angular/cli": "8.3.2",
"@angular/compiler-cli": "8.2.4",
"@angular/language-service": "8.2.4",
"@angular-devkit/build-angular": "0.803.3",
"@angular-devkit/build-ng-packagr": "0.803.3",
"@angular/cli": "8.3.3",
"@angular/compiler-cli": "8.2.5",
"@angular/language-service": "8.2.5",
"@commitlint/cli": "8.1.0",
"@commitlint/config-conventional": "8.1.0",
"@compodoc/compodoc": "1.1.10",
"@types/jasmine": "3.3.13",
"@types/jasminewd2": "2.0.6",
"@types/jest": "24.0.18",
"@types/node": "8.10.46",
"all-contributors-cli": "6.8.2",
"all-contributors-cli": "6.9.0",
"codelyzer": "5.1.0",
"husky": "3.0.5",
"jasmine-core": "3.4.0",
"jasmine-spec-reporter": "4.2.1",
"jest": "24.9.0",
"jsonlint": "1.6.3",
"lint-staged": "9.2.5",
"ng-packagr": "5.5.0",
"prettier": "1.18.2",
"protractor": "6.0.0",
"snyk": "1.200.1",
"snyk": "1.226.0",
"ts-node": "8.3.0",
"tsickle": "0.37.0",
"tslib": "1.10.0",
Expand Down
4 changes: 2 additions & 2 deletions package/configs/jest/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'jest-preset-angular';
import './global-mocks';

import { reset } from '../../src/utils/helpers';
import { resetPackage } from '../../src/utils/helpers';

afterEach(reset);
afterEach(resetPackage);
36 changes: 17 additions & 19 deletions package/src/creators/feature.creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,24 @@ import { connectDetached } from '../functions';
/**
* Creates a feature route
*/
export function createFeature<R = any, C = any>(
export const createFeature = <R = any, C = any>(
routes: Routes,
{ key, detached, routeName }: Partial<CreatorOptionArgs> = {}
): LazySlice<R, C> {
return (
parentStructure: Structure,
alternativeName?: string
): Slice<R, C> => {
const name = alternativeName ? alternativeName : parentStructure.name;
const notes: Notes<R, C> = createNote<R, C>(routes, routeName);
const feature: Slice<R, C> = createSlice<R, C>(parentStructure, notes);
const updatedRouteState: Slices<Slice<R, C>> = updateHub<R, C>(
feature,
name,
key || name
);
hub.next(updatedRouteState);
): LazySlice<R, C> => (
parentStructure: Structure,
alternativeName?: string
): Slice<R, C> => {
const name = alternativeName ? alternativeName : parentStructure.name;
const notes: Notes<R, C> = createNote<R, C>(routes, routeName);
const feature: Slice<R, C> = createSlice<R, C>(parentStructure, notes);
const updatedRouteState: Slices<Slice<R, C>> = updateHub<R, C>(
feature,
name,
key || name
);
hub.next(updatedRouteState);

connectDetached(detached, parentStructure);
connectDetached(detached, parentStructure);

return hub.value[name];
};
}
return hub.value[name];
};
2 changes: 1 addition & 1 deletion package/src/creators/note.creator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Route } from '@angular/router';
import { DefaultNameOptions, Note, Notes } from '../interfaces';
import { setRouteName } from '../utils/name';
import { setRouteName } from '../utils/path';

/**
* creates a route note
Expand Down
1 change: 1 addition & 0 deletions package/src/creators/root.creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function createRoot<R = any, C = any>(
if (hub.value !== null) {
throw new Error('Routeshub is already declared');
}

const defaultRootName = 'app';
const notes: Notes<R, C> = createNote<R, C>(routes, routeName);
const rootSlice: Slice<R, C> = createSlice<R, C>(null, notes);
Expand Down
86 changes: 86 additions & 0 deletions package/src/creators/slice.creator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Routes } from '@angular/router';
import { createNote } from './note.creator';
import { createSlice } from './slice.creator';
import { Structure } from '../interfaces/common.interfaces';

describe('createSlice', () => {
it('should create basic without parent', () => {
const routes: Routes = [{ path: '' }];
const notes = createNote(routes);
const result = {
root: {
id: 0,
name: 'root',
parentId: null,
path: '',
state: ['/']
}
};
expect(createSlice(null, notes)).toEqual(result);
});

it('should create slice of few routes', () => {
const routes: Routes = [{ path: '' }, { path: 'about' }, { path: 'map' }];
const notes = createNote(routes);
const result = {
root: {
id: 0,
name: 'root',
parentId: null,
path: '',
state: ['/']
},
about: {
id: 1,
name: 'about',
parentId: null,
path: 'about',
state: ['/', 'about']
},
map: {
id: 2,
name: 'map',
parentId: null,
path: 'map',
state: ['/', 'map']
}
};
expect(createSlice(null, notes)).toEqual(result);
});

it('should create slice of few routes with parent', () => {
const parentStructure: Structure = {
id: 0,
parentId: null,
state: ['/', 'admin'],
name: 'root',
path: ''
};
const routes: Routes = [{ path: '' }, { path: 'about' }, { path: 'map' }];
const notes = createNote(routes);
const result = {
root: {
id: 0,
name: 'root',
parentId: 0,
path: '',
state: ['/', 'admin']
},
about: {
id: 1,
name: 'about',
parentId: 0,
path: 'about',
state: ['/', 'admin', 'about']
},
map: {
id: 2,
name: 'map',
parentId: 0,
path: 'map',
state: ['/', 'admin', 'map']
}
};
expect(createSlice(parentStructure, notes)).toEqual(result);
});
});
14 changes: 6 additions & 8 deletions package/src/creators/slice.creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import {
import { getState } from '../utils/state';

/**
* Serializes routes
* to enhance capabilities
* serializes routes to enhance capabilities
*/
export function createSlice<R, C>(
export const createSlice = <R, C>(
parentStructure: Structure | null,
routes: Notes<R, C>
): InternalSlice<R, C> {
return Object.keys(routes).reduce(
notes: Notes<R, C>
): InternalSlice<R, C> =>
Object.keys(notes).reduce(
(acc: InternalSlice<R, C>, key: string): InternalSlice<R, C> => {
const { children, path, name } = routes[key];
const { children, path, name } = notes[key];
const route: InternalStructure = {
parentId: parentStructure && parentStructure.id,
state: getState(parentStructure, path),
Expand All @@ -35,4 +34,3 @@ export function createSlice<R, C>(
},
{} as InternalSlice<R, C>
);
}
36 changes: 21 additions & 15 deletions package/src/decorators/sliced.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ import { getSlice } from '../functions';
import { Slice } from '../interfaces';
import { privateNotesKey } from '../interfaces/common.interfaces';

export function Sliced<T = any>(
/**
* decorator which provides possibility
* to get slices inside component
*/
// tslint:disable:variable-name
export const Sliced = <T = any>(
arg: privateNotesKey
): (target: any, propertyKey: PropertyKey) => void {
return <R>(target: any, propertyKey: privateNotesKey) => {
let sliceValue: Slice<R>;
): ((target: any, propertyKey: PropertyKey) => void) => <R>(
target: any,
propertyKey: privateNotesKey
) => {
let sliceValue: Slice<R>;

hub.pipe(take(1)).subscribe(() => {
sliceValue = getSlice<R>(arg);
});
hub.pipe(take(1)).subscribe(() => {
sliceValue = getSlice<R>(arg);
});

Object.defineProperty(target, propertyKey, {
get(): Slice<R> {
return sliceValue || ({} as Slice<R>);
},
set(): void {}
});
};
}
Object.defineProperty(target, propertyKey, {
get(): Slice<R> {
return sliceValue || ({} as Slice<R>);
},
set(): void {}
});
};
13 changes: 9 additions & 4 deletions package/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import { indexer } from './indexer';
/*
* util for internal usage
*/
export const reset = (): void => {
export const resetPackage = (): void => {
hub.next(null);
indexer.next({ reset: true });
};

/**
* checks attribute presence and activity
*/
export function checkAttrActivity(attr): boolean {
return attr === '' || !!attr;
}
export const checkAttrActivity = (attr: boolean): boolean => Boolean(attr);

/**
* gets string | string[] and returns valid format in string []
Expand All @@ -23,3 +21,10 @@ export const getClassNames = (input: string | string[]): string[] => {
const classNames = input instanceof Array ? input : input.split(' ');
return classNames.filter((className: string) => className.length > 0);
};

/**
* hides a way to flush an error message
*/
export const showError = (...errorMessages: any[]): void => {
console.error(...errorMessages);
};
4 changes: 2 additions & 2 deletions package/src/utils/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* generator that keeps and generates unique identifiers
*/
function* idfy(): IterableIterator<number> {
function* makeResettableIterator(): IterableIterator<number> {
let index = 0;
while (true) {
const options = yield index++;
Expand All @@ -16,4 +16,4 @@ function* idfy(): IterableIterator<number> {
/**
* provides ordered ids
*/
export const indexer = idfy();
export const indexer = makeResettableIterator();
8 changes: 3 additions & 5 deletions package/src/utils/link.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Structure } from '../interfaces';
import { transformPathToState } from './path';
import { showError } from './helpers';

/**
* makes adjustments to string link
*/
export function correctStringLink(value: string): string {
switch (true) {
case value === '[Object object]': {
// tslint:disable-next-line:max-line-length
console.error(
`ERROR: incorrect [[${value}]] has been passed into navLink`
);
showError(`ERROR: incorrect [[${value}]] has been passed into navLink.`);
return '/';
}
case value.includes(','):
Expand Down Expand Up @@ -38,7 +36,7 @@ export const getRouteLink = (
} else if (typeof input === 'object' && input.state) {
return input.state;
} else {
console.error('ERROR: navLink gets incorrect data format', '\n', input);
showError('ERROR: navLink gets incorrect data format', '\n', input);
return [];
}
};
Expand Down
Loading

0 comments on commit 14c53dd

Please sign in to comment.