Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
Simplify dat variable
Browse files Browse the repository at this point in the history
  • Loading branch information
katowulf committed Dec 30, 2016
1 parent 84e57e6 commit 35ce76f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@

// when results are written to the database, read them and display
function showResults(snap) {
var dat = snap.val();
if( dat === null ) { return; } // wait until we get data
if( !snap.exists() ) { return; } // wait until we get data
var dat = snap.val().hits;

// when a value arrives from the database, stop listening
// and remove the temporary data from the database
Expand All @@ -109,19 +109,19 @@

// the rest of this just displays data in our demo and probably
// isn't very interesting
var totalText = dat.hits.total;
if( dat.hits.hits && dat.hits.hits.length !== dat.hits.total ) {
totalText = dat.hits.hits.length + ' of ' + dat.hits.total;
var totalText = dat.total;
if( dat.hits && dat.hits.length !== dat.total ) {
totalText = dat.hits.length + ' of ' + dat.total;
}
$('#total').text('(' + totalText + ')');

var $pair = $('#results')
.text(JSON.stringify(dat, null, 2))
.removeClass('error zero');
if( dat.hits.error ) {
if( dat.error ) {
$pair.addClass('error');
}
else if( dat.hits.total < 1 ) {
else if( dat.total < 1 ) {
$pair.addClass('zero');
}
}
Expand Down

0 comments on commit 35ce76f

Please sign in to comment.