Bare-bones RS client

This commit is contained in:
2020-09-08 16:50:01 +02:00
parent 00156c8d70
commit a48d74608f
9 changed files with 178 additions and 4 deletions

View File

@@ -0,0 +1,16 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import Storage from 'dashtab/services/storage';
export default class Application extends Controller.extend({
// anything which *must* be merged to prototype here
}) {
@service storage!: Storage;
}
// DO NOT DELETE: this is how TypeScript knows how to look up your controllers.
declare module '@ember/controller' {
interface Registry {
'application': Application;
}
}

13
app/routes/application.ts Normal file
View File

@@ -0,0 +1,13 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import Storage from 'dashtab/services/storage';
export default class Application extends Route.extend({
// anything which *must* be merged to prototype here
}) {
@service storage!: Storage;
beforeModel() {
this.storage.initialize();
}
}

55
app/services/storage.ts Normal file
View File

@@ -0,0 +1,55 @@
import Service from '@ember/service';
import RemoteStorage from 'remotestoragejs';
import { tracked } from '@glimmer/tracking';
export default class Storage extends Service.extend({
// anything which *must* be merged to prototype here
}) {
remoteStorage: RemoteStorage;
@tracked connecting = true;
@tracked connected = false;
initialize() {
this.remoteStorage = new RemoteStorage();
(<any>window).remoteStorage = this.remoteStorage;
console.log('rs:', this.remoteStorage);
this.remoteStorage.access.claim('myfavoritedrinks', 'rw');
this.remoteStorage.caching.enable('/myfavoritedrinks/');
this.setupEventHandlers();
}
setupEventHandlers () {
this.remoteStorage.on('ready', () => {
console.log('rs ready');
});
this.remoteStorage.on('connected', () => {
this.connecting = false;
this.connected = true;
console.log('rs connected');
});
this.remoteStorage.on('not-connected', () => {
this.connecting = false;
this.connected = false;
console.log('rs not connected');
});
this.remoteStorage.on('disconnected', () => {
this.connected = false;
console.log('rs disconnected');
});
this.remoteStorage.on('connecting', () => {
this.connecting = true;
console.log('rs connecting');
});
this.remoteStorage.on('sync-done', () => {
console.log('rs sync done');
});
}
}
// DO NOT DELETE: this is how TypeScript knows how to look up your services.
declare module '@ember/service' {
interface Registry {
'storage': Storage;
}
}

View File

@@ -1 +1,8 @@
<h1>Dashtab</h1>
<p>
RS connecting: {{this.storage.connecting}}<br>
RS connected: {{this.storage.connected}}
</p>
{{outlet}}