only pass platform into Client

simplifying the API for SDK
This commit is contained in:
Bruno Windels 2021-12-22 17:19:37 +01:00
parent 9238961992
commit ba27d20b24
4 changed files with 8 additions and 15 deletions

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {Client} from "../matrix/Client.js";
import {SessionViewModel} from "./session/SessionViewModel.js"; import {SessionViewModel} from "./session/SessionViewModel.js";
import {SessionLoadViewModel} from "./SessionLoadViewModel.js"; import {SessionLoadViewModel} from "./SessionLoadViewModel.js";
import {LoginViewModel} from "./login/LoginViewModel.js"; import {LoginViewModel} from "./login/LoginViewModel.js";
@ -23,7 +24,6 @@ import {ViewModel} from "./ViewModel.js";
export class RootViewModel extends ViewModel { export class RootViewModel extends ViewModel {
constructor(options) { constructor(options) {
super(options); super(options);
this._createClient = options.createClient;
this._error = null; this._error = null;
this._sessionPickerViewModel = null; this._sessionPickerViewModel = null;
this._sessionLoadViewModel = null; this._sessionLoadViewModel = null;
@ -106,7 +106,6 @@ export class RootViewModel extends ViewModel {
this._setSection(() => { this._setSection(() => {
this._loginViewModel = new LoginViewModel(this.childOptions({ this._loginViewModel = new LoginViewModel(this.childOptions({
defaultHomeserver: this.platform.config["defaultHomeServer"], defaultHomeserver: this.platform.config["defaultHomeServer"],
createClient: this._createClient,
ready: client => { ready: client => {
// we don't want to load the session container again, // we don't want to load the session container again,
// but we also want the change of screen to go through the navigation // but we also want the change of screen to go through the navigation
@ -132,7 +131,7 @@ export class RootViewModel extends ViewModel {
} }
_showSessionLoader(sessionId) { _showSessionLoader(sessionId) {
const client = this._createClient(); const client = new Client(this.platform);
client.startWithExistingSession(sessionId); client.startWithExistingSession(sessionId);
this._setSection(() => { this._setSection(() => {
this._sessionLoadViewModel = new SessionLoadViewModel(this.childOptions({ this._sessionLoadViewModel = new SessionLoadViewModel(this.childOptions({

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {Client} from "../../matrix/Client.js";
import {ViewModel} from "../ViewModel.js"; import {ViewModel} from "../ViewModel.js";
import {PasswordLoginViewModel} from "./PasswordLoginViewModel.js"; import {PasswordLoginViewModel} from "./PasswordLoginViewModel.js";
import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js"; import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js";
@ -24,11 +25,10 @@ import {SessionLoadViewModel} from "../SessionLoadViewModel.js";
export class LoginViewModel extends ViewModel { export class LoginViewModel extends ViewModel {
constructor(options) { constructor(options) {
super(options); super(options);
const {ready, defaultHomeserver, createClient, loginToken} = options; const {ready, defaultHomeserver, loginToken} = options;
this._createClient = createClient;
this._ready = ready; this._ready = ready;
this._loginToken = loginToken; this._loginToken = loginToken;
this._client = this._createClient(); this._client = new Client(this.platform);
this._loginOptions = null; this._loginOptions = null;
this._passwordLoginViewModel = null; this._passwordLoginViewModel = null;
this._startSSOLoginViewModel = null; this._startSSOLoginViewModel = null;

View File

@ -52,7 +52,7 @@ export const LoginFailure = createEnum(
); );
export class Client { export class Client {
constructor({platform, olmPromise, workerPromise}) { constructor(platform) {
this._platform = platform; this._platform = platform;
this._sessionStartedByReconnector = false; this._sessionStartedByReconnector = false;
this._status = new ObservableValue(LoadStatus.NotLoading); this._status = new ObservableValue(LoadStatus.NotLoading);
@ -64,8 +64,8 @@ export class Client {
this._sessionId = null; this._sessionId = null;
this._storage = null; this._storage = null;
this._requestScheduler = null; this._requestScheduler = null;
this._olmPromise = olmPromise; this._olmPromise = platform.loadOlm();
this._workerPromise = workerPromise; this._workerPromise = platform.loadOlmWorker();
this._accountSetup = undefined; this._accountSetup = undefined;
} }

View File

@ -37,13 +37,7 @@ export async function main(platform) {
platform.setNavigation(navigation); platform.setNavigation(navigation);
const urlRouter = createRouter({navigation, history: platform.history}); const urlRouter = createRouter({navigation, history: platform.history});
urlRouter.attach(); urlRouter.attach();
const olmPromise = platform.loadOlm();
const workerPromise = platform.loadOlmWorker();
const vm = new RootViewModel({ const vm = new RootViewModel({
createClient: () => {
return new Client({platform, olmPromise, workerPromise});
},
platform, platform,
// the only public interface of the router is to create urls, // the only public interface of the router is to create urls,
// so we call it that in the view models // so we call it that in the view models