forked from unbug/codelf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppModel.js
More file actions
47 lines (40 loc) · 1.2 KB
/
AppModel.js
File metadata and controls
47 lines (40 loc) · 1.2 KB
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
import BaseModel from './BaseModel';
import LocalStorage from '../utils/LocalStorage';
import * as Tools from '../utils/Tools';
import {searchParams} from '../utils/Param';
import Navigator from '../utils/Navigator';
const APP_NANE = 'codelf';
const DEVICE_ID_KEY = `${APP_NANE}_device_id`;
class AppModel extends BaseModel {
constructor() {
super();
this._data = {
debug: searchParams()['debug'],
appName: APP_NANE,
deviceId: LocalStorage.getItem(DEVICE_ID_KEY),
isGithub: /github\.io/g.test(window.location.href)
};
if (!this._data.deviceId) {
this._data.deviceId = Tools.uuid();
LocalStorage.setItem(DEVICE_ID_KEY, this._data.deviceId)
}
}
analytics(param) {
(this.isGithub || this.debug) && setTimeout(function () {
Navigator.getFrame(null).setAttribute('src', '//www.mihtool.com/analytics.html?codelf' + (param ? ('&' + param) : ''));
}, param ? 500 : 1000);
}
genPersistenceKey(key) {
if (key !== undefined && key !== null) {
return `${this._data.appName}_${key}`;
}
return null;
}
get debug() {
return this._data.debug;
}
get isGithub() {
return this._data.isGithub;
}
}
export default new AppModel();