feat(UseCase): add warning message "UseCase is already released" #116

Merged
merged 3 commits into from Mar 23, 2017

Conversation

Projects
None yet
1 participant
@azu
Member

azu commented Mar 8, 2017

Following case is violation of UseCase lifecycle.
Almin don't support this pattern.

P: Parent UseCase
C: Child UseCase

                P fin.   C fin.
|---------------|          |
P    |                     |
     C---------------------|

Example:

class ChildUseCase extends UseCase {}
class ParentUseCase extends UseCase {
    execute() {
        setTimeout(() => {
            // isolate execution
            this.context.useCase(new ChildUseCase()).execute().then(() => {
                // ChildUseCase's dispatch is not work!
            });
        }, 100);
        return Promise.resolve();
    }
}

However, Almin should display warning message.
We want to add warning message to this case.

Edit:

See https://almin.js.org/docs/warnings/usecase-is-already-released.html for more details.

Implementation

P: Parent UseCase
C: Child UseCase
Add: Add instance to UseCaseInstanceMap
Delete: Remove instance from UseCaseInstanceMap

Add P         Delete P   Delete P
|---------------|          |
P    |                     |
     C---------------------|
  Add C
  
  

@azu azu changed the title from test(UseCase): add isolated nesting usecase to feat(UseCase): add warning message to UseCase that is already released Mar 9, 2017

@azu azu changed the title from feat(UseCase): add warning message to UseCase that is already released to feat(UseCase): add warning message to "UseCase is already released" Mar 9, 2017

const storeGroup = new QueuedStoreGroup([store]);
const asyncUseCase = createAsyncChangeStoreUseCase(store);
class ChangeTheStoreUseCase extends UseCase {
execute() {
store.emitChange();
- this.context.useCase(asyncUseCase).execute(); // 2
+ return this.context.useCase(asyncUseCase).execute(); // 2

This comment has been minimized.

@azu

azu Mar 9, 2017

Member

This line was shown warning message by This PR.

@azu

azu Mar 9, 2017

Member

This line was shown warning message by This PR.

@azu azu added the enhancement label Mar 12, 2017

src/UseCaseExecutor.ts
+ * When child is completed after parent did completed, display warning warning message
+ * @private
+ */
+ private _addWarningNoMoreDispatch() {

This comment has been minimized.

@azu

azu Mar 21, 2017

Member

💡 We have already known that this._parentUseCase is parent.
If this._parentUseCase is released, then call this._willExecute in the Child UseCase and throw Warning message.
Is it precision?

Currently approach have a potensial of memory leak.
Because, listen the dead useCase.

@azu

azu Mar 21, 2017

Member

💡 We have already known that this._parentUseCase is parent.
If this._parentUseCase is released, then call this._willExecute in the Child UseCase and throw Warning message.
Is it precision?

Currently approach have a potensial of memory leak.
Because, listen the dead useCase.

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu Mar 22, 2017

Member

Proposal

P: Parent UseCase
C: Child UseCase
Add: Add instance to UseCaseInstanceMap
Delete: Remove instance from UseCaseInstanceMap

Add P         Delete P   Delete P
|---------------|          |
P    |                     |
     C---------------------|
  Add C
  
  
Member

azu commented Mar 22, 2017

Proposal

P: Parent UseCase
C: Child UseCase
Add: Add instance to UseCaseInstanceMap
Delete: Remove instance from UseCaseInstanceMap

Add P         Delete P   Delete P
|---------------|          |
P    |                     |
     C---------------------|
  Add C
  
  
test/UseCase-test.js
+ afterEach(() => {
+ consoleWarnStub.restore();
+ });
+ it("should delegate dispatch to parent -> dispatcher", function(done) {

This comment has been minimized.

@azu

azu Mar 23, 2017

Member

wrong message

@azu

azu Mar 23, 2017

Member

wrong message

@azu azu changed the title from feat(UseCase): add warning message to "UseCase is already released" to feat(UseCase): add warning message "UseCase is already released" Mar 23, 2017

@azu azu referenced this pull request Mar 23, 2017

Closed

TypeScript: Map-Like typing #127

@azu azu merged commit 0d7385d into master Mar 23, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@azu azu deleted the test-isolate-child-usecase-will-not-resolve branch Mar 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment