app-saga-utils
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,4 +0,3 @@ | ||
export * from "./IWatcher"; | ||
export * from "./RootSaga"; | ||
export * from "./Watcher"; | ||
export * from "./WatchFunction"; | ||
export { DependencyResolver, Watcher, WatchFunction, } from './types'; | ||
export * from './RootSagaBase'; | ||
export * from './WatcherBase'; |
@@ -1,5 +0,3 @@ | ||
export * from "./IWatcher"; | ||
export * from "./RootSaga"; | ||
export * from "./Watcher"; | ||
export * from "./WatchFunction"; | ||
export * from './RootSagaBase'; | ||
export * from './WatcherBase'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,10 +0,9 @@ | ||
import { SagaMiddleware } from "redux-saga"; | ||
import { WatchFunction } from "./WatchFunction"; | ||
import { IWatcher } from "./IWatcher"; | ||
import { SagaMiddleware } from 'redux-saga'; | ||
import { Watcher, WatchFunction } from './types'; | ||
export declare abstract class RootSagaBase { | ||
protected watchFunctions: WatchFunction[]; | ||
protected addWatchers(baseWatchers: IWatcher[]): void; | ||
protected addWatcher(baseWatcher: IWatcher): void; | ||
protected addWatchers(baseWatchers: Watcher[]): void; | ||
protected addWatcher(baseWatcher: Watcher): void; | ||
constructor(); | ||
run(sagaMiddleware: SagaMiddleware): void; | ||
} |
@@ -1,11 +0,10 @@ | ||
import { AppAction } from "app-redux-utils"; | ||
import { IWatcher } from "./IWatcher"; | ||
import { WatchFunction } from "./WatchFunction"; | ||
export declare abstract class WatcherBase implements IWatcher { | ||
import { Constructor, DependencyResolver, Watcher, WatchFunction } from './types'; | ||
export declare abstract class WatcherBase<TSaga> implements Watcher { | ||
private readonly sagaInstanceType; | ||
private readonly watcher; | ||
protected constructor(sagaInstanceType: Constructor<TSaga>, container?: DependencyResolver); | ||
watchFunctions: WatchFunction[]; | ||
protected constructor(); | ||
private getSagaWithCallbackAction; | ||
protected watchLatest(actionType: string, saga: (action: AppAction) => void): void; | ||
protected watchEvery(actionType: string, saga: (action: AppAction) => void): void; | ||
protected watchThrottle(actionType: string, saga: (action: AppAction) => void, throttleInMilliseconds?: number): void; | ||
protected get watchLatest(): (actionType: string, sagaName: keyof TSaga) => void; | ||
protected get watchEvery(): (actionType: string, sagaName: keyof TSaga) => void; | ||
protected get watchThrottle(): (actionType: string, sagaName: keyof TSaga, throttleInMilliseconds?: number | undefined) => void; | ||
} |
@@ -1,35 +0,18 @@ | ||
import { all, put, takeEvery, takeLatest, throttle } from "@redux-saga/core/effects"; | ||
import { sagaWatcher } from './sagaWatcher'; | ||
export class WatcherBase { | ||
constructor() { | ||
this.watchFunctions = []; | ||
constructor(sagaInstanceType, container) { | ||
this.sagaInstanceType = sagaInstanceType; | ||
this.watcher = sagaWatcher(sagaInstanceType, container); | ||
this.watchFunctions = this.watcher.watchFunctions; | ||
} | ||
getSagaWithCallbackAction(saga) { | ||
return function* (action) { | ||
yield saga(action); | ||
if (!action.stopPropagation) { | ||
const actions = action.getActions(); | ||
const putActionEffects = actions.map(action => put(action())); | ||
yield all(putActionEffects); | ||
} | ||
}; | ||
get watchLatest() { | ||
return this.watcher.watchLatest; | ||
} | ||
watchLatest(actionType, saga) { | ||
const sagaWithCallbackAction = this.getSagaWithCallbackAction(saga); | ||
this.watchFunctions.push(function* () { | ||
yield takeLatest(actionType, sagaWithCallbackAction); | ||
}); | ||
get watchEvery() { | ||
return this.watcher.watchEvery; | ||
} | ||
watchEvery(actionType, saga) { | ||
const sagaWithCallbackAction = this.getSagaWithCallbackAction(saga); | ||
this.watchFunctions.push(function* () { | ||
yield takeEvery(actionType, sagaWithCallbackAction); | ||
}); | ||
get watchThrottle() { | ||
return this.watcher.watchThrottle; | ||
} | ||
watchThrottle(actionType, saga, throttleInMilliseconds = 1000) { | ||
const sagaWithCallbackAction = this.getSagaWithCallbackAction(saga); | ||
this.watchFunctions.push(function* () { | ||
yield throttle(throttleInMilliseconds, actionType, sagaWithCallbackAction); | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=WatcherBase.js.map |
{ | ||
"name": "app-saga-utils", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Helpful utils for redux-saga", | ||
@@ -24,9 +24,9 @@ "contributors": [ | ||
"dependencies": { | ||
"app-redux-utils": "1.1.1", | ||
"app-redux-utils": "1.3.5", | ||
"redux-saga": "1.1.3" | ||
}, | ||
"devDependencies": { | ||
"tslint": "6.1.2", | ||
"tslint": "6.1.3", | ||
"tslint-eslint-rules": "5.4.0", | ||
"typescript": "3.9.7" | ||
"typescript": "4.2.4" | ||
}, | ||
@@ -33,0 +33,0 @@ "repository": { |
# Installation | ||
```bush | ||
@@ -10,17 +11,22 @@ npm install app-saga-utils | ||
// User.watcher.ts | ||
import { Watcher } from "app-saga-utils"; | ||
import { WatcherBase } from 'app-saga-utils'; | ||
import { UserActions } from "../redux"; | ||
import { UserSaga } from "./User.saga"; | ||
import { UserActions } from '../redux'; | ||
import { UserSaga } from './User.saga'; | ||
export class UserWatcher extends Watcher { | ||
constructor() { | ||
super(); | ||
export class UserWatcher extends WatcherBase<UserSaga> { | ||
constructor() { | ||
super(UserSaga); | ||
this.watchLatest( | ||
UserActions.SET_USER, | ||
UserSaga.setUser | ||
); | ||
} | ||
this.watchLatest( | ||
UserActions.SET_USER, | ||
'setUser' | ||
); | ||
} | ||
} | ||
// or | ||
export const userWatcher = sagaWatcher(UserSaga); | ||
watcher.watchLatest(UserActions.SET_USER, 'setUser'); | ||
``` | ||
@@ -30,17 +36,17 @@ | ||
// RootSagaBase.ts | ||
import { RootSaga } from "app-saga-utils"; | ||
import { RootSagaBase } from 'app-saga-utils'; | ||
import { UserWatcher } from "./User.watcher"; | ||
import { UserWatcher } from './User.watcher'; | ||
export class RootSagaBase extends RootSaga { | ||
constructor() { | ||
super(); | ||
export class RootSaga extends RootSagaBase { | ||
constructor() { | ||
super(); | ||
this.addWatchers([ | ||
new UserWatcher(), | ||
]); | ||
} | ||
this.addWatchers([ | ||
new UserWatcher(), | ||
]); | ||
} | ||
} | ||
``` | ||
and register your saga like usually `new RootSagaBase().run(sagaMiddleware);` | ||
and register your saga like usually `new RootSagaBase().run(sagaMiddleware);` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18938
51
235
51
+ Addedapp-redux-utils@1.3.5(transitive)
+ Addedredux@4.1.0(transitive)
- Removedapp-redux-utils@1.1.1(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedredux@4.0.5(transitive)
- Removedsymbol-observable@1.2.0(transitive)
Updatedapp-redux-utils@1.3.5