Skip to content

Commit 0695e63

Browse files
committed
feat(*): add actions dispatcher
1 parent be9b0ea commit 0695e63

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

.eslintrc.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
{
2525
"files": ["*.ts", "*.tsx"],
2626
"extends": ["plugin:@nrwl/nx/typescript"],
27-
"rules": {}
27+
"rules": {
28+
"@typescript-eslint/no-explicit-any": ["off"],
29+
"@typescript-eslint/no-non-null-assertion": ["off"]
30+
}
2831
},
2932
{
3033
"files": ["*.js", "*.jsx"],

apps/web/src/main.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { enableProdMode } from '@angular/core';
22
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
33

4-
import { AppModule } from './app/app.module';
4+
import { AppModule } from './app/app.module';
55
import { environment } from './environments/environment';
6+
import { devTools } from '@ngneat/effects';
7+
8+
devTools()
69

710
if (environment.production) {
811
enableProdMode();

libs/effects/src/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ export {
22
registerEffects,
33
removeEffects,
44
createEffect,
5-
removeAllEffects,
6-
} from './lib/effects-manager';
7-
export { initEffects } from './lib/effects-manager';
8-
export { actions } from './lib/actions';
5+
removeAllEffects
6+
} from './lib/effects-manager';
7+
export { initEffects } from './lib/effects-manager';
8+
export { actions, actionsDispatcher, Actions } from './lib/actions';
99
export { action as createAction, props, payload } from 'ts-action';
10-
export { ofType } from 'ts-action-operators';
10+
export { ofType } from 'ts-action-operators';
11+

libs/effects/src/lib/actions.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { Subject } from 'rxjs';
2-
import { Action } from './action.model';
2+
import { Action } from './action.model';
33

44
export class Actions extends Subject<Action> {
55
dispatch(value: Action): void {
6-
this.logAction(value);
7-
86
this.next(value);
97
}
10-
11-
logAction(value: Action): void {
12-
const { type, ...props } = value;
13-
const hasPayload = Object.getOwnPropertyNames(props).length > 0;
14-
// logAction(type, null, hasPayload ? props : null);
15-
}
168
}
179

18-
export const actions = new Actions();
10+
export const actions = new Actions();
11+
export const actionsDispatcher = actions.asObservable();

libs/effects/src/lib/effects-manager.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import { Observable, Subject, takeUntil } from 'rxjs';
2-
import { Effect, EffectConfig } from './effect.model';
3-
import { Action } from './action.model';
4-
import { Actions, actions } from './actions';
5-
import { coerceArray } from './utils';
2+
import { Effect, EffectConfig } from './effect.model';
3+
import { Action } from './action.model';
4+
import { Actions, actions } from './actions';
5+
import { coerceArray } from './utils';
6+
67

78
interface EffectsConfig {
8-
logger?: any; // todo type
99
dispatchByDefault?: boolean;
1010
}
1111

12-
class EffectsManager {
13-
private effects = new WeakMap<Effect, Subject<void>>();
12+
export class EffectsManager {
13+
private effects = new WeakMap<Effect, Subject<void>>();
1414
private destroyEffects$ = new Subject<void>();
1515
private config: EffectsConfig;
1616

1717
constructor(config?: EffectsConfig) {
1818
this.config = {
19-
// logger:
2019
dispatchByDefault: false,
21-
...config,
20+
...config
2221
};
2322
}
2423

@@ -36,6 +35,7 @@ class EffectsManager {
3635

3736
removeAllEffects() {
3837
this.destroyEffects$.next();
38+
this.effects = new WeakMap<Effect, Subject<void>>();
3939
}
4040

4141
private subscribeEffect(effect: Effect) {

0 commit comments

Comments
 (0)