only pass platform into Client
simplifying the API for SDK
This commit is contained in:
parent
9238961992
commit
ba27d20b24
4 changed files with 8 additions and 15 deletions
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {Client} from "../matrix/Client.js";
|
||||
import {SessionViewModel} from "./session/SessionViewModel.js";
|
||||
import {SessionLoadViewModel} from "./SessionLoadViewModel.js";
|
||||
import {LoginViewModel} from "./login/LoginViewModel.js";
|
||||
|
@ -23,7 +24,6 @@ import {ViewModel} from "./ViewModel.js";
|
|||
export class RootViewModel extends ViewModel {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._createClient = options.createClient;
|
||||
this._error = null;
|
||||
this._sessionPickerViewModel = null;
|
||||
this._sessionLoadViewModel = null;
|
||||
|
@ -106,7 +106,6 @@ export class RootViewModel extends ViewModel {
|
|||
this._setSection(() => {
|
||||
this._loginViewModel = new LoginViewModel(this.childOptions({
|
||||
defaultHomeserver: this.platform.config["defaultHomeServer"],
|
||||
createClient: this._createClient,
|
||||
ready: client => {
|
||||
// we don't want to load the session container again,
|
||||
// but we also want the change of screen to go through the navigation
|
||||
|
@ -132,7 +131,7 @@ export class RootViewModel extends ViewModel {
|
|||
}
|
||||
|
||||
_showSessionLoader(sessionId) {
|
||||
const client = this._createClient();
|
||||
const client = new Client(this.platform);
|
||||
client.startWithExistingSession(sessionId);
|
||||
this._setSection(() => {
|
||||
this._sessionLoadViewModel = new SessionLoadViewModel(this.childOptions({
|
||||
|
|
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {Client} from "../../matrix/Client.js";
|
||||
import {ViewModel} from "../ViewModel.js";
|
||||
import {PasswordLoginViewModel} from "./PasswordLoginViewModel.js";
|
||||
import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js";
|
||||
|
@ -24,11 +25,10 @@ import {SessionLoadViewModel} from "../SessionLoadViewModel.js";
|
|||
export class LoginViewModel extends ViewModel {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
const {ready, defaultHomeserver, createClient, loginToken} = options;
|
||||
this._createClient = createClient;
|
||||
const {ready, defaultHomeserver, loginToken} = options;
|
||||
this._ready = ready;
|
||||
this._loginToken = loginToken;
|
||||
this._client = this._createClient();
|
||||
this._client = new Client(this.platform);
|
||||
this._loginOptions = null;
|
||||
this._passwordLoginViewModel = null;
|
||||
this._startSSOLoginViewModel = null;
|
||||
|
|
|
@ -52,7 +52,7 @@ export const LoginFailure = createEnum(
|
|||
);
|
||||
|
||||
export class Client {
|
||||
constructor({platform, olmPromise, workerPromise}) {
|
||||
constructor(platform) {
|
||||
this._platform = platform;
|
||||
this._sessionStartedByReconnector = false;
|
||||
this._status = new ObservableValue(LoadStatus.NotLoading);
|
||||
|
@ -64,8 +64,8 @@ export class Client {
|
|||
this._sessionId = null;
|
||||
this._storage = null;
|
||||
this._requestScheduler = null;
|
||||
this._olmPromise = olmPromise;
|
||||
this._workerPromise = workerPromise;
|
||||
this._olmPromise = platform.loadOlm();
|
||||
this._workerPromise = platform.loadOlmWorker();
|
||||
this._accountSetup = undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,13 +37,7 @@ export async function main(platform) {
|
|||
platform.setNavigation(navigation);
|
||||
const urlRouter = createRouter({navigation, history: platform.history});
|
||||
urlRouter.attach();
|
||||
const olmPromise = platform.loadOlm();
|
||||
const workerPromise = platform.loadOlmWorker();
|
||||
|
||||
const vm = new RootViewModel({
|
||||
createClient: () => {
|
||||
return new Client({platform, olmPromise, workerPromise});
|
||||
},
|
||||
platform,
|
||||
// the only public interface of the router is to create urls,
|
||||
// so we call it that in the view models
|
||||
|
|
Reference in a new issue