From 66fdae38aa8c6fa6f1de579ccccbb15000ec7e02 Mon Sep 17 00:00:00 2001 From: Pankaj Rawat Date: Thu, 20 Jul 2017 12:50:42 +0530 Subject: [PATCH 1/6] inital migration with bad hacks --- .vscode/launch.json | 19 ++++++++++ .vscode/settings.json | 21 ++++++++++ package.json | 11 +++--- src/app/app.module.ts | 4 +- src/app/app.reducers.ts | 2 +- src/app/auth/actions/auth.actions.ts | 10 ++--- src/app/auth/reducers/auth.reducer.ts | 2 +- src/app/checkout/actions/checkout.actions.ts | 20 +++++----- src/app/checkout/checkout.module.ts | 4 +- src/app/checkout/effects/checkout.effects.ts | 6 +-- src/app/checkout/reducers/checkout.reducer.ts | 2 +- src/app/core/index.ts | 10 +++-- src/app/home/reducers/search.actions.ts | 4 +- src/app/home/reducers/search.reducers.ts | 2 +- src/app/product/actions/product-actions.ts | 14 +++---- src/app/product/effects/product.effects.ts | 6 +-- src/app/product/reducers/product-reducer.ts | 2 +- src/app/user/actions/user.actions.ts | 4 +- src/app/user/reducers/user.reducer.ts | 2 +- yarn.lock | 38 +++++++++++-------- 20 files changed, 118 insertions(+), 65 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..c40b9a52 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + "version": "0.1.0", + "configurations": [ + { + "name": "Launch localhost", + "type": "chrome", + "request": "launch", + "url": "http://localhost:4200", + "webRoot": "${workspaceRoot}/wwwroot" + }, + { + "name": "Launch index.html (disable sourcemaps)", + "type": "chrome", + "request": "launch", + "sourceMaps": false, + "file": "${workspaceRoot}/index.html" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..9f4fbaf8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,21 @@ +{ + "typescript.check.workspaceVersion": false, + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/.DS_Store": true, + "node_modules": true, + "bin": true, + "obj": true, + "dist": true, + "Properties": true, + ".vs": true, + "*.csproj": true, + "*.sln": true, + "*.csproj.user": true, + "*.suo": true, + ".docker": false, + "docs": false + } +} \ No newline at end of file diff --git a/package.json b/package.json index f3b4cd96..4d18ce28 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,9 @@ "@angular/platform-browser-dynamic": "^4.2.6", "@angular/router": "^4.2.6", "@ngrx/core": "^1.2.0", - "@ngrx/effects": "^2.0.4", - "@ngrx/store": "^2.2.1", + "@ngrx/effects": "^4.0.1", + "@ngrx/router-store": "^4.0.0", + "@ngrx/store": "^4.0.0", "bootstrap": "^3.3.7", "bootstrap-sass": "^3.3.7", "core-js": "^2.4.1", @@ -37,14 +38,14 @@ "ngx-bootstrap": "^1.7.1", "reselect": "^2.5.4", "rxjs": "^5.3.0", - "zone.js": "0.8.7" + "zone.js": "0.8.12" }, "devDependencies": { "@angular/cli": "^1.1.2", "@angular/compiler-cli": "^4.2.6", "@angularclass/hmr": "^1.2.2", "@compodoc/compodoc": "^1.0.0-beta.8", - "@ngrx/store-devtools": "^3.2.3", + "@ngrx/store-devtools": "^4.0.0", "@types/grecaptcha": "^2.0.31", "@types/jasmine": "2.5.38", "@types/morris.js": "^0.5.6", @@ -67,7 +68,7 @@ "sw-precache": "^5.0.0", "ts-node": "^1.7.2", "tslint": "^4.5.1", - "typescript": "2.3" + "typescript": "^2.4.0" }, "description": "Spree for Angular2", "main": "index.js", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e0238689..eae2c068 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -15,7 +15,7 @@ import { HomeModule } from './home/index'; import { LayoutModule } from './layout/index'; import { CoreModule } from './core/index'; import { StoreModule } from '@ngrx/store'; -import { reducer } from './app.reducers'; +import { reducers } from './app.reducers'; import { CheckoutHeaderComponent } from './layout/checkout-header/checkout-header.component'; import { CheckoutFooterComponent } from './layout/checkout-footer/checkout-footer.component'; @@ -36,7 +36,7 @@ import 'rxjs/add/observable/of'; ], imports: [ RouterModule.forRoot(routes), - StoreModule.provideStore(reducer), + StoreModule.forRoot(reducers), BrowserModule, FormsModule, HttpModule, diff --git a/src/app/app.reducers.ts b/src/app/app.reducers.ts index 374a6797..ed77b798 100644 --- a/src/app/app.reducers.ts +++ b/src/app/app.reducers.ts @@ -35,7 +35,7 @@ import { compose } from '@ngrx/core/compose'; */ import { storeFreeze } from 'ngrx-store-freeze'; -const reducers = { +export const reducers = { products: productReducer, auth: authReducer, checkout: checkoutReducer, diff --git a/src/app/auth/actions/auth.actions.ts b/src/app/auth/actions/auth.actions.ts index cee7061a..3992b19e 100644 --- a/src/app/auth/actions/auth.actions.ts +++ b/src/app/auth/actions/auth.actions.ts @@ -7,23 +7,23 @@ export class AuthActions { static LOGOUT_SUCCESS = 'LOGOUT_SUCCESS'; static AUTHORIZE = 'AUTHORIZE'; - authorize(): Action { + authorize() { return { type: AuthActions.AUTHORIZE }; } - login(): Action { + login() { return { type: AuthActions.LOGIN }; } - loginSuccess(): Action { + loginSuccess() { return { type: AuthActions.LOGIN_SUCCESS}; } - logout(): Action { + logout() { return { type: AuthActions.LOGOUT }; } - logoutSuccess(): Action { + logoutSuccess() { return { type: AuthActions.LOGOUT_SUCCESS }; } } diff --git a/src/app/auth/reducers/auth.reducer.ts b/src/app/auth/reducers/auth.reducer.ts index 9ae718a8..da426aa5 100644 --- a/src/app/auth/reducers/auth.reducer.ts +++ b/src/app/auth/reducers/auth.reducer.ts @@ -5,7 +5,7 @@ import { AuthState, AuthStateRecord } from './auth.state'; export const initialState: AuthState = new AuthStateRecord() as AuthState; export const authReducer: ActionReducer = - (state: AuthState = initialState, { type, payload }: Action): AuthState => { + (state: AuthState = initialState, { type, payload }: any): AuthState => { switch (type) { case AuthActions.LOGIN_SUCCESS: return state.merge({ isAuthenticated: true }) as AuthState; diff --git a/src/app/checkout/actions/checkout.actions.ts b/src/app/checkout/actions/checkout.actions.ts index 1219629d..51cdefd3 100644 --- a/src/app/checkout/actions/checkout.actions.ts +++ b/src/app/checkout/actions/checkout.actions.ts @@ -28,61 +28,61 @@ export class CheckoutActions { }; } - addToCart(variant_id: number): Action { + addToCart(variant_id: number) { return { type: CheckoutActions.ADD_TO_CART, payload: variant_id }; } - addToCartSuccess(lineItem: LineItem): Action { + addToCartSuccess(lineItem: LineItem) { return { type: CheckoutActions.ADD_TO_CART_SUCCESS, payload: lineItem }; } - removeLineItem(lineItemId: number): Action { + removeLineItem(lineItemId: number) { return { type: CheckoutActions.REMOVE_LINE_ITEM, payload: lineItemId }; } - removeLineItemSuccess(lineItem: LineItem): Action { + removeLineItemSuccess(lineItem: LineItem) { return { type: CheckoutActions.REMOVE_LINE_ITEM_SUCCESS, payload: lineItem }; } - changeLineItemQuantity(quantity: number, lineItemId: number): Action { + changeLineItemQuantity(quantity: number, lineItemId: number) { return { type: CheckoutActions.CHANGE_LINE_ITEM_QUANTITY, payload: { quantity, lineItemId } }; } - placeOrder(): Action { + placeOrder() { return { type: CheckoutActions.PLACE_ORDER }; } - changeOrderState(): Action { + changeOrderState() { return { type: CheckoutActions.CHANGE_ORDER_STATE }; } - changeOrderStateSuccess(order: Order): Action { + changeOrderStateSuccess(order: Order) { return { type: CheckoutActions.CHANGE_ORDER_STATE_SUCCESS, payload: order }; } - updateOrder(): Action { + updateOrder() { return { type: CheckoutActions.UPDATE_ORDER }; } - updateOrderSuccess(order: Order): Action { + updateOrderSuccess(order: Order) { return { type: CheckoutActions.UPDATE_ORDER_SUCCESS, payload: order diff --git a/src/app/checkout/checkout.module.ts b/src/app/checkout/checkout.module.ts index 58abb766..9a5d3c19 100644 --- a/src/app/checkout/checkout.module.ts +++ b/src/app/checkout/checkout.module.ts @@ -16,7 +16,9 @@ import { CheckoutRoutes as routes } from './checkout.routes'; imports: [ CommonModule, RouterModule.forChild(routes), - EffectsModule.run(CheckoutEffects), + EffectsModule.forRoot([ + CheckoutEffects + ]), CartModule, AddressModule, PaymentModule diff --git a/src/app/checkout/effects/checkout.effects.ts b/src/app/checkout/effects/checkout.effects.ts index b591063c..704c6a1c 100644 --- a/src/app/checkout/effects/checkout.effects.ts +++ b/src/app/checkout/effects/checkout.effects.ts @@ -17,7 +17,7 @@ export class CheckoutEffects { @Effect() AddToCart$ = this.actions$ .ofType(CheckoutActions.ADD_TO_CART) - .switchMap((action: Action) => { + .switchMap((action: any) => { return this.checkoutService.createNewLineItem(action.payload); }) .map((lineItem: LineItem) => this.actions.addToCartSuccess(lineItem)); @@ -25,7 +25,7 @@ export class CheckoutEffects { // @Effect() // FetchCurrentOrder$ = this.actions$ // .ofType(CartActions.FETCH_CURRENT_ORDER) - // .switchMap((action: Action) => { + // .switchMap((action: any) => { // return this.cartService.fetchCurrentOrder(); // }) // .map((order: Order) => { @@ -39,7 +39,7 @@ export class CheckoutEffects { // @Effect() // RemoveLineItem$ = this.actions$ // .ofType(CartActions.REMOVE_LINE_ITEM) - // .switchMap((action: Action) => { + // .switchMap((action: any) => { // return this.cartService.deleteLineItem(action.payload); // }) // .map(() => this.cartActions.removeLineItemSuccess()); diff --git a/src/app/checkout/reducers/checkout.reducer.ts b/src/app/checkout/reducers/checkout.reducer.ts index 2f57f6ac..6149e81e 100644 --- a/src/app/checkout/reducers/checkout.reducer.ts +++ b/src/app/checkout/reducers/checkout.reducer.ts @@ -7,7 +7,7 @@ import { Action, ActionReducer } from '@ngrx/store'; export const initialState: CheckoutState = new CheckoutStateRecord() as CheckoutState; export const checkoutReducer: ActionReducer = - (state: CheckoutState = initialState, { type, payload }: Action): CheckoutState => { + (state: CheckoutState = initialState, { type, payload }: any): CheckoutState => { let _lineItems, _lineItemEntities, _lineItemIds, _lineItem, _lineItemEntity, _lineItemId, diff --git a/src/app/core/index.ts b/src/app/core/index.ts index b5de053c..69e7133c 100644 --- a/src/app/core/index.ts +++ b/src/app/core/index.ts @@ -43,10 +43,12 @@ export function httpInterceptor( imports: [ // Were not working on modules sice update to rc-5 // TO BE moved to respective modules. - EffectsModule.run(AuthenticationEffects), - EffectsModule.run(ProductEffects), - EffectsModule.run(CheckoutEffects), - EffectsModule.run(UserEffects) + EffectsModule.forRoot([ + AuthenticationEffects, + ProductEffects, + CheckoutEffects, + UserEffects + ]) ], providers: [ VariantParserService, diff --git a/src/app/home/reducers/search.actions.ts b/src/app/home/reducers/search.actions.ts index fb9d5105..1b686fc4 100644 --- a/src/app/home/reducers/search.actions.ts +++ b/src/app/home/reducers/search.actions.ts @@ -10,7 +10,7 @@ export class SearchActions { * Fetches all the filters that have been getSelectedProduct * Used in filterSummaryComponent */ - getAllFiltes(): Action { + getAllFiltes() { return { type: SearchActions.GET_ALL_FILTERS }; } @@ -19,7 +19,7 @@ export class SearchActions { * @param taxon Class Taxon * Get's triggered on checking the checkboxes in TaxonsComponent. */ - addFilter(taxon: any): Action { + addFilter(taxon: any) { return { type: SearchActions.ADD_FILTER, payload: taxon diff --git a/src/app/home/reducers/search.reducers.ts b/src/app/home/reducers/search.reducers.ts index 9be11300..371c3517 100644 --- a/src/app/home/reducers/search.reducers.ts +++ b/src/app/home/reducers/search.reducers.ts @@ -6,7 +6,7 @@ import { SearchState, SearchStateRecord } from './search.state'; export const initialState: SearchState = new SearchStateRecord() as SearchState; export const searchReducer: ActionReducer = - (state: SearchState = initialState, {type, payload}: Action): SearchState => { + (state: SearchState = initialState, {type, payload}: any): SearchState => { switch (type) { case SearchActions.ADD_FILTER: let filterAlreadyPresent = false; diff --git a/src/app/product/actions/product-actions.ts b/src/app/product/actions/product-actions.ts index a970e5a7..00f0c4ac 100644 --- a/src/app/product/actions/product-actions.ts +++ b/src/app/product/actions/product-actions.ts @@ -11,11 +11,11 @@ export class ProductActions { static GET_ALL_TAXONOMIES = 'GET_ALL_TAXONOMIES'; static GET_ALL_TAXONOMIES_SUCCESS = 'GET_ALL_TAXONOMIES_SUCCESS'; - getAllProducts(): Action { + getAllProducts() { return { type: ProductActions.GET_ALL_PRODUCTS }; } - getProductDetail(id: string): Action { + getProductDetail(id: string) { return { type: ProductActions.GET_PRODUCT_DETAIL, payload: id @@ -23,29 +23,29 @@ export class ProductActions { } // change products type to Product[] - getAllProductsSuccess(products: any): Action { + getAllProductsSuccess(products: any) { return { type: ProductActions.GET_ALL_PRODUCTS_SUCCESS, payload: products }; } - getProductDetailSuccess(product: Product): Action { + getProductDetailSuccess(product: Product) { return { type: ProductActions.GET_PRODUCT_DETAIL_SUCCESS, payload: product }; } - clearSelectedProduct(): Action { + clearSelectedProduct() { return { type: ProductActions.CLEAR_SELECTED_PRODUCT }; } - getAllTaxonomies(): Action { + getAllTaxonomies() { return { type: ProductActions.GET_ALL_TAXONOMIES }; } - getAllTaxonomiesSuccess(taxonomies: any): Action { + getAllTaxonomiesSuccess(taxonomies: any) { return { type: ProductActions.GET_ALL_TAXONOMIES_SUCCESS, payload: taxonomies diff --git a/src/app/product/effects/product.effects.ts b/src/app/product/effects/product.effects.ts index fdbdcf7a..368a3ede 100644 --- a/src/app/product/effects/product.effects.ts +++ b/src/app/product/effects/product.effects.ts @@ -19,18 +19,18 @@ export class ProductEffects { @Effect() GetAllProducts$: Observable = this.actions$ .ofType(ProductActions.GET_ALL_PRODUCTS) - .switchMap((action: Action) => this.productService.getProducts()) + .switchMap((action: any) => this.productService.getProducts()) .map((data: any) => this.productActions.getAllProductsSuccess({products: data})); @Effect() GetAllTaxonomies$: Observable = this.actions$ .ofType(ProductActions.GET_ALL_TAXONOMIES) - .switchMap((action: Action) => this.productService.getTaxonomies()) + .switchMap((action: any) => this.productService.getTaxonomies()) .map((data: any) => this.productActions.getAllTaxonomiesSuccess({taxonomies: data})); @Effect() GetProductDetail$: Observable = this.actions$ .ofType(ProductActions.GET_PRODUCT_DETAIL) - .switchMap((action: Action) => this.productService.getProduct(action.payload)) + .switchMap((action: any) => this.productService.getProduct(action.payload)) .map((data: any) => this.productActions.getProductDetailSuccess(data)); } diff --git a/src/app/product/reducers/product-reducer.ts b/src/app/product/reducers/product-reducer.ts index a0234d9e..c51d00f9 100644 --- a/src/app/product/reducers/product-reducer.ts +++ b/src/app/product/reducers/product-reducer.ts @@ -7,7 +7,7 @@ import { Action, ActionReducer } from '@ngrx/store'; export const initialState: ProductState = new ProductStateRecord() as ProductState; export const productReducer: ActionReducer = - (state: ProductState = initialState, { type, payload }: Action): ProductState => { + (state: ProductState = initialState, { type, payload }: any): ProductState => { switch (type) { case ProductActions.GET_PRODUCT_DETAIL_SUCCESS: diff --git a/src/app/user/actions/user.actions.ts b/src/app/user/actions/user.actions.ts index cc8caa7e..3e37236d 100644 --- a/src/app/user/actions/user.actions.ts +++ b/src/app/user/actions/user.actions.ts @@ -5,11 +5,11 @@ export class UserActions { static GET_USER_ORDERS = 'GET_USER_ORDERS'; static GET_USER_ORDERS_SUCCESS = 'GET_USER_ORDERS_SUCCESS'; - getUserOrders(): Action { + getUserOrders() { return { type: UserActions.GET_USER_ORDERS }; } - getUserOrdersSuccess(orders: Order[]): Action { + getUserOrdersSuccess(orders: Order[]) { return { type: UserActions.GET_USER_ORDERS_SUCCESS, payload: orders }; } } diff --git a/src/app/user/reducers/user.reducer.ts b/src/app/user/reducers/user.reducer.ts index b2f89de4..b9344995 100644 --- a/src/app/user/reducers/user.reducer.ts +++ b/src/app/user/reducers/user.reducer.ts @@ -12,7 +12,7 @@ export /** * @returns {UserState} */ const userReducer: ActionReducer = - (state: UserState = initialState, { type, payload }: Action): UserState => { + (state: UserState = initialState, { type, payload }: any): UserState => { switch (type) { case UserActions.GET_USER_ORDERS_SUCCESS: return state.merge({ orders: payload }) as UserState; diff --git a/yarn.lock b/yarn.lock index bd540564..034c5827 100644 --- a/yarn.lock +++ b/yarn.lock @@ -184,17 +184,21 @@ version "1.2.0" resolved "https://registry.yarnpkg.com/@ngrx/core/-/core-1.2.0.tgz#882b46abafa2e0e6d887cb71a1b2c2fa3e6d0dc6" -"@ngrx/effects@^2.0.4": - version "2.0.4" - resolved "https://registry.yarnpkg.com/@ngrx/effects/-/effects-2.0.4.tgz#418eee5e1032fa66de5bbf1855653bb1951f12a4" +"@ngrx/effects@^4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@ngrx/effects/-/effects-4.0.1.tgz#9403d5668c70217eb5c84ba7a5ffebbbcf507b34" -"@ngrx/store-devtools@^3.2.3": - version "3.2.3" - resolved "https://registry.yarnpkg.com/@ngrx/store-devtools/-/store-devtools-3.2.3.tgz#3e89ac95ba7e96ebb20180a61d731954078728fb" +"@ngrx/router-store@^4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@ngrx/router-store/-/router-store-4.0.0.tgz#22b50297395669834df09c46b5a15a8eb56b871d" -"@ngrx/store@^2.2.1": - version "2.2.1" - resolved "https://registry.yarnpkg.com/@ngrx/store/-/store-2.2.1.tgz#316ec1e43aa5a0166e5e6e1aa2c34a4049386510" +"@ngrx/store-devtools@^4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@ngrx/store-devtools/-/store-devtools-4.0.0.tgz#b79c24773217df7fd9735ad21f9cbf2533c96e04" + +"@ngrx/store@^4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@ngrx/store/-/store-4.0.0.tgz#714d82056f0eb31518ca85a68a5cfecfc12cc50b" "@ngtools/json-schema@1.1.0": version "1.1.0" @@ -6202,14 +6206,14 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@2.3, "typescript@>=2.0.0 <2.4.0": - version "2.3.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.4.tgz#3d38321828231e434f287514959c37a82b629f42" - -typescript@2.4.1: +typescript@2.4.1, typescript@^2.4.0: version "2.4.1" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.1.tgz#c3ccb16ddaa0b2314de031e7e6fee89e5ba346bc" +"typescript@>=2.0.0 <2.4.0": + version "2.3.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.4.tgz#3d38321828231e434f287514959c37a82b629f42" + uglify-js@2.8.x, uglify-js@^2.6, uglify-js@^2.8.5: version "2.8.15" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.15.tgz#835dd4cd5872554756e6874508d0d0561704d94d" @@ -6821,6 +6825,10 @@ yn@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/yn/-/yn-1.2.0.tgz#d237a4c533f279b2b89d3acac2db4b8c795e4a63" -zone.js@0.8.7, zone.js@^0.8.4: +zone.js@0.8.12: + version "0.8.12" + resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.12.tgz#86ff5053c98aec291a0bf4bbac501d694a05cfbb" + +zone.js@^0.8.4: version "0.8.7" resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.7.tgz#14c360b962ff86efc4f507f34428391eb1b28fb9" From 13f84c1a8e8571a6b4f8abc66293928aa5cb7961 Mon Sep 17 00:00:00 2001 From: Pankaj Rawat Date: Wed, 2 Aug 2017 08:06:34 +0530 Subject: [PATCH 2/6] added track by in prouct list --- src/app/home/content/product-list/product-list.component.html | 2 +- src/app/home/content/product-list/product-list.component.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/home/content/product-list/product-list.component.html b/src/app/home/content/product-list/product-list.component.html index 80d9ed3f..7846cd4f 100644 --- a/src/app/home/content/product-list/product-list.component.html +++ b/src/app/home/content/product-list/product-list.component.html @@ -2,7 +2,7 @@