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 { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import { AsyncStore } from "./AsyncStore";
|
import { AsyncStore } from "./AsyncStore";
|
||||||
import { ActionPayload } from "../dispatcher/payloads";
|
import { ActionPayload } from "../dispatcher/payloads";
|
||||||
|
import { Dispatcher } from "flux";
|
||||||
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||||
|
|
||||||
export abstract class AsyncStoreWithClient<T extends Object> extends AsyncStore<T> {
|
export abstract class AsyncStoreWithClient<T extends Object> extends AsyncStore<T> {
|
||||||
protected matrixClient: MatrixClient;
|
protected matrixClient: MatrixClient;
|
||||||
|
|
||||||
protected abstract async onAction(payload: ActionPayload);
|
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() {
|
protected async onReady() {
|
||||||
// Default implementation is to do nothing.
|
// Default implementation is to do nothing.
|
||||||
}
|
}
|
||||||
|
@ -40,8 +53,13 @@ export abstract class AsyncStoreWithClient<T extends Object> extends AsyncStore<
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.matrixClient !== payload.matrixClient) {
|
||||||
|
if (this.matrixClient) {
|
||||||
|
await this.onNotReady();
|
||||||
|
}
|
||||||
this.matrixClient = payload.matrixClient;
|
this.matrixClient = payload.matrixClient;
|
||||||
await this.onReady();
|
await this.onReady();
|
||||||
|
}
|
||||||
} else if (payload.action === 'on_client_not_viable' || payload.action === 'on_logged_out') {
|
} else if (payload.action === 'on_client_not_viable' || payload.action === 'on_logged_out') {
|
||||||
if (this.matrixClient) {
|
if (this.matrixClient) {
|
||||||
await this.onNotReady();
|
await this.onNotReady();
|
||||||
|
|
Loading…
Reference in New Issue