Skip to content

Commit 9e7a776

Browse files
committed
fix(almin): remove dispatcher from DispatchPayloadMeta
1 parent 0ee1551 commit 9e7a776

13 files changed

+10
-106
lines changed

packages/almin/src/Context.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ export class Context<T> {
174174
const transaction = details && details.meta && details.meta.transaction;
175175
const isUseCaseFinished = details && details.meta && details.meta.isUseCaseFinished;
176176
const meta = new DispatcherPayloadMetaImpl({
177-
dispatcher: this.dispatcher,
178177
// StoreChangedPayload is always trusted.
179178
// Because, StoreChangedPayload is created by almin, not user.
180179
// Related issue: https://github.com/almin/almin/issues/328

packages/almin/src/Dispatcher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export class Dispatcher extends EventEmitter {
130130
} else {
131131
// the `payload` object generated by user
132132
const dispatchOnlyMeta = new DispatcherPayloadMetaImpl({
133-
dispatcher: this,
134133
isTrusted: false
135134
});
136135
this.emit(ON_DISPATCH, payload, dispatchOnlyMeta);

packages/almin/src/DispatcherPayloadMeta.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ export interface Transaction {
1919
* Dispatch Payload Meta arguments.
2020
* @private
2121
*/
22-
export interface DispatcherPayloadMetaArgs {
22+
export type DispatcherPayloadMetaArgs = {
2323
useCase?: UseCaseLike;
24-
dispatcher?: Dispatcher;
2524
isUseCaseFinished?: boolean;
2625
parentUseCase?: UseCase | null;
2726
isTrusted: boolean;
2827
transaction?: Transaction;
29-
}
28+
};
3029

3130
/**
3231
* `DispatcherPayloadMeta` is a meta object for `payload`.
@@ -39,7 +38,6 @@ export interface DispatcherPayloadMetaArgs {
3938
* console.log(meta); // instance of DispatcherPayloadMeta
4039
* console.log(meta.useCase); // reference to UseCase
4140
* console.log(meta.parentUseCase); // reference to Parent UseCase
42-
* console.log(meta.dispatcher); // reference to Dispatcher
4341
* console.log(meta.timeStamp); // Timestamp
4442
* console.log(meta.isTrusted); // Is it system payload?
4543
* });
@@ -51,26 +49,6 @@ export interface DispatcherPayloadMeta {
5149
*/
5250
readonly useCase: UseCaseLike | null;
5351

54-
/**
55-
* A dispatcher of the payload
56-
* In other word, the payload is dispatched by `this.dispatcher`
57-
*
58-
* ## Dispatcher in a useCase
59-
*
60-
* In following example, this.dispatcher is same with this.useCase.
61-
*
62-
* ```js
63-
* class Example extends UseCase {
64-
* execute(){
65-
* this.dispatch({ type })
66-
* // ^^^^
67-
* // === this dispatcher === this.useCase
68-
* }
69-
* }
70-
* ```
71-
*/
72-
readonly dispatcher: UseCase | Dispatcher | null;
73-
7452
/**
7553
* A parent useCase of the `this.useCase`,
7654
* When useCase is nesting, parentUseCase is a UseCase.
@@ -112,7 +90,6 @@ export interface DispatcherPayloadMeta {
11290
*/
11391
export class DispatcherPayloadMetaImpl implements DispatcherPayloadMeta {
11492
readonly useCase: UseCaseLike | null;
115-
readonly dispatcher: UseCase | Dispatcher | null;
11693
readonly parentUseCase: UseCase | Dispatcher | null;
11794
readonly timeStamp: number;
11895
readonly isTrusted: boolean;
@@ -121,7 +98,6 @@ export class DispatcherPayloadMetaImpl implements DispatcherPayloadMeta {
12198

12299
constructor(args: DispatcherPayloadMetaArgs) {
123100
this.useCase = args.useCase || null;
124-
this.dispatcher = args.dispatcher === undefined ? null : args.dispatcher;
125101
this.parentUseCase = args.parentUseCase || null;
126102
this.timeStamp = Date.now();
127103
this.isTrusted = args.isTrusted;

packages/almin/src/FunctionalUseCase.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ export class FunctionalUseCase extends Dispatcher implements UseCaseLike {
7878
const useCaseMeta = new DispatcherPayloadMetaImpl({
7979
// this dispatch payload generated by this UseCase
8080
useCase: this,
81-
// dispatcher is the UseCase
82-
dispatcher: this,
8381
// parent is the same with UseCase. because this useCase dispatch the payload
8482
parentUseCase: null,
8583
// the user create this payload
@@ -117,7 +115,6 @@ export class FunctionalUseCase extends Dispatcher implements UseCaseLike {
117115
throwError(error?: Error | any): void {
118116
const meta = new DispatcherPayloadMetaImpl({
119117
useCase: this,
120-
dispatcher: this,
121118
isTrusted: true,
122119
isUseCaseFinished: false
123120
});

packages/almin/src/UILayer/StoreGroup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ export class StoreGroup<T> extends Dispatcher implements StoreGroupLike {
231231
// InitializedPayload for passing to Store if the state change is not related payload.
232232
const payload = new InitializedPayload();
233233
const meta = new DispatcherPayloadMetaImpl({
234-
dispatcher: this,
235234
isTrusted: true
236235
});
237236
// 1. write in read

packages/almin/src/UnitOfWork/UseCaseUnitOfWork.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export class UseCaseUnitOfWork {
8787
this.isTransactionWorking = true;
8888
const payload = new TransactionBeganPayload(this.name);
8989
const meta = new DispatcherPayloadMetaImpl({
90-
dispatcher: this.dispatcher,
9190
isTrusted: true,
9291
transaction: transaction
9392
});
@@ -163,7 +162,6 @@ Not to allow to do multiple commits in a transaction`);
163162
// payload, meta
164163
const payload = new TransactionEndedPayload(this.name);
165164
const meta = new DispatcherPayloadMetaImpl({
166-
dispatcher: this.dispatcher,
167165
isTrusted: true,
168166
transaction: transaction
169167
});

packages/almin/src/UseCase.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ export abstract class UseCase extends Dispatcher implements UseCaseLike {
144144
: new DispatcherPayloadMetaImpl({
145145
// this dispatch payload generated by this UseCase
146146
useCase: this,
147-
// dispatcher is the UseCase
148-
dispatcher: this,
149147
// parent is the same with UseCase. because this useCase dispatch the payload
150148
parentUseCase: null,
151149
// the user create this payload
@@ -176,7 +174,6 @@ export abstract class UseCase extends Dispatcher implements UseCaseLike {
176174
throwError(error?: Error | any): void {
177175
const meta = new DispatcherPayloadMetaImpl({
178176
useCase: this,
179-
dispatcher: this,
180177
isTrusted: true,
181178
isUseCaseFinished: false
182179
});

packages/almin/src/UseCaseExecutor.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ export class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher imple
166166
*/
167167
private _parentUseCase: UseCase | null;
168168

169-
/**
170-
* A dispatcher instance
171-
*/
172-
private _dispatcher: Dispatcher;
173-
174169
/**
175170
* callable release handlers that are called in release()
176171
*/
@@ -185,7 +180,7 @@ export class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher imple
185180
*
186181
* **internal** documentation
187182
*/
188-
constructor({ useCase, parent, dispatcher }: { useCase: T; parent: UseCase | null; dispatcher: Dispatcher }) {
183+
constructor({ useCase, parent }: { useCase: T; parent: UseCase | null }) {
189184
super();
190185
if (process.env.NODE_ENV !== "production") {
191186
// execute and finish =>
@@ -199,7 +194,6 @@ export class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher imple
199194

200195
this.useCase = useCase;
201196
this._parentUseCase = parent;
202-
this._dispatcher = dispatcher;
203197
this._releaseHandlers = [];
204198
/**
205199
* ## Delegating Payload
@@ -223,7 +217,6 @@ export class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher imple
223217
});
224218
const meta = new DispatcherPayloadMetaImpl({
225219
useCase: this.useCase,
226-
dispatcher: this._dispatcher,
227220
parentUseCase: this._parentUseCase,
228221
isTrusted: true,
229222
isUseCaseFinished: true
@@ -243,7 +236,6 @@ export class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher imple
243236
});
244237
const meta = new DispatcherPayloadMetaImpl({
245238
useCase: this.useCase,
246-
dispatcher: this._dispatcher,
247239
parentUseCase: this._parentUseCase,
248240
isTrusted: true,
249241
isUseCaseFinished: false
@@ -270,7 +262,6 @@ export class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher imple
270262
});
271263
const meta = new DispatcherPayloadMetaImpl({
272264
useCase: this.useCase,
273-
dispatcher: this._dispatcher,
274265
parentUseCase: this._parentUseCase,
275266
isTrusted: true,
276267
isUseCaseFinished
@@ -288,7 +279,6 @@ export class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher imple
288279
});
289280
const meta = new DispatcherPayloadMetaImpl({
290281
useCase: this.useCase,
291-
dispatcher: this._dispatcher,
292282
parentUseCase: this._parentUseCase,
293283
isTrusted: true,
294284
isUseCaseFinished: true

packages/almin/src/UseCaseExecutorFactory.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export function createUseCaseExecutor(useCase: any, dispatcher: Dispatcher): Use
1515
if (isUseCase(useCase)) {
1616
return new UseCaseExecutorImpl({
1717
useCase,
18-
parent: isUseCase(dispatcher) ? dispatcher : null,
19-
dispatcher
18+
parent: isUseCase(dispatcher) ? dispatcher : null
2019
});
2120
} else if (isUseCaseFunction(useCase)) {
2221
// When pass UseCase constructor itself, throw assertion error
@@ -29,8 +28,7 @@ The argument is UseCase constructor itself: ${useCase}`
2928
const functionalUseCase = new FunctionalUseCase(useCase);
3029
return new UseCaseExecutorImpl({
3130
useCase: functionalUseCase,
32-
parent: isUseCase(dispatcher) ? dispatcher : null,
33-
dispatcher
31+
parent: isUseCase(dispatcher) ? dispatcher : null
3432
});
3533
}
3634
throw new Error(`Context#useCase argument should be UseCase: ${useCase}`);

packages/almin/test/Context-test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe("Context", function() {
109109
const [payload, meta] = dispatchedPayload[0];
110110
assert.deepEqual(payload, DISPATCHED_EVENT);
111111
assert.strictEqual(meta.useCase, useCase);
112-
assert.strictEqual(meta.dispatcher, useCase);
112+
assert.strictEqual(meta.isTrusted, false);
113113
assert.strictEqual(meta.parentUseCase, null);
114114
assert.strictEqual(typeof meta.timeStamp, "number");
115115
});
@@ -183,7 +183,6 @@ describe("Context", function() {
183183
assert.ok(Array.isArray(payload.args));
184184
assert.ok(typeof meta.timeStamp === "number");
185185
assert.equal(meta.useCase, notExecuteUseCase);
186-
assert.equal(meta.dispatcher, dispatcher);
187186
assert.equal(meta.parentUseCase, null);
188187
assert.equal(meta.isUseCaseFinished, true);
189188
done();
@@ -225,7 +224,6 @@ describe("Context", function() {
225224
assert.ok(Array.isArray(payload.args));
226225
assert.ok(typeof meta.timeStamp === "number");
227226
assert.equal(meta.useCase, testUseCase);
228-
assert.equal(meta.dispatcher, dispatcher);
229227
assert.equal(meta.parentUseCase, null);
230228
done();
231229
});
@@ -280,7 +278,6 @@ describe("Context", function() {
280278
isCalled.will = true;
281279
assert.ok(payload instanceof WillExecutedPayload);
282280
assert.equal(meta.useCase, eventUseCase);
283-
assert.equal(meta.dispatcher, dispatcher);
284281
assert.equal(meta.parentUseCase, null);
285282
});
286283
// onDispatch should not called when UseCase will/did execute.
@@ -292,15 +289,15 @@ describe("Context", function() {
292289
appContext.events.onDidExecuteEachUseCase((payload, meta) => {
293290
isCalled.did = true;
294291
assert.ok(payload instanceof DidExecutedPayload);
292+
assert.equal(meta.isTrusted, true);
295293
assert.equal(meta.useCase, eventUseCase);
296-
assert.equal(meta.dispatcher, dispatcher);
297294
assert.equal(meta.parentUseCase, null);
298295
});
299296
appContext.events.onCompleteEachUseCase((payload, meta) => {
300297
isCalled.complete = true;
301298
assert.ok(payload instanceof CompletedPayload);
299+
assert.equal(meta.isTrusted, true);
302300
assert.equal(meta.useCase, eventUseCase);
303-
assert.equal(meta.dispatcher, dispatcher);
304301
assert.equal(meta.parentUseCase, null);
305302
});
306303
// when
@@ -366,7 +363,6 @@ describe("Context", function() {
366363
assert.ok(payload.error instanceof Error);
367364
assert.equal(typeof meta.timeStamp, "number");
368365
assert.equal(meta.useCase, throwUseCase);
369-
assert.equal(meta.dispatcher, throwUseCase);
370366
assert.equal(meta.parentUseCase, null);
371367
done();
372368
});

0 commit comments

Comments
 (0)