Merge branch 'master' into bwindels/calls
This commit is contained in:
commit
ae0973b916
5 changed files with 21 additions and 18 deletions
|
@ -31,7 +31,8 @@ import {
|
||||||
createNavigation,
|
createNavigation,
|
||||||
createRouter,
|
createRouter,
|
||||||
RoomViewModel,
|
RoomViewModel,
|
||||||
TimelineView
|
TimelineView,
|
||||||
|
viewClassForTile
|
||||||
} from "hydrogen-view-sdk";
|
} from "hydrogen-view-sdk";
|
||||||
import downloadSandboxPath from 'hydrogen-view-sdk/download-sandbox.html?url';
|
import downloadSandboxPath from 'hydrogen-view-sdk/download-sandbox.html?url';
|
||||||
import workerPath from 'hydrogen-view-sdk/main.js?url';
|
import workerPath from 'hydrogen-view-sdk/main.js?url';
|
||||||
|
@ -53,7 +54,7 @@ import "hydrogen-view-sdk/theme-element-light.css";
|
||||||
async function main() {
|
async function main() {
|
||||||
const app = document.querySelector<HTMLDivElement>('#app')!
|
const app = document.querySelector<HTMLDivElement>('#app')!
|
||||||
const config = {};
|
const config = {};
|
||||||
const platform = new Platform(app, assetPaths, config, { development: import.meta.env.DEV });
|
const platform = new Platform({container: app, assetPaths, config, options: { development: import.meta.env.DEV }});
|
||||||
const navigation = createNavigation();
|
const navigation = createNavigation();
|
||||||
platform.setNavigation(navigation);
|
platform.setNavigation(navigation);
|
||||||
const urlRouter = createRouter({
|
const urlRouter = createRouter({
|
||||||
|
@ -88,7 +89,7 @@ async function main() {
|
||||||
navigation,
|
navigation,
|
||||||
});
|
});
|
||||||
await vm.load();
|
await vm.load();
|
||||||
const view = new TimelineView(vm.timelineViewModel);
|
const view = new TimelineView(vm.timelineViewModel, viewClassForTile);
|
||||||
app.appendChild(view.mount());
|
app.appendChild(view.mount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "hydrogen-view-sdk",
|
"name": "hydrogen-view-sdk",
|
||||||
"description": "Embeddable matrix client library, including view components",
|
"description": "Embeddable matrix client library, including view components",
|
||||||
"version": "0.0.10",
|
"version": "0.0.12",
|
||||||
"main": "./hydrogen.es.js",
|
"main": "./hydrogen.es.js",
|
||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ export type Options = {
|
||||||
export class ViewModel<O extends Options = Options> extends EventEmitter<{change: never}> {
|
export class ViewModel<O extends Options = Options> extends EventEmitter<{change: never}> {
|
||||||
private disposables?: Disposables;
|
private disposables?: Disposables;
|
||||||
private _isDisposed = false;
|
private _isDisposed = false;
|
||||||
private _options: O;
|
private _options: Readonly<O>;
|
||||||
|
|
||||||
constructor(options: O) {
|
constructor(options: Readonly<O>) {
|
||||||
super();
|
super();
|
||||||
this._options = options;
|
this._options = options;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
|
||||||
return Object.assign({}, this._options, explicitOptions);
|
return Object.assign({}, this._options, explicitOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
get options(): O { return this._options; }
|
get options(): Readonly<O> { return this._options; }
|
||||||
|
|
||||||
// makes it easier to pass through dependencies of a sub-view model
|
// makes it easier to pass through dependencies of a sub-view model
|
||||||
getOption<N extends keyof O>(name: N): O[N] {
|
getOption<N extends keyof O>(name: N): O[N] {
|
||||||
|
@ -115,10 +115,6 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOptions(options: O): void {
|
|
||||||
this._options = Object.assign(this._options, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
emitChange(changedProps: any): void {
|
emitChange(changedProps: any): void {
|
||||||
if (this._options.emitChange) {
|
if (this._options.emitChange) {
|
||||||
this._options.emitChange(changedProps);
|
this._options.emitChange(changedProps);
|
||||||
|
|
|
@ -22,6 +22,7 @@ export class SimpleTile extends ViewModel {
|
||||||
constructor(entry, options) {
|
constructor(entry, options) {
|
||||||
super(options);
|
super(options);
|
||||||
this._entry = entry;
|
this._entry = entry;
|
||||||
|
this._emitUpdate = undefined;
|
||||||
}
|
}
|
||||||
// view model props for all subclasses
|
// view model props for all subclasses
|
||||||
// hmmm, could also do instanceof ... ?
|
// hmmm, could also do instanceof ... ?
|
||||||
|
@ -67,16 +68,20 @@ export class SimpleTile extends ViewModel {
|
||||||
|
|
||||||
// TilesCollection contract below
|
// TilesCollection contract below
|
||||||
setUpdateEmit(emitUpdate) {
|
setUpdateEmit(emitUpdate) {
|
||||||
this.updateOptions({emitChange: paramName => {
|
this._emitUpdate = emitUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** overrides the emitChange in ViewModel to also emit the update over the tiles collection */
|
||||||
|
emitChange(changedProps) {
|
||||||
|
if (this._emitUpdate) {
|
||||||
// it can happen that after some network call
|
// it can happen that after some network call
|
||||||
// we switched away from the room and the response
|
// we switched away from the room and the response
|
||||||
// comes in, triggering an emitChange in a tile that
|
// comes in, triggering an emitChange in a tile that
|
||||||
// has been disposed already (and hence the change
|
// has been disposed already (and hence the change
|
||||||
// callback has been cleared by dispose) We should just ignore this.
|
// callback has been cleared by dispose) We should just ignore this.
|
||||||
if (emitUpdate) {
|
this._emitUpdate(this, changedProps);
|
||||||
emitUpdate(this, paramName);
|
|
||||||
}
|
}
|
||||||
}});
|
super.emitChange(changedProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
get upperEntry() {
|
get upperEntry() {
|
||||||
|
|
|
@ -132,14 +132,15 @@ export class Client {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async startRegistration(homeserver, username, password, initialDeviceDisplayName) {
|
async startRegistration(homeserver, username, password, initialDeviceDisplayName, flowSelector) {
|
||||||
const request = this._platform.request;
|
const request = this._platform.request;
|
||||||
const hsApi = new HomeServerApi({homeserver, request});
|
const hsApi = new HomeServerApi({homeserver, request});
|
||||||
const registration = new Registration(hsApi, {
|
const registration = new Registration(hsApi, {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
initialDeviceDisplayName,
|
initialDeviceDisplayName,
|
||||||
});
|
},
|
||||||
|
flowSelector);
|
||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue