-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneutrino.ts
65 lines (52 loc) · 1.5 KB
/
neutrino.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
import {Authentication} from './auth'
import {Data} from './collection'
import {ObjectEvents} from './object'
import {ArrayEvents} from './realtimeArray'
import Utils from './utils'
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
) {
opts = opts || {};
//http://104.155.50.163/v1/ | http://localhost:5000/v1
//ws://104.155.40.140/ | ws://localhost:6000/
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);
}
collection(type: string): Data {
if (!this._dataCache[type]) {
this._dataCache[type] = new Data(this, type);
}
return this._dataCache[type];
}
static app(appId, opts): App {
return new App(appId, opts);
}
}
App['ObjectEvents'] = ObjectEvents;
App['ArrayEvents'] = ArrayEvents;
if (typeof window !== 'undefined') {
window['Neutrino'] = App;
} else if (typeof module !== 'undefined') {
module['Neutrino'] = App;
} else {
this['Neutrino'] = App;
}