Ensure AsyncStoreWithClient can start mid-lifecycle
In some cases we're likely to miss the PREPARED sync, so just handle ourselves as ready if we have a client set.pull/21833/head
parent
14757cacd5
commit
75f53e4118
|
@ -17,12 +17,25 @@ limitations under the License.
|
|||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { AsyncStore } from "./AsyncStore";
|
||||
import { ActionPayload } from "../dispatcher/payloads";
|
||||
import { Dispatcher } from "flux";
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
|
||||
export abstract class AsyncStoreWithClient<T extends Object> extends AsyncStore<T> {
|
||||
protected matrixClient: MatrixClient;
|
||||
|
||||
protected abstract async onAction(payload: ActionPayload);
|
||||
|
||||
protected constructor(dispatcher: Dispatcher<ActionPayload>, initialState: T = <T>{}) {
|
||||
super(dispatcher, initialState);
|
||||
|
||||
if (MatrixClientPeg.get()) {
|
||||
this.matrixClient = MatrixClientPeg.get();
|
||||
|
||||
// noinspection JSIgnoredPromiseFromCall
|
||||
this.onReady();
|
||||
}
|
||||
}
|
||||
|
||||
protected async onReady() {
|
||||
// Default implementation is to do nothing.
|
||||
}
|
||||
|
@ -40,8 +53,13 @@ export abstract class AsyncStoreWithClient<T extends Object> extends AsyncStore<
|
|||
return;
|
||||
}
|
||||
|
||||
this.matrixClient = payload.matrixClient;
|
||||
await this.onReady();
|
||||
if (this.matrixClient !== payload.matrixClient) {
|
||||
if (this.matrixClient) {
|
||||
await this.onNotReady();
|
||||
}
|
||||
this.matrixClient = payload.matrixClient;
|
||||
await this.onReady();
|
||||
}
|
||||
} else if (payload.action === 'on_client_not_viable' || payload.action === 'on_logged_out') {
|
||||
if (this.matrixClient) {
|
||||
await this.onNotReady();
|
||||
|
|
Loading…
Reference in New Issue