Bare-bones RS client
This commit is contained in:
16
app/controllers/application.ts
Normal file
16
app/controllers/application.ts
Normal 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
13
app/routes/application.ts
Normal 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
55
app/services/storage.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -1 +1,8 @@
|
||||
<h1>Dashtab</h1>
|
||||
|
||||
<p>
|
||||
RS connecting: {{this.storage.connecting}}<br>
|
||||
RS connected: {{this.storage.connected}}
|
||||
</p>
|
||||
|
||||
{{outlet}}
|
||||
Reference in New Issue
Block a user