Skip to content

Commit 6aaaec9

Browse files
committed
fix(almin): fix trouble emit StoreChangedPayload
In some case, LifeCycleEventHub#onDispatch receive StoreChangedPayload #328 This fixes that `StoreChangedPayload` always be `isTrust: true` payload. `LifeCycleEventHub#onDispatch` ignore trusted Payload. As a result, LifeCycleEventHub#onDispatch have not received StoreChangedPayload. fix #328
1 parent c513531 commit 6aaaec9

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

packages/almin/src/Context.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,26 @@ export class Context<T> {
158158
if (this.config.strict) {
159159
this.storeGroup.useStrict();
160160
}
161+
// If some stores are changed, emit StoreChangedPayload
161162
// Store -> StoreGroup -> LifeCycleEventHub
162163
const storeGroupOnChangeToStoreChangedPayload = (
163164
stores: Array<StoreLike<any>>,
164165
details?: StoreGroupReasonForChange
165166
) => {
166167
stores.forEach(store => {
167168
const payload = new StoreChangedPayload(store);
168-
// FIXME: store#emitChange -> isTruest:false event
169169
// Should not included in StoreChanged Event
170-
const meta = details
171-
? details.meta
172-
: new DispatcherPayloadMetaImpl({
173-
useCase: undefined,
174-
dispatcher: this.dispatcher,
175-
parentUseCase: null,
176-
isTrusted: true,
177-
isUseCaseFinished: false,
178-
transaction: undefined
179-
});
170+
// inherit some context from the reason of change details
171+
const transaction = details && details.meta && details.meta.transaction;
172+
const isUseCaseFinished = details && details.meta && details.meta.isUseCaseFinished;
173+
const meta = new DispatcherPayloadMetaImpl({
174+
useCase: undefined,
175+
dispatcher: this.dispatcher,
176+
parentUseCase: null,
177+
isTrusted: true, // <= StoreChangedPayload is always trusted
178+
isUseCaseFinished: isUseCaseFinished,
179+
transaction: transaction
180+
});
180181
this.dispatcher.dispatch(payload, meta);
181182
});
182183
};

packages/almin/src/UILayer/StoreGroup.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,13 @@ But, ${store.name}#getState() was called.`
466466
/**
467467
* Observe changes of the store group.
468468
*
469-
* `details` is the reason of changing stores.
470-
* If `details` it not found, the reason by system.
471-
*
472-
* For example, the user can change store using `Store#emitChange` manually.
469+
* For example, the user can change store using `Store#setState` manually.
473470
* In this case, the `details` is defined and report.
474471
*
475-
* Contrast, almin try to update store in a lifecycle.
472+
* Contrast, almin try to update store in a lifecycle(didUseCase, completeUseCase etc...).
476473
* In this case, the `details` is not defined and report.
477474
*
478-
* TODO(azu): we should always define `details`
479-
*
480-
* onChange workflow: https://code2flow.com/mHFviS
475+
* StoreGroup#onChange workflow: https://code2flow.com/mHFviS
481476
*/
482477
onChange(handler: (stores: Array<Store<T>>, details?: StoreGroupReasonForChange) => void): () => void {
483478
this.on(CHANGE_STORE_GROUP, handler);

0 commit comments

Comments
 (0)