Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
fix(quotes): fix quotes highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
albertosantini committed Jan 8, 2018
1 parent d327789 commit 6275f43
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/client/app/components/quotes/quotes.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ export class QuotesTemplate {
}

static highlighter(value, instrument, type) {
if (typeof value !== "string") {
return "";
}

const classes = "pv1 pr1 bb b--black-20 tr";
const quoteClasses = `${instrument}-${type} ${classes}`;
const greenClass = "highlight-green";
const redClass = "highlight-red";

if (!QuotesTemplate.cache[instrument]) {
QuotesTemplate.cache[instrument] = {};
}
Expand All @@ -55,11 +46,21 @@ export class QuotesTemplate {
const cache = QuotesTemplate.cache[instrument][type];
const oldValue = cache.value;

const classes = "pv1 pr1 bb b--black-20 tr";
const quoteClasses = `${instrument}-${type} ${classes}`;
const greenClass = "highlight-green";
const redClass = "highlight-red";

if (value === oldValue) {
return cache.classes || quoteClasses;
}

const highlight = value >= oldValue
? `${quoteClasses} ${greenClass}`
: `${quoteClasses} ${redClass}`;

cache.value = value;
cache.classes = highlight;

clearTimeout(cache.timeout);
cache.timeout = setTimeout(() => {
Expand All @@ -68,6 +69,7 @@ export class QuotesTemplate {
if (el) {
el.classList.remove(greenClass);
el.classList.remove(redClass);
cache.classes = quoteClasses;
}
}, 500);

Expand Down

0 comments on commit 6275f43

Please sign in to comment.