Skip to content

Commit

Permalink
Upgraded to angular 5 and ngrx 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Jan 11, 2018
1 parent a196cca commit 6401caa
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 102 deletions.
34 changes: 17 additions & 17 deletions package.json
Expand Up @@ -35,24 +35,24 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^4.3.1",
"@angular/animations": "^5.2.0",
"@angular/cli": "^1.2.4",
"@angular/common": "^4.3.1",
"@angular/compiler": "^4.3.1",
"@angular/compiler-cli": "^4.3.1",
"@angular/core": "^4.3.1",
"@angular/forms": "^4.3.1",
"@angular/http": "^4.3.1",
"@angular/platform-browser": "^4.3.1",
"@angular/platform-browser-dynamic": "^4.3.1",
"@angular/router": "^4.3.1",
"@ngrx/core": "^1.2.0",
"@ngrx/effects": "^2.0.4",
"@ngrx/store": "^2.2.3",
"@ngrx/store-devtools": "^3.2.4",
"@ngx-translate/core": "^8.0.0",
"@ngx-translate/http-loader": "^2.0.0",
"@webcomponents/custom-elements": "^1.0.4",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/compiler-cli": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/platform-server": "^5.2.0",
"@angular/router": "^5.2.0",
"@ngrx/effects": "^4.1.1",
"@ngrx/store": "^4.1.1",
"@ngrx/store-devtools": "^4.1.1",
"@ngx-translate/core": "^9.0.2",
"@ngx-translate/http-loader": "^2.0.1",
"@webcomponents/custom-elements": "^1.0.6",
"body-parser": "^1.17.1",
"bootstrap": "4.0.0-alpha.5",
"clarity-angular": "^0.10.13",
Expand Down
5 changes: 5 additions & 0 deletions src/app/actions/index.ts
@@ -1,4 +1,9 @@
import { Action } from '@ngrx/store';
import { Action as queryAction } from './query/query';
import { Action as gqlSchemaAction } from './gql-schema/gql-schema';

export interface ActionWithPayload extends Action {
payload?: object;
}

export type Action = queryAction | gqlSchemaAction;
2 changes: 2 additions & 0 deletions src/app/actions/layout/layout.ts
Expand Up @@ -28,3 +28,5 @@ export class NotifyExperimentalAction implements Action {

constructor(public windowId: string) {}
}

export type Action = StartLoadingAction | StopLoadingAction | SetWindowNameAction | NotifyExperimentalAction;
8 changes: 4 additions & 4 deletions src/app/app.module.ts
Expand Up @@ -18,7 +18,7 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader';

import { SharedModule } from './shared/shared.module';

import { appReducer } from './reducers';
import { reducer, metaReducers } from './reducers';

import { QueryEffects } from './effects/query';

Expand Down Expand Up @@ -69,9 +69,9 @@ const providers = [
SharedModule,
ComponentModule,
DocViewerModule,
StoreModule.provideStore(appReducer),
EffectsModule.run(QueryEffects),
StoreDevtoolsModule.instrumentOnlyWithExtension(),
StoreModule.forRoot(reducer, { metaReducers }),
EffectsModule.forRoot([ QueryEffects ]),
StoreDevtoolsModule.instrument(),
ToastModule.forRoot(),
TranslateModule.forRoot({
loader: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/reducers/gql-schema/gql-schema.ts
Expand Up @@ -19,7 +19,7 @@ const initialState: State = {
allowIntrospection: true
};

export function gqlSchemaReducer(state = initialState, action: Action): State {
export function gqlSchemaReducer(state = initialState, action: gqlSchema.Action): State {
switch (action.type) {
case gqlSchema.SET_INTROSPECTION:
case gqlSchema.SET_INTROSPECTION_FROM_DB:
Expand Down
32 changes: 12 additions & 20 deletions src/app/reducers/index.ts
@@ -1,5 +1,5 @@
import { combineReducers, Action, ActionReducer } from '@ngrx/store';
import { compose } from '@ngrx/core/compose';
import { combineReducers, Action, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store';
import { compose } from '@ngrx/store';
import { localStorageSync } from 'ngrx-store-localstorage';

import { environment } from '../../environments/environment';
Expand Down Expand Up @@ -44,29 +44,21 @@ export interface State {
}

// Meta reducer to log actions
export const log = (reducer) => (state: State, action: Action) => {
export const log = (_reducer) => (state: State, action: Action) => {
if (!environment.production) {
console.log(action.type, action);
}
return reducer(state, action);
return _reducer(state, action);
};

export const keySerializer = (key) => 'altair_' + key;

// Needed to fix the error encountered resolving symbol values statically error for the compose() method
export function createReducer() {
const reducer = compose(
localStorageSync({ keys: ['windows', 'windowsMeta'], rehydrate: true, storageKeySerializer: keySerializer}),
log,
combineReducers
)({
windows: fromWindows.windows(combineReducers(perWindowReducers)),
windowsMeta: fromWindowsMeta.windowsMetaReducer
});
export const metaReducers: MetaReducer<any>[] = [
localStorageSync({ keys: ['windows', 'windowsMeta'], rehydrate: true, storageKeySerializer: keySerializer }),
log
];

return reducer;
}

export function appReducer(state: State, action: Action) {
return createReducer()(state, action);
}
export const reducer: ActionReducerMap<State> = {
windows: fromWindows.windows(combineReducers(perWindowReducers)),
windowsMeta: fromWindowsMeta.windowsMetaReducer
};
2 changes: 1 addition & 1 deletion src/app/reducers/layout/layout.ts
Expand Up @@ -12,7 +12,7 @@ const initialState: State = {
title: 'New window'
};

export function layoutReducer(state = initialState, action: Action): State {
export function layoutReducer(state = initialState, action: layout.Action): State {
switch (action.type) {
case layout.START_LOADING:
return Object.assign({}, state, { isLoading: true });
Expand Down
4 changes: 2 additions & 2 deletions src/app/reducers/windows.ts
Expand Up @@ -19,6 +19,7 @@ export function windows(reducer: ActionReducer<any>) {
return function(state = initialState, action: any) {

const _state = Object.assign({}, state);
let _windowState = _state[action.windowId];

switch (action.type) {
case windowsActions.ADD_WINDOW:
Expand All @@ -40,7 +41,7 @@ export function windows(reducer: ActionReducer<any>) {
const windowTitle = window.title;

// Using JSON.parse and JSON.stringify instead of Object.assign for deep cloning
const _windowState = JSON.parse(JSON.stringify(initWindowState));
_windowState = JSON.parse(JSON.stringify(initWindowState));
_windowState.windowId = windowKey;
_windowState.layout.title = _windowState.layout.title || windowTitle;

Expand All @@ -57,7 +58,6 @@ export function windows(reducer: ActionReducer<any>) {

return Object.assign({}, _state);
default:
const _windowState = _state[action.windowId];
if (!_windowState) {
// If the provided windowId is invalid, log the error and just return the state
console.warn('Invalid window ID provided.');
Expand Down
121 changes: 64 additions & 57 deletions yarn.lock
Expand Up @@ -47,9 +47,9 @@
minimist "^1.2.0"
rxjs "^5.5.2"

"@angular/animations@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/animations/-/animations-4.4.6.tgz#fa661899a8a4e38cb7c583c7a5c97ce65d592a35"
"@angular/animations@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/animations/-/animations-5.2.0.tgz#a3ce02c01b074f0de7c2c23c1f08b4a00f0bec5f"
dependencies:
tslib "^1.7.1"

Expand Down Expand Up @@ -117,83 +117,82 @@
optionalDependencies:
node-sass "^4.3.0"

"@angular/common@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/common/-/common-4.4.6.tgz#4b81420724e0828a0e839b95a55eb1a7e83918f2"
"@angular/common@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/common/-/common-5.2.0.tgz#d184fb90763da1d1bab1f6c4f41dd80c79e47506"
dependencies:
tslib "^1.7.1"

"@angular/compiler-cli@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/compiler-cli/-/compiler-cli-4.4.6.tgz#bafd3d1e260e99087eb9a8cf7532dbd603abb9b1"
"@angular/compiler-cli@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/compiler-cli/-/compiler-cli-5.2.0.tgz#336b6d0127c69f25637cbcd82a4b76de6f3a2cce"
dependencies:
"@angular/tsc-wrapped" "4.4.6"
chokidar "^1.4.2"
minimist "^1.2.0"
reflect-metadata "^0.1.2"
tsickle "^0.26.0"

"@angular/compiler@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-4.4.6.tgz#2ee1faf25b757e1d128979074be7fae529b3bc20"
"@angular/compiler@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-5.2.0.tgz#3798795b97e60b47fdc0a150e062dedb4ac39467"
dependencies:
tslib "^1.7.1"

"@angular/core@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/core/-/core-4.4.6.tgz#13031fd10dcfe438875419b38f21120958bc2354"
"@angular/core@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/core/-/core-5.2.0.tgz#f91bf83de3e0defd621adcc007c25d7cd5a85af1"
dependencies:
tslib "^1.7.1"

"@angular/forms@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/forms/-/forms-4.4.6.tgz#fe64ace42435c1b80f49034b7c41ce8caf14a44a"
"@angular/forms@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/forms/-/forms-5.2.0.tgz#b5fb6b9ba97334bca0e3202d7fee6b9162cbc824"
dependencies:
tslib "^1.7.1"

"@angular/http@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/http/-/http-4.4.6.tgz#0af680c6710bdc026d940e225cfd0f6a5c005d0c"
"@angular/http@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/http/-/http-5.2.0.tgz#ebffff97e6c7baa3609a2d68e982bf990b1c72dc"
dependencies:
tslib "^1.7.1"

"@angular/platform-browser-dynamic@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/platform-browser-dynamic/-/platform-browser-dynamic-4.4.6.tgz#4d3d9a6a7bf2cf3de4058a615ae059eff641fa36"
"@angular/platform-browser-dynamic@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/platform-browser-dynamic/-/platform-browser-dynamic-5.2.0.tgz#6d3e074363606b559c3319d2433d1c08ccaefbad"
dependencies:
tslib "^1.7.1"

"@angular/platform-browser@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/platform-browser/-/platform-browser-4.4.6.tgz#a9839c547e1b654fa1d24a89780c8ba6ab8dcce0"
"@angular/platform-browser@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/platform-browser/-/platform-browser-5.2.0.tgz#89cbc8abf54171ecf3dd9a40970b4982eecc9f73"
dependencies:
tslib "^1.7.1"

"@angular/router@^4.3.1":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/router/-/router-4.4.6.tgz#0f6ad29ae0ff8d2c9ea379bd320447217b7ec866"
"@angular/platform-server@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/platform-server/-/platform-server-5.2.0.tgz#33fa4c310fc48ee77eb94109db45b2af6c37444e"
dependencies:
domino "^1.0.29"
tslib "^1.7.1"
xhr2 "^0.1.4"

"@angular/tsc-wrapped@4.4.6":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@angular/tsc-wrapped/-/tsc-wrapped-4.4.6.tgz#16787cbbf50bdc7e738123b19c32527f244e178d"
"@angular/router@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@angular/router/-/router-5.2.0.tgz#0a43f1c6add592c9cb0b9846fc157fc5b23ee73d"
dependencies:
tsickle "^0.21.0"

"@ngrx/core@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@ngrx/core/-/core-1.2.0.tgz#882b46abafa2e0e6d887cb71a1b2c2fa3e6d0dc6"
tslib "^1.7.1"

"@ngrx/effects@^2.0.4":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@ngrx/effects/-/effects-2.0.5.tgz#10986923b7193af9b08944e80c5a661ba93a7936"
"@ngrx/effects@^4.1.1":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@ngrx/effects/-/effects-4.1.1.tgz#cb758b8527964b258ea41951f59aa144e3ef9fae"

"@ngrx/store-devtools@^3.2.4":
version "3.2.4"
resolved "https://registry.yarnpkg.com/@ngrx/store-devtools/-/store-devtools-3.2.4.tgz#2ce4d13bf34848a9e51ec87e3b125ed67b51e550"
"@ngrx/store-devtools@^4.1.1":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@ngrx/store-devtools/-/store-devtools-4.1.1.tgz#20745c39c7560fdc05fa4f22638442a7ec7dd676"

"@ngrx/store@^2.2.3":
version "2.2.3"
resolved "https://registry.yarnpkg.com/@ngrx/store/-/store-2.2.3.tgz#e7bd1149f1c44208f1cc4744353f0f98a0f1f57b"
"@ngrx/store@^4.1.1":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@ngrx/store/-/store-4.1.1.tgz#680e34df2775e8852754ed777ffac95bd81b7de0"

"@ngtools/json-schema@1.1.0", "@ngtools/json-schema@^1.1.0":
version "1.1.0"
Expand All @@ -212,11 +211,11 @@
tree-kill "^1.0.0"
webpack-sources "^1.1.0"

"@ngx-translate/core@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@ngx-translate/core/-/core-8.0.0.tgz#751fd6b512d80f3a748d2de8dfc96dfefa29afe0"
"@ngx-translate/core@^9.0.2":
version "9.0.2"
resolved "https://registry.yarnpkg.com/@ngx-translate/core/-/core-9.0.2.tgz#d4cab861e3ea8ea14a6df5dcd744dfeb29fb15e2"

"@ngx-translate/http-loader@^2.0.0":
"@ngx-translate/http-loader@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@ngx-translate/http-loader/-/http-loader-2.0.1.tgz#aa67788e64bfa8652691a77b022b3b4031209113"

Expand Down Expand Up @@ -302,7 +301,7 @@
version "0.0.30"
resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1"

"@webcomponents/custom-elements@^1.0.4":
"@webcomponents/custom-elements@^1.0.6":
version "1.0.6"
resolved "https://registry.yarnpkg.com/@webcomponents/custom-elements/-/custom-elements-1.0.6.tgz#79944e0d7dcb830063308df65560a6fd2bd20a9a"

Expand Down Expand Up @@ -1866,7 +1865,7 @@ cheerio@^0.20.0:
optionalDependencies:
jsdom "^7.0.2"

chokidar@^1.4.1, chokidar@^1.6.0, chokidar@^1.7.0:
chokidar@^1.4.1, chokidar@^1.4.2, chokidar@^1.6.0, chokidar@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
dependencies:
Expand Down Expand Up @@ -2917,6 +2916,10 @@ domhandler@^2.3.0:
dependencies:
domelementtype "1"

domino@^1.0.29:
version "1.0.30"
resolved "https://registry.yarnpkg.com/domino/-/domino-1.0.30.tgz#54a4154ecae968616680f8feba3cedff355c71f4"

domutils@1.1:
version "1.1.6"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.1.6.tgz#bddc3de099b9a2efacc51c623f28f416ecc57485"
Expand Down Expand Up @@ -9043,9 +9046,9 @@ tsconfig@^7.0.0:
strip-bom "^3.0.0"
strip-json-comments "^2.0.0"

tsickle@^0.21.0:
version "0.21.6"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.21.6.tgz#53b01b979c5c13fdb13afb3fb958177e5991588d"
tsickle@^0.26.0:
version "0.26.0"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.26.0.tgz#40b30a2dd6abcb33b182e37596674bd1cfe4039c"
dependencies:
minimist "^1.2.0"
mkdirp "^0.5.1"
Expand Down Expand Up @@ -9805,6 +9808,10 @@ xdg-basedir@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4"

xhr2@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/xhr2/-/xhr2-0.1.4.tgz#7f87658847716db5026323812f818cadab387a5f"

xml-char-classes@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/xml-char-classes/-/xml-char-classes-1.0.0.tgz#64657848a20ffc5df583a42ad8a277b4512bbc4d"
Expand Down

0 comments on commit 6401caa

Please sign in to comment.