Comparing version 0.0.2 to 0.0.3
import { Subscription, Subject } from 'rxjs'; | ||
import { ActionLike } from './types/ActionLike'; | ||
import { Epic } from './types/epic'; | ||
import { ActionLike } from './types/ActionLike.js'; | ||
import { Epic } from './types/epic.js'; | ||
export declare function startEpics<A extends ActionLike, P>(epics: Array<Epic<A, A, P>>, action$: Subject<A>, params: P): Subscription; |
@@ -1,4 +0,4 @@ | ||
export * from './control'; | ||
export * from './operators'; | ||
export * from './types/ActionLike'; | ||
export * from './types/epic'; | ||
export * from './control.js'; | ||
export * from './operators.js'; | ||
export * from './types/ActionLike.js'; | ||
export * from './types/epic.js'; |
@@ -1,5 +0,5 @@ | ||
export * from './control'; | ||
export * from './operators'; | ||
export * from './types/ActionLike'; | ||
export * from './types/epic'; | ||
export * from './control.js'; | ||
export * from './operators.js'; | ||
export * from './types/ActionLike.js'; | ||
export * from './types/epic.js'; | ||
//# sourceMappingURL=index.js.map |
import { OperatorFunction } from 'rxjs'; | ||
import { ActionLike } from './types/ActionLike'; | ||
import { ActionLike } from './types/ActionLike.js'; | ||
export declare function ofType<Input extends ActionLike, Type extends Input['type'], Output extends Input = Extract<Input, ActionLike>>(...types: [Type, ...Type[]]): OperatorFunction<Input, Output>; |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=ActionLike.js.map |
import { Observable } from 'rxjs'; | ||
import { ActionLike } from './ActionLike'; | ||
import { ActionLike } from './ActionLike.js'; | ||
export declare interface Epic<Input extends ActionLike = any, Output extends Input = Input, Dependencies = any> { | ||
(action$: Observable<Input>, dependencies: Dependencies): Observable<Output>; | ||
} |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=epic.js.map |
{ | ||
"name": "epix", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Epics without redux-observable", | ||
@@ -26,8 +26,9 @@ "type": "module", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^3.6.1", | ||
"@typescript-eslint/parser": "^3.6.1", | ||
"eslint": "^6.8.0", | ||
"@typescript-eslint/eslint-plugin": "^4.8.1", | ||
"@typescript-eslint/parser": "^4.8.1", | ||
"eslint": "^7.14.0", | ||
"eslint-config-getkey": "^0.1.2", | ||
"husky": "^4.2.5", | ||
"typescript": "^3.9.7" | ||
"husky": "^4.3.0", | ||
"rxjs": "^6.6.3", | ||
"typescript": "^4.1.2" | ||
}, | ||
@@ -34,0 +35,0 @@ "peerDependencies": { |
@@ -22,1 +22,85 @@ # Epix | ||
``` | ||
## API | ||
```js | ||
import { Subject } from 'rxjs'; | ||
import { startEpics, ofType } from 'epix'; | ||
const action$ = new Subject(); | ||
function logMessageEpic(action$) { | ||
return action$.pipe( | ||
ofType('logMessage'), | ||
tap(({ message }) => console.log(message)), | ||
map(() => ({ type: 'logMessageDone' })), | ||
); | ||
} | ||
function doNothingEpic() { | ||
return empty(); | ||
} | ||
const epics = [ | ||
logMessageEpic, | ||
doNothingEpic, | ||
]; | ||
startEpics(epics, action$); | ||
action$.next({ | ||
type: 'logMessage', | ||
message: 'Hello world', | ||
}); | ||
``` | ||
If you have no idea what's going on here, I recommend getting accustomed with [redux-observable](https://redux-observable.js.org/) first. | ||
### startEpics(epics, action$, [options]) | ||
This is `epix`'s replacement of `createEpicMiddleware` and `combineEpics` in a single function. | ||
#### Arguments | ||
1. `epics: Array<Epic>`: your epics. The order matters, epics higher up in the array run before other | ||
2. `action$: Subject`: the action stream, that actions will go trough. | ||
3. `[options: Object]`: pass what you want here. It will be made available to all epics as their second argument. | ||
## TypeScript | ||
Define your epics with `Epic` as a type. | ||
```ts | ||
import { tap, ignoreElements } from 'rxjs/operators'; | ||
import { ofType, Epic } from 'epix'; | ||
const logMessageEpic: Epic = (action$) => { | ||
return action$.pipe( | ||
ofType('sayHi'), | ||
tap(() => console.log('Hi!')), | ||
ignoreElements(), | ||
); | ||
} | ||
``` | ||
Define an action type. | ||
```ts | ||
type Actions = { | ||
type: 'sayHi'; | ||
entityId: string; | ||
ev: InteractionEvent; | ||
} | { | ||
type: 'sayMyName'; | ||
name: string; | ||
}; | ||
``` | ||
Use it. | ||
```ts | ||
const action$ = new Subject<Actions>(); | ||
startEpics<Actions, { logger: (message: string) => {} }>(epics, action$, { logger: console.log }); | ||
``` |
Sorry, the diff of this file is not supported yet
23631
46
106
7