Sunday, November 4, 2018

Adding and removing an attribute from the entire group of array: ES6 Javascript

Adding and removing an attribute from the object array

I mostly like to elaborate things that I am writing about but sometimes answers need to be kept short and crisp, so I will get down to the answers right away.

1. Adding an attribute:

Entity:

export class Case {

  caseId: string;
  name: string;
  description: string;
}

Method to add attribute:

I need to add checked attributed to the array of Case:
const checkedCases = cases.map(obj => {
  return ({...obj, checked : false});
});

2. Removing the attribute

Entity:

export class CheckedCase {
  caseId: string;
  name: string;
  description: string;
  checked: boolean;
}

Method to remove attribute:

I need to add checked attributed to the array of Case:
const cases = checkedCases.map(obj => {
  delete obj.checked;
  return obj;
});

Unit testing D3 transitions

Hello everyone,

Today I am going to tell you about unit testing D3 transitions. Anyone working in Javascript technology would be very much aware with D3.js library. D3.js is a data driven javascript library for Dom manipulating, which comes with a large set of advanced features, enabling the quick calculation and rendering of very large data sets.


Recently I was working on creating charts using D3.js library and as the client demanded the chart needed to be fancied with some good animations.

First of all, creating transitions in D3 charts require a lot of skill for everything to fall in place and then writing unit tests for that is SOMETHING. (FYI, I am pretty new to D3.js library. Started working on them just a month back).

Chart code:

I am referencing to this d3 bar chart to write unit tests:

http://bl.ocks.org/enjalot/1429426


Unit tests:

function flushAllD3Transitions() {
    var now = performance.now;
    performance.now = function() { return Infinity; };
    d3.timerFlush();
    performance.now = now;
 }

Thank you for taking the time to read this. I hope this would have helped. 

P.S. If you want me to discuss any other topic, write to me in the comments below.