Created
March 19, 2018 13:25
-
-
Save magnusbakken/2380b0384b725113f5e14a9eefb5a5d4 to your computer and use it in GitHub Desktop.
ts-action before/after
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git <redacted> | |
index 8c60296..57a1aa1 100644 | |
--- <redacted>.ts | |
+++ <redacted>.ts | |
@@ -1,45 +1,26 @@ | |
-// tslint:disable:max-classes-per-file | |
-import { Injectable } from "@angular/core"; | |
-import { Action } from "redux"; | |
- | |
-import { Article, ArticleScheme } from "<redacted>"; | |
-import { BaseApiFailureAction, DummyAction } from "app/common/store"; | |
- | |
-export class LoadArticleAction implements Action { | |
- public readonly type = ArticlesActionType.LOAD_ARTICLE; | |
- constructor(public id: number, public schemeId: number) { } | |
-} | |
- | |
-export class LoadArticleSucceededAction implements Action { | |
- public readonly type = ArticlesActionType.LOAD_ARTICLE_SUCCEEDED; | |
- constructor(public article: Article) { } | |
-} | |
- | |
-export class LoadArticleFailedAction extends BaseApiFailureAction { | |
- public readonly type = ArticlesActionType.LOAD_ARTICLE_FAILED; | |
-} | |
- | |
-export class ArticleSchemeLoadedAction implements Action { | |
- public readonly type = ArticlesActionType.ARTICLE_SCHEME_LOADED; | |
- constructor(public scheme: ArticleScheme) { } | |
-} | |
- | |
-export class UnloadArticlesAction implements Action { | |
- public readonly type = ArticlesActionType.UNLOAD_ARTICLES; | |
-} | |
- | |
-export enum ArticlesActionType { | |
- LOAD_ARTICLE = "[Article] Load Article", | |
- LOAD_ARTICLE_SUCCEEDED = "[Article] Load Article Succeeded", | |
- LOAD_ARTICLE_FAILED = "[Article] Load Article Failed", | |
- ARTICLE_SCHEME_LOADED = "[Article] Article Scheme Loaded", | |
- UNLOAD_ARTICLES = "[Article] Unload Articles", | |
-} | |
- | |
-export type ArticlesAction = | |
- LoadArticleAction | | |
- LoadArticleSucceededAction | | |
- LoadArticleFailedAction | | |
- ArticleSchemeLoadedAction | | |
- UnloadArticlesAction | | |
- DummyAction; | |
+import { action, props, union } from "ts-action"; | |
+ | |
+import { Article, ArticleScheme } from "<redacted>"; | |
+import { ApiFailure } from "app/common/store"; | |
+ | |
+export const LoadArticleAction = action( | |
+ "[Article] Load Article", | |
+ props<{ id: number, schemeId: number, lastModified: string }>()); | |
+export const LoadArticleSucceededAction = action( | |
+ "[Article] Load Article Succeeded", | |
+ props<{ article: Article }>()); | |
+export const LoadArticleFailedAction = action( | |
+ "[Article] Load Article Failed", | |
+ props<ApiFailure>()); | |
+export const ArticleSchemeLoadedAction = action( | |
+ "[Article] Article Scheme Loaded", | |
+ props<{ scheme: ArticleScheme }>()); | |
+export const UnloadArticlesAction = action("[Article] Unload Articles"); | |
+ | |
+export const ArticlesAction = union({ | |
+ LoadArticleAction, | |
+ LoadArticleSucceededAction, | |
+ LoadArticleFailedAction, | |
+ ArticleSchemeLoadedAction, | |
+ UnloadArticlesAction, | |
+}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment