Skip to content

Commit

Permalink
add disable firebase option
Browse files Browse the repository at this point in the history
  • Loading branch information
chxj1992 committed Jan 19, 2018
1 parent bbee75c commit f8a3238
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dist/kline.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kline.js.map

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions src/js/firebase.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as firebase from 'firebase';

firebase.initializeApp({
databaseURL: "https://kline-1f82d.firebaseio.com"
});

function date() {
let d = new Date(),
Expand All @@ -16,18 +13,24 @@ function date() {
return [year, month, day].join('');
}

firebase.database().ref('/domains/' + btoa(document.domain)).transaction(function (data) {
let d = date();
if (data === null) {
data = {
domain: document.domain,
data: {}
};
}
if (data['data'][d] === undefined) {
data['data'][d] = 1;
} else {
data['data'][d]++;
}
return data;
});
export default function fire() {
firebase.initializeApp({
databaseURL: "https://kline-1f82d.firebaseio.com"
});

firebase.database().ref('/domains/' + btoa(document.domain)).transaction(function (data) {
let d = date();
if (data === null) {
data = {
domain: document.domain,
data: {}
};
}
if (data['data'][d] === undefined) {
data['data'][d] = 1;
} else {
data['data'][d]++;
}
return data;
});
}
7 changes: 6 additions & 1 deletion src/js/kline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ChartSettings} from './chart_settings'
import {Template} from './templates'
import '../css/main.css'
import tpl from '../view/tpl.html'
import './firebase'
import fire from './firebase'
import $ from 'jquery'


Expand Down Expand Up @@ -47,6 +47,7 @@ export default class Kline {
this.isSized = false;
this.paused = false;
this.subscribed = null;
this.disableFirebase = false;

this.periodMap = {
"01w": 7 * 86400 * 1000,
Expand Down Expand Up @@ -114,6 +115,10 @@ export default class Kline {
Control.socketConnect();
}

if (!this.disableFirebase) {
fire();
}

this.registerMouseEvent();
ChartManager.instance.bindCanvas("main", document.getElementById("chart_mainCanvas"));
ChartManager.instance.bindCanvas("overlay", document.getElementById("chart_overlayCanvas"));
Expand Down

0 comments on commit f8a3238

Please sign in to comment.