Skip to content

Commit

Permalink
chore(payload): Remove ***Payload.Type static property (#87)
Browse files Browse the repository at this point in the history
- Breaking Change
- Fix #86
- To detect the type of `***Payload`, you should use `is***Payload()`.
  • Loading branch information
tetsuharuohzeki authored and azu committed Feb 20, 2017
1 parent 057f179 commit fca4b2e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Dispatcher from "./Dispatcher";
import DispatcherPayloadMeta from "./DispatcherPayloadMeta";
import Payload from "./payload/Payload";
import ErrorPayload from "./payload/ErrorPayload";
import { isErrorPayload } from "./payload/ErrorPayload";
import { StoreLike } from './StoreLike';

const STATE_CHANGE_EVENT = "STATE_CHANGE_EVENT";
Expand Down Expand Up @@ -97,7 +97,7 @@ abstract class Store extends Dispatcher implements StoreLike {
onError(handler: (payload: Payload, meta: DispatcherPayloadMeta) => void): () => void {
console.warn("Store#onError is deprecated. Please use Store#onDispatch.");
return this.onDispatch((payload, meta) => {
if (payload.type === ErrorPayload.Type) {
if (isErrorPayload(payload)) {
handler(payload, meta);
}
});
Expand Down
9 changes: 4 additions & 5 deletions src/payload/CompletedPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"use strict";
import Payload from "./Payload";

/**
* XXX: This is exported for an unit testing.
* DO NOT USE THIS in your application.
*/
export const TYPE = "ALMIN__COMPLETED_EACH_USECASE__";

export default class CompletedPayload extends Payload {

static get Type(): typeof TYPE {
return TYPE;
}

/**
* the value is returned by the useCase
* Difference of DidExecutedPayload, the value always is resolved value.
Expand Down
9 changes: 4 additions & 5 deletions src/payload/DidExecutedPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"use strict";
import Payload from "./Payload";

/**
* XXX: This is exported for an unit testing.
* DO NOT USE THIS in your application.
*/
export const TYPE = "ALMIN__DID_EXECUTED_EACH_USECASE__";

export default class DidExecutedPayload extends Payload {

static get Type(): typeof TYPE {
return TYPE;
}

/**
* the value is returned by the useCase
* Maybe Promise or some value or undefined.
Expand Down
9 changes: 4 additions & 5 deletions src/payload/ErrorPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"use strict";
import Payload from "./Payload";

/**
* XXX: This is exported for an unit testing.
* DO NOT USE THIS in your application.
*/
export const TYPE = "ALMIN__ErrorPayload__";

/**
* This payload is executed
*/
export default class ErrorPayload extends Payload {

static get Type(): typeof TYPE {
return TYPE;
}

/**
* the `error` in the UseCase
*/
Expand Down
9 changes: 4 additions & 5 deletions src/payload/WillExecutedPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"use strict";
import Payload from "./Payload";

/**
* XXX: This is exported for an unit testing.
* DO NOT USE THIS in your application.
*/
export const TYPE = "ALMIN__WILL_EXECUTED_EACH_USECASE__";

export default class WillExecutedPayload extends Payload {

static get Type(): typeof TYPE {
return TYPE;
}

/**
* a array for argument of the useCase
*/
Expand Down
10 changes: 6 additions & 4 deletions test/UseCase-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import UseCase from "../lib/UseCase";
import Dispatcher from "../lib/Dispatcher";
import Store from "../lib/Store";
import Context from "../lib/Context";
import {WillExecutedPayload, DidExecutedPayload, CompletedPayload} from "../lib/index";
import { TYPE as CompletedPayloadType } from '../lib/payload/CompletedPayload';
import { TYPE as DidExecutedPayloadType } from '../lib/payload/DidExecutedPayload';
import { TYPE as WillExecutedPayloadType } from '../lib/payload/WillExecutedPayload';
import UseCaseContext from "../lib/UseCaseContext";

describe("UseCase", function() {
Expand Down Expand Up @@ -60,9 +62,9 @@ describe("UseCase", function() {
const bUseCase = new BUseCase();
const callStack = [];
const expectedCallStackOfAUseCase = [
WillExecutedPayload.Type,
DidExecutedPayload.Type,
CompletedPayload.Type
WillExecutedPayloadType,
DidExecutedPayloadType,
CompletedPayloadType
];
const expectedCallStack = [
`${aUseCase.name}:will`,
Expand Down

0 comments on commit fca4b2e

Please sign in to comment.