Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: full ng refacto #15

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bcf70af
:sparkles: add a d3 renderer with mock datas
gregoryruiz Apr 13, 2017
48b02c9
chore(pkg): add testing stack
douglasduteil Apr 11, 2017
8256034
SAVE working refacto
douglasduteil Apr 17, 2017
2c9703b
SAVE adding more test
douglasduteil Apr 17, 2017
12b75b8
wip-full-ng-refacto
douglasduteil Apr 17, 2017
910c9f6
Merge branch 'wip-full-ng-refacto' of https://github.com/douglasdutei…
gregoryruiz Apr 23, 2017
846d1f2
:art: extra typing & renaming
gregoryruiz Apr 25, 2017
19d76a8
:fire: delete core.module
gregoryruiz Apr 25, 2017
5a6f640
:art: simplify module id logic
gregoryruiz Apr 25, 2017
ff9e32d
:art: refactor dependencyWheel
gregoryruiz Apr 26, 2017
cd13f8f
fix(dev): bootstrap
paulsouche May 14, 2017
3a4b759
chore(deps): update
paulsouche May 14, 2017
f731a05
chore(ts): better config
paulsouche May 14, 2017
4c820dc
Merge pull request #10 from paulsouche/paulsouche-wip
gregoryruiz May 14, 2017
442937f
feat: add examples
paulsouche May 14, 2017
6e7bc8b
Merge pull request #11 from paulsouche/feat-examples
gregoryruiz May 15, 2017
5d57718
test(fixtures): add all chalk dependencies
douglasduteil Apr 19, 2017
38680b3
chore(routing): replace angular-ui-router by @uirouter/angularjs
douglasduteil May 15, 2017
4e03538
chore(webpack): use minial stats
douglasduteil May 15, 2017
a1d321c
Merge pull request #12 from douglasduteil/chore-routing-replace-angul…
gregoryruiz May 15, 2017
b90dbbf
Merge pull request #13 from douglasduteil/test-fixtures-add-all-chalk…
gregoryruiz May 15, 2017
ac99cd9
Merge pull request #14 from douglasduteil/chore-webpack-use-minial-stats
gregoryruiz May 17, 2017
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
43 changes: 35 additions & 8 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
{
"env": {
"test": {
"presets": [
[
"env",
{
"targets": {
"browsers": [
"last 2 versions"
]
},
"useBuiltIns": true
}
]
]
}
},
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions"]
},
"modules": false,
"useBuiltIns": true
}]
[
"env",
{
"targets": {
"browsers": [
"last 2 versions"
]
},
"modules": false,
"useBuiltIns": true
}
]
],
"plugins": [
"lodash",
["angularjs-annotate", { "explicitOnly" : true}]
[
"angularjs-annotate",
{
"explicitOnly": true
}
]
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ typings/
# Output of 'npm run watch'
dist/*
.awcache
out-tsc
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"**/.git": true,
"dist/": true,
"**/node_modules": true,
"**/out-tsc": true,
"**/*.js": {"when": "$(basename).ts"},
"**/*.css": {"when": "$(basename).scss"},
"**/*.map": {"when": "$(basename).map"}
Expand All @@ -16,4 +17,4 @@
"/node_modules"
],
"typescript.tsdk": "./node_modules/typescript/lib"
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ $ npm run serve:prod
last successful master branch build can be found here: [gregoryruiz.github.io/nso/](https://gregoryruiz.github.io/nso/#!/search/gregory)

## Credits
[@douglasduteil](https://github.com/douglasduteil) for his ideas, disponibility, advices, wisdom & friendship.
[@douglasduteil](https://github.com/douglasduteil) for his ideas, availability, advices, wisdom & friendship.
21 changes: 21 additions & 0 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//

module.exports = function(config) {
config.set({
basePath: '..',

frameworks: ['mocha'],

files: [
{pattern: 'test/**/*.spec.ts', watched: false}
],

preprocessors: {
'test/*.spec.ts': ['webpack'],
},

browsers: ['jsdom'],

webpack: require('./webpack.config.test').default
});
};
6 changes: 4 additions & 2 deletions config/webpack.config.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ exports.default = {
context: resolve(__dirname, '..'),

entry: {
webfont: './src/webfont.ts',
bootstrap: ['babel-polyfill', './src/bootstrap.ts']
inline: [
'./src/www/inline.ts'
],
bootstrap: ['babel-polyfill', './src/www/main.ts']
},

//
Expand Down
3 changes: 2 additions & 1 deletion config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports.default = webpackMerge(
{
devServer: {
compress: true,
stats: 'minimal',
contentBase: resolve(__dirname, 'public'),
historyApiFallback: true,
watchContentBase: true
Expand All @@ -38,7 +39,7 @@ exports.default = webpackMerge(
// html-webpack-plugin plugin
new HtmlWebpackPlugin({
inject: false,
template: './src/index.html'
template: './src/www/index.html'
}),

]
Expand Down
6 changes: 4 additions & 2 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//

const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const Visualizer = require('webpack-visualizer-plugin');
const webpackMerge = require('webpack-merge');
const { LoaderOptionsPlugin, optimize: { UglifyJsPlugin } } = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin')
Expand All @@ -19,7 +20,7 @@ exports.default = webpackMerge(
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: './src/index.html',
template: './src/www/index.html',
minify: {
collapseWhitespace: true,
conservativeCollapse: true,
Expand Down Expand Up @@ -65,7 +66,8 @@ exports.default = webpackMerge(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false
})
}),
new Visualizer()
]),
}
);
19 changes: 19 additions & 0 deletions examples/01-SRP/srp-bad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* tslint:disable:max-classes-per-file */

// Bad SRP

class UserSettings {
constructor(user) {
this.user = user;
}

public changeSettings(settings) {
if (this.verifyCredentials()) {
// ...
}
}

public verifyCredentials() {
// ...
}
}
26 changes: 26 additions & 0 deletions examples/01-SRP/srp-good.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* tslint:disable:max-classes-per-file */

// Good SRP

class UserAuth {
constructor(user) {
this.user = user;
}

public verifyCredentials() {
// ...
}
}

class UserSettings {
constructor(user) {
this.user = user;
this.auth = new UserAuth(user);
}

public changeSettings(settings) {
if (this.auth.verifyCredentials()) {
// ...
}
}
}
43 changes: 43 additions & 0 deletions examples/02-OCP/ocp-bad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* tslint:disable:max-classes-per-file */

// Bad OCP

class AjaxAdapter extends Adapter {
constructor() {
super();
this.name = "ajaxAdapter";
}
}

class NodeAdapter extends Adapter {
constructor() {
super();
this.name = "nodeAdapter";
}
}

class HttpRequester {
constructor(adapter) {
this.adapter = adapter;
}

public fetch(url) {
if (this.adapter.name === "ajaxAdapter") {
return makeAjaxCall(url).then((response) => {
// transform response and return
});
} else if (this.adapter.name === "httpNodeAdapter") {
return makeHttpCall(url).then((response) => {
// transform response and return
});
}
}
}

function makeAjaxCall(url) {
// request and return promise
}

function makeHttpCall(url) {
// request and return promise
}
38 changes: 38 additions & 0 deletions examples/02-OCP/ocp-good.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* tslint:disable:max-classes-per-file */

// Good OCP

class AjaxAdapter extends Adapter {
constructor() {
super();
this.name = "ajaxAdapter";
}

public request(url) {
// request and return promise
}
}

class NodeAdapter extends Adapter {
constructor() {
super();
this.name = "nodeAdapter";
}

public request(url) {
// request and return promise
}
}

class HttpRequester {
constructor(adapter) {
this.adapter = adapter;
}

public fetch(url) {
return this.adapter.request(url)
.then((response) => {
// transform response and return
});
}
}
54 changes: 54 additions & 0 deletions examples/03-LSP/lsp-bad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* tslint:disable:max-classes-per-file */

// Bad LSP

class Rectangle {
constructor() {
this.width = 0;
this.height = 0;
}

public setColor(color) {
// ...
}

public render(area) {
// ...
}

public setWidth(width) {
this.width = width;
}

public setHeight(height) {
this.height = height;
}

public getArea() {
return this.width * this.height;
}
}

class Square extends Rectangle {
public setWidth(width) {
this.width = width;
this.height = width;
}

public setHeight(height) {
this.width = height;
this.height = height;
}
}

function renderLargeRectangles(rectangles) {
rectangles.forEach((rectangle) => {
rectangle.setWidth(4);
rectangle.setHeight(5);
const area = rectangle.getArea(); // BAD: Returns 25 for Square. Should be 20.
rectangle.render(area);
});
}

const rectangles = [new Rectangle(), new Rectangle(), new Square()];
renderLargeRectangles(rectangles);
46 changes: 46 additions & 0 deletions examples/03-LSP/lsp-good.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* tslint:disable:max-classes-per-file */

// Good LSP

class Shape {
public setColor(color) {
// ...
}

public render(area) {
// ...
}
}

class Rectangle extends Shape {
constructor(width, height) {
super();
this.width = width;
this.height = height;
}

public getArea() {
return this.width * this.height;
}
}

class Square extends Shape {
constructor(length) {
super();
this.length = length;
}

public getArea() {
return this.length * this.length;
}
}

function renderLargeShapes(shapes) {
shapes.forEach((shape) => {
const area = shape.getArea();
shape.render(area);
});
}

const shapes = [new Rectangle(4, 5), new Rectangle(4, 5), new Square(5)];
renderLargeShapes(shapes);
Loading