Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made markers_array and barriers_array change only on value change #5

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Barriers', () => {
expect(Barriers.barriersToString(true, +11, +15)).to.deep.eql(['+11','+15']);
});
});

describe('barriersObjectToArray', () => {
const main = {
color: "green",
Expand All @@ -36,7 +36,7 @@ describe('Barriers', () => {
const barriers = {
main,
};
expect(Barriers.barriersObjectToArray(barriers)).to.deep.eql([{
expect(Barriers.barriersObjectToArray(barriers, [])).to.deep.eql([{
color: "green",
draggable: false
}]);
Expand All @@ -46,7 +46,7 @@ describe('Barriers', () => {
main,
somethingEmpty: {},
};
expect(Barriers.barriersObjectToArray(barriers)).to.deep.eql([{
expect(Barriers.barriersObjectToArray(barriers, [])).to.deep.eql([{
color: "green",
draggable: false
}]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ export const barriersToString = (is_relative, ...barriers_list) => barriers_list
.filter(barrier => barrier !== undefined && barrier !== null)
.map(barrier => `${is_relative && !/^[+-]/.test(barrier) ? '+' : ''}${barrier}`);

export const barriersObjectToArray = (barriers) => (
Object.keys(barriers || {})
.map(key => toJS(barriers[key]))
.filter(item => !isEmptyObject(item))
);
export const barriersObjectToArray = (barriers, reference_array) => {
Object.keys(barriers).forEach(barrier => {
const js_object = toJS(barriers[barrier]);
if (!isEmptyObject(js_object)) {
reference_array.push(js_object);
}
});

return reference_array;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class SmartChartStore extends BaseStore {
@observable granularity;
@observable barriers = observable.object({});
@observable markers = observable.object({});
barriers_empty_array = [];
markers_empty_array = [];

@observable is_contract_mode = false;
@observable is_title_enabled = true;
Expand Down Expand Up @@ -83,7 +85,7 @@ export default class SmartChartStore extends BaseStore {
if (this.trade_chart_layout && !isEmptyObject(this.trade_chart_layout)) {
this.applySavedTradeChartLayout();
}
}
};

@action.bound
onUnmount = () => {
Expand Down Expand Up @@ -185,7 +187,30 @@ export default class SmartChartStore extends BaseStore {

@computed
get barriers_array() {
return barriersObjectToArray(this.barriers);
let has_differing = false;
const barriers_array = barriersObjectToArray(this.barriers, []);

if (this.barriers_empty_array.length !== barriers_array.length) {
has_differing = true;
} else {
this.barriers_empty_array.forEach(barrier => {
barriers_array.forEach(next_barrier => {
Object.keys(barrier).forEach(key => {
if (barrier[key] !== next_barrier[key]) {
has_differing = true;
}
});
});
});
}

if (has_differing) {
this.barriers_empty_array = [];
} else {
this.barriers_empty_array.length = 0;
}

return barriersObjectToArray(this.barriers, this.barriers_empty_array);
}

// ---------- Markers ----------
Expand All @@ -203,7 +228,30 @@ export default class SmartChartStore extends BaseStore {

@computed
get markers_array() {
return barriersObjectToArray(this.markers);
let has_differing = false;
const markers_array = barriersObjectToArray(this.markers, []);

if (this.markers_empty_array.length !== markers_array.length) {
has_differing = true;
} else {
this.markers_empty_array.forEach(marker => {
markers_array.forEach(next_marker => {
Object.keys(marker).forEach(key => {
if (marker[key] !== next_marker[key]) {
has_differing = true;
}
});
});
});
}

if (has_differing) {
this.markers_empty_array = [];
} else {
this.markers_empty_array.length = 0;
}

return barriersObjectToArray(this.markers, this.markers_empty_array);
}

// ---------- Chart Settings ----------
Expand Down