/
UseCaseContext.ts
42 lines (37 loc) · 1.08 KB
/
UseCaseContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// LICENSE : MIT
"use strict";
import UseCase from "./UseCase";
import UseCaseExecutor from "./UseCaseExecutor";
const assert = require("assert");
/**
* UseCase internally use UseCaseContext insteadof Context.
* It has limitation as against to Context.
* Because, UseCaseContext is for UseCase.
* @public
*/
export default class UseCaseContext {
dispatcher: UseCase;;
/**
* @param [dispatcher] dispatcher is Dispatcher or parent UseCase.
* @public
*/
constructor(dispatcher: UseCase) {
this.dispatcher = dispatcher;
}
/**
* Create UseCaseExecutor for `useCase`.
* @param {UseCase} useCase
* @returns {UseCaseExecutor}
* @public
*/
useCase(useCase: UseCase): UseCaseExecutor {
if (process.env.NODE_ENV !== "production") {
assert(useCase !== this.dispatcher, `the useCase(${useCase}) should not equal this useCase(${this.dispatcher})`);
}
return new UseCaseExecutor({
useCase,
parent: this.dispatcher,
dispatcher: this.dispatcher
});
}
}