Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const deepEqualForSelectedProperties = (obj1, obj2, propertiesToCheck) => {
- for(const key of propertiesToCheck) {
- // O compariamo oggetti (content)
- if(key === 'content') {
- if(obj1['content']['blocks']) {
- for(let i = 0; i < obj1['content']['blocks'].length; i++) {
- console.log(obj1['content']['blocks']);
- console.log(obj2['content']['blocks']);
- if(!deepEqualForContent(obj1['content']['blocks'][i], obj2['content']['blocks'][i])) {
- console.log('Failing on ', obj1['content']['blocks'][i], 'vs', obj2['content']['blocks'][i]);
- return false;
- }
- }
- } else {
- return false;
- }
- }
- // O compariamo primitivi (!= content)
- console.log("Checking l1", key, obj1[key], 'vs', obj2[key])
- if(key !== 'content' && obj1[key] !== obj2[key]) {
- console.log('missmatch esterno', key, obj1[key], obj2[key]);
- return false;
- }
- }
- return true;
- };
- const deepEqualForContent = (obj1, obj2) => {
- const [keys1, keys2] = [Object.keys(obj1), Object.keys(obj2)];
- // Do not replace with !obj1.isLocked
- let checkThisLevel = true;
- if(obj1.isLocked === false && obj2.isLocked === false) {
- console.log('Skipping the below level', obj1, obj2)
- checkThisLevel = false;
- // return true;
- }
- for(const key of keys1) {
- if(isObject(obj1[key])) {
- if(!isObject(obj2[key])) {
- return false;
- }
- // Both of them are objects
- console.log('CONSIDERO OGGETTO: ', key, obj1[key])
- if(!deepEqualForContent(obj1[key], obj2[key])) {
- return false;
- }
- } else {
- // Primitives
- console.log((checkThisLevel ? 'checking' : 'skipping'), key);
- if(checkThisLevel) {
- console.log("Checking", key, obj1[key], 'vs', obj2[key])
- if(obj1[key] !== obj2[key]) {
- return false;
- }
- }
- }
- }
- return true;
- }
- const isObject = (item) => item && typeof item === 'object';
- const t = {
- isCreatedByHq: true,
- sitemapId: "Home",
- parentId: null,
- title: "Home",
- internalTitle: "Home",
- locale: "it",
- content: {
- blocks: [
- {
- type: "DWSCoverCarousel",
- isLocked: true,
- isPinned: true,
- scrollpointer: false,
- items: [
- {
- type: "DwsCover",
- isLocked: true,
- isPinned: false,
- owner: "hidden",
- palette: "dark",
- gradient: false,
- title: "Titolo Slide 1",
- preTitle: "Pre Titolo Slide 1",
- chapter: {
- name: "Chapter slide 1",
- nav: false,
- },
- scrollIndicator: false,
- link: {
- content: "",
- title: "",
- url: "",
- target: "_blank",
- },
- cta2: {
- content: "Testfff",
- url: "http://localhost:4200/back-office/cms/dws-pages/new",
- target: "_blank",
- },
- cta3: null,
- background: null,
- },
- {
- type: "DwsCover",
- isLocked: true,
- isPinned: false,
- owner: "hidden",
- palette: "",
- gradient: false,
- title: "Titolo Slide 2",
- preTitle: "Pre Titolo Slide 2",
- chapter: {
- name: "",
- nav: false,
- },
- scrollIndicator: false,
- link: {
- content: "",
- title: "",
- url: "",
- target: "_blank",
- },
- cta2: {
- content: "Content cta2",
- url: "",
- target: "_blank",
- },
- cta3: null,
- background: null,
- },
- ],
- },
- {
- type: "DWSCoverCarousel",
- isLocked: true,
- isPinned: true,
- scrollpointer: false,
- items: [
- {
- type: "DwsCover",
- isLocked: false,
- isPinned: false,
- owner: "hidden",
- palette: "dark",
- gradient: false,
- title: "Titolo Slide 2",
- preTitle: "Pre Titolo Slide 1",
- chapter: {
- name: "Chapter slide 1",
- nav: false,
- },
- scrollIndicator: false,
- link: {
- content: "",
- title: "",
- url: "",
- target: "_blank",
- },
- cta2: {
- content: "Testfff",
- url: "http://localhost:4200/back-office/cms/dws-pages/new",
- target: "_blank",
- },
- cta3: null,
- background: null,
- },
- {
- type: "DwsCover",
- isLocked: true,
- isPinned: false,
- owner: "hidden",
- palette: "",
- gradient: false,
- title: "Titolo Slide 2",
- preTitle: "Pre Titolo Slide 2",
- chapter: {
- name: "",
- nav: false,
- },
- scrollIndicator: false,
- link: {
- content: "",
- title: "",
- url: "",
- target: "_blank",
- },
- cta2: {
- content: "Content cta2",
- url: "",
- target: "_blank",
- },
- cta3: null,
- background: null,
- },
- ],
- },
- ],
- },
- slug: "home",
- status: "draft",
- id: "6010301d70155b5998348291",
- original: "600ffc5f70155b59983480ef",
- createdAt: "2021-01-26T15:07:09.244Z",
- updatedAt: null,
- revision: 0,
- active: false,
- };
- const t2 = {
- isCreatedByHq: true,
- sitemapId: "Home",
- parentId: null,
- title: "Home",
- internalTitle: "Home",
- locale: "it",
- content: {
- blocks: [
- {
- type: "DWSCoverCarousel",
- isLocked: true,
- isPinned: true,
- scrollpointer: false,
- items: [
- {
- type: "DwsCover",
- isLocked: true,
- isPinned: false,
- owner: "hidden",
- palette: "dark",
- gradient: false,
- title: "Titolo Slide 1",
- preTitle: "Pre Titolo Slide 1",
- chapter: {
- name: "Chapter slide 1",
- nav: false,
- },
- scrollIndicator: false,
- link: {
- content: "",
- title: "",
- url: "",
- target: "_blank",
- },
- cta2: {
- content: "Testfff",
- url: "http://localhost:4200/back-office/cms/dws-pages/new",
- target: "_blank",
- },
- cta3: null,
- background: null,
- },
- {
- type: "DwsCover",
- isLocked: true,
- isPinned: false,
- owner: "hidden",
- palette: "",
- gradient: false,
- title: "Titolo Slide 2",
- preTitle: "Pre Titolo Slide 2",
- chapter: {
- name: "",
- nav: false,
- },
- scrollIndicator: false,
- link: {
- content: "",
- title: "",
- url: "",
- target: "_blank",
- },
- cta2: {
- content: "Content cta2",
- url: "",
- target: "_blank",
- },
- cta3: null,
- background: null,
- },
- ],
- },
- {
- type: "DWSCoverCarousel",
- isLocked: true,
- isPinned: true,
- scrollpointer: false,
- items: [
- {
- type: "DwsCover",
- isLocked: false,
- isPinned: false,
- owner: "hidden",
- palette: "dark",
- gradient: false,
- title: "Titolo Slide 1",
- preTitle: "Pre Titolo Slide 1",
- chapter: {
- name: "Chapter slide 1",
- nav: false,
- },
- scrollIndicator: false,
- link: {
- content: "",
- title: "",
- url: "",
- target: "_blank",
- },
- cta2: {
- content: "Testfff",
- url: "http://localhost:4200/back-office/cms/dws-pages/new",
- target: "_blank",
- },
- cta3: null,
- background: null,
- },
- {
- type: "DwsCover",
- isLocked: true,
- isPinned: false,
- owner: "hidden",
- palette: "",
- gradient: false,
- title: "Titolo Slide 2",
- preTitle: "Pre Titolo Slide 2",
- chapter: {
- name: "",
- nav: false,
- },
- scrollIndicator: false,
- link: {
- content: "",
- title: "",
- url: "",
- target: "_blank",
- },
- cta2: {
- content: "Content cta2",
- url: "",
- target: "_blank",
- },
- cta3: null,
- background: null,
- },
- ],
- },
- ],
- },
- slug: "home",
- status: "draft",
- id: "6010301d70155b5998348291",
- original: "600ffc5f70155b59983480ef",
- createdAt: "2021-01-26T15:07:09.244Z",
- updatedAt: null,
- revision: 0,
- active: false,
- };
Add Comment
Please, Sign In to add comment