-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
46 lines (37 loc) · 1.03 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {Authentication} from './auth'
import {Data} from './collection'
import Utils from './utils'
import {EventEmitter2} from 'eventemitter2'
export interface AppOptions {
host?: string
realtimeHost?: string
}
interface AppCache {
[index: string]: Data;
}
export class App {
host: string;
appHost: string;
realtimeHost: string;
token: string = '';
_uniqueId: string = Utils.random();
auth: Authentication;
private _dataCache: AppCache = {};
constructor(
public appId: string,
private opts?: AppOptions
) {
super();
opts = opts || {};
this.host = opts.host || 'http://104.155.50.163/v1/';
this.appHost = this.host + 'app/' + this.appId + '/';
this.realtimeHost = opts.realtimeHost || 'ws://104.155.40.140/';
this.auth = new Authentication(this);
}
use(type: string): Data {
if (!this._dataCache[type]) {
this._dataCache[type] = new Data(this, type);
}
return this._dataCache[type];
}
}