diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-03-04 01:56:42 -0800 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-03-04 01:56:42 -0800 |
commit | 8acc65db04d8252eb33e411f51cb341a8428aa11 (patch) | |
tree | 2435ffc934c4529eb4d6670e2b2d447f194cc4d2 | |
parent | dd867317e7916dd7c8fc54b724187874b37230e3 (diff) |
Make `naive-client` injectable
-rw-r--r-- | sample-apps/angular-chat/src/app/app.module.ts | 3 | ||||
-rw-r--r-- | sample-apps/angular-chat/src/app/naive.service.spec.ts | 12 | ||||
-rw-r--r-- | sample-apps/angular-chat/src/app/naive.service.ts | 29 |
3 files changed, 43 insertions, 1 deletions
diff --git a/sample-apps/angular-chat/src/app/app.module.ts b/sample-apps/angular-chat/src/app/app.module.ts index 8072942..dd99bf2 100644 --- a/sample-apps/angular-chat/src/app/app.module.ts +++ b/sample-apps/angular-chat/src/app/app.module.ts @@ -4,11 +4,12 @@ import { FormsModule } from '@angular/forms' import { AppComponent } from './app.component' import { MessagingService } from './messaging.service' +import { NaiveService } from './naive.service' @NgModule({ declarations: [AppComponent], imports: [BrowserModule, FormsModule], - providers: [MessagingService], + providers: [MessagingService, NaiveService], bootstrap: [AppComponent] }) export class AppModule {} diff --git a/sample-apps/angular-chat/src/app/naive.service.spec.ts b/sample-apps/angular-chat/src/app/naive.service.spec.ts new file mode 100644 index 0000000..ad1c194 --- /dev/null +++ b/sample-apps/angular-chat/src/app/naive.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { NaiveService } from './naive.service'; + +describe('NaiveService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: NaiveService = TestBed.get(NaiveService); + expect(service).toBeTruthy(); + }); +}); diff --git a/sample-apps/angular-chat/src/app/naive.service.ts b/sample-apps/angular-chat/src/app/naive.service.ts new file mode 100644 index 0000000..7d491d7 --- /dev/null +++ b/sample-apps/angular-chat/src/app/naive.service.ts @@ -0,0 +1,29 @@ +import { Injectable } from '@angular/core' +import { Observable } from 'rxjs' + +import { dbFactory, DatabaseConnection } from 'naive-client' + +import { NaiveServiceInterface } from './naive.model' + +const wsUrl = 'ws://localhost:5001' +const httpUrl = 'http://localhost:5000' + +@Injectable({ + providedIn: 'root' +}) +export class NaiveService { + private db: DatabaseConnection = dbFactory({ wsUrl, httpUrl }) + init = this.db.init + write = this.db.write + read = this.db.read + remove = this.db.remove + subscribe = this.db.subscribe + + toObservable(path: string): Observable<any> { + return Observable.create(observer => { + this.subscribe(path, data => { + observer.next(data) + }) + }) + } +} |