Skip to content

Commit

Permalink
get rid of "hydux-mutator"
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Jul 15, 2018
1 parent c104a2c commit 1b726ed
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 93 deletions.
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"compare-versions": "3.3.0",
"deep-equal": "1.0.1",
"electron-log": "2.2.16",
"electron-rpc-api": "0.2.0",
"electron-rpc-api": "0.2.1",
"electron-unhandled": "1.1.0",
"electron-updater": "2.23.3",
"fs-json-store": "2.0.0",
Expand All @@ -85,7 +85,7 @@
"keepasshttp-client": "2.2.6",
"keytar": "4.2.1",
"rolling-rate-limiter": "0.1.11",
"rxjs": "6.2.1",
"rxjs": "6.2.2",
"valid-url": "1.0.9"
},
"devDependencies": {
Expand All @@ -112,7 +112,7 @@
"@types/glob": "5.0.35",
"@types/html-webpack-plugin": "2.30.3",
"@types/jasmine": "2.8.8",
"@types/karma": "1.7.4",
"@types/karma": "1.7.5",
"@types/keytar": "4.0.1",
"@types/mini-css-extract-plugin": "0.2.0",
"@types/mkdirp": "0.5.2",
Expand All @@ -122,11 +122,11 @@
"@types/source-map": "0.5.7",
"@types/stacktrace-js": "0.0.32",
"@types/systemjs": "0.20.6",
"@types/tapable": "1.0.3",
"@types/tapable": "1.0.4",
"@types/uglifyjs-webpack-plugin": "1.1.0",
"@types/valid-url": "1.0.2",
"@types/webdriverio": "4.10.3",
"@types/webpack": "4.4.5",
"@types/webpack": "4.4.6",
"@types/webpack-dev-server": "2.9.5",
"@types/webpack-env": "1.13.6",
"@types/webpack-merge": "4.1.3",
Expand All @@ -142,9 +142,9 @@
"cross-env": "5.2.0",
"cross-spawn": "6.0.5",
"css-loader": "1.0.0",
"cssnano": "4.0.1",
"cssnano": "4.0.2",
"devtron": "1.4.0",
"electron": "2.0.4",
"electron": "2.0.5",
"electron-builder": "20.20.4",
"exports-loader": "0.7.0",
"file-loader": "1.1.11",
Expand All @@ -154,6 +154,7 @@
"html-loader": "0.5.5",
"html-webpack-plugin": "4.0.0-alpha",
"hydux-mutator": "0.1.11",
"immer": "1.3.1",
"jasmine": "3.1.0",
"karma": "2.0.4",
"karma-chrome-launcher": "2.2.0",
Expand Down Expand Up @@ -182,7 +183,7 @@
"raw-loader": "0.5.1",
"resolve-url-loader": "2.3.0",
"rewiremock": "3.7.4",
"rxjs-compat": "6.2.1",
"rxjs-compat": "6.2.2",
"sass-lint": "1.12.1",
"sass-loader": "7.0.3",
"script-loader": "0.7.2",
Expand Down
2 changes: 1 addition & 1 deletion src/web/src/app/+accounts/accounts.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class AccountsEffects {
const {account, webView, unSubscribeOn} = payload;
const {type, login, entryUrl} = account.accountConfig;
const observable = this.electronService.webViewCaller(webView, type).pipe(
exhaustMap((caller) => caller("notification", {unSubscribeOn, timeoutMs: 0})({entryUrl})),
exhaustMap((caller) => caller("notification", {unSubscribeOn})({entryUrl})),
map((notification) => ACCOUNTS_ACTIONS.NotificationPatch({login, notification})),
);

Expand Down
22 changes: 14 additions & 8 deletions src/web/src/app/components/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import immer from "immer";
import {ComponentFixture, TestBed, TestModuleMetadata} from "@angular/core/testing";
import {Location} from "@angular/common";
import {RouterTestingModule} from "@angular/router/testing";
import {setIn} from "hydux-mutator";
import {Store, StoreModule} from "@ngrx/store";

import {AppComponent} from "./app.component";
Expand Down Expand Up @@ -42,9 +42,12 @@ describe(AppComponent.name, () => {
const locationPathStub = jasmine.createSpy().and.returnValue({indexOf: hashIndexOfSpy});

testBed.resetTestingModule();
testBed = initTestEnvironment((tb) => tb.configureTestingModule(setIn(moduleDef, (_) => _.providers, [{
provide: Location, useValue: {path: locationPathStub},
}])));

testBed = initTestEnvironment((tb) => tb.configureTestingModule(immer(moduleDef, (draft) => {
draft.providers = [
{provide: Location, useValue: {path: locationPathStub}},
];
})));
await testBed.compileComponents();
fixture = testBed.createComponent(AppComponent);

Expand All @@ -60,10 +63,13 @@ describe(AppComponent.name, () => {
const event = new KeyboardEvent("keyup", {key: ESC_KEY});

testBed.resetTestingModule();
testBed = initTestEnvironment((tb) => tb.configureTestingModule(setIn(moduleDef, (_) => _.providers, [
{provide: Location, useValue: {path: locationPathStub}},
{provide: Store, useValue: {dispatch: storeDispatchStub}},
])));
testBed = initTestEnvironment((tb) => tb.configureTestingModule(immer(moduleDef, (draft) => {
draft.providers = [
{provide: Location, useValue: {path: locationPathStub}},
{provide: Store, useValue: {dispatch: storeDispatchStub}},
];
})));

await testBed.compileComponents();
fixture = testBed.createComponent(AppComponent);

Expand Down
20 changes: 7 additions & 13 deletions src/web/src/app/store/reducers/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import immer from "immer";
import {createFeatureSelector, createSelector} from "@ngrx/store";
import {UnionOf} from "unionize";
import {updateIn} from "hydux-mutator";

import * as fromRoot from "src/web/src/app/store/reducers/root";
import {ACCOUNTS_ACTIONS} from "src/web/src/app/store/actions";
Expand Down Expand Up @@ -72,22 +72,16 @@ export function reducer(state = initialState, action: UnionOf<typeof ACCOUNTS_AC
NotificationPatch: ({login, notification}) => {
const {index} = selectAccountByLogin(state.accounts, login);

return updateIn(
state,
(_) => _.accounts[index].notifications,
(_) => ({..._, ...notification}),
[index],
);
return immer(state, (draft) => {
draft.accounts[index].notifications = {...draft.accounts[index].notifications, ...notification};
});
},
PatchProgress: ({login, patch}) => {
const {index} = selectAccountByLogin(state.accounts, login);

return updateIn(
state,
(_) => _.accounts[index].progress,
(progress) => ({...progress, ...patch}),
[index],
);
return immer(state, (draft) => {
draft.accounts[index].progress = {...draft.accounts[index].progress, ...patch};
});
},
default: () => state,
});
Expand Down
14 changes: 6 additions & 8 deletions src/web/src/app/store/reducers/options.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {createFeatureSelector, createSelector} from "@ngrx/store";
import {UnionOf} from "unionize";

import * as fromRoot from "./root";
import {Config, Settings} from "src/shared/model/options";
import {ElectronContextLocations} from "src/shared/model/electron";
import {OPTIONS_ACTIONS} from "src/web/src/app/store/actions";
import {pickBaseConfigProperties} from "src/shared/util";
import {UnionOf} from "unionize";
import {updateIn} from "hydux-mutator";

export const featureName = "options";

Expand Down Expand Up @@ -40,14 +39,13 @@ const initialState: State = {

export function reducer(state = initialState, action: UnionOf<typeof OPTIONS_ACTIONS>): State {
return OPTIONS_ACTIONS.match(action, {
InitResponse: (payload) => ({...state, ...payload}),
InitResponse: (statePatch) => ({...state, ...statePatch}),
GetConfigResponse: (config) => ({...state, config}),
GetSettingsResponse: (settings) => ({...state, settings}),
PatchProgress: (patch) => updateIn(
state,
(_) => _.progress,
(progress) => ({...progress, ...patch}),
),
PatchProgress: (progressPatch) => ({
...state,
progress: {...state.progress, ...progressPatch},
}),
default: () => state,
});
}
Expand Down
Loading

0 comments on commit 1b726ed

Please sign in to comment.