Skip to content

Commit

Permalink
Error Fix example -3
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetkuslular committed Aug 8, 2022
1 parent b03291f commit 7cb6261
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"identity-obj-proxy": "3.0.0",
"intersection-observer": "0.7.0",
"js-cookie": "^2.2.1",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "2.5.2",
"newrelic": "^6.13.0",
"node-sass": "6.0.1",
Expand Down
3 changes: 2 additions & 1 deletion src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
} from './universal/service/RenderService';
import Component from './universal/model/Component';
import logger from './universal/utils/logger';
import omit from 'lodash/omit';
import omit from './universal/utils/lodash/omit';

import { getPreviewFile } from './universal/utils/previewHelper';

const appConfig = require('__APP_CONFIG__');
Expand Down
2 changes: 1 addition & 1 deletion src/universal/model/Renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import omit from 'lodash/omit';
import { isPreview, renderComponent, renderLinksAndScripts } from '../service/RenderService';
import { BLACKLIST_OUTPUT } from '../utils/constants';
import omit from '../utils/lodash/omit';

export default class Renderer {
constructor(component, context) {
Expand Down
3 changes: 2 additions & 1 deletion src/universal/partials/Welcome/PartialCards.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import groupBy from 'lodash/groupBy';
import ReactDOMServer from 'react-dom/server';
import { ServerStyleSheet } from 'styled-components';

import partials from './partials';
import groupBy from '../../utils/lodash/groupBy';

const STATUS_COLOR = {
live: '#8dc63f',
dev: '#FF6000',
Expand Down
22 changes: 22 additions & 0 deletions src/universal/utils/lodash/groupBy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function groupBy(arr, predicate) {

This comment has been minimized.

Copy link
@emreyalvac

emreyalvac Aug 8, 2022

Member

Bu function hali hazirda utils/struct altinda var diye hatirliyorum. Diger kullanan yerleri de duruma gore duzeltmek gerekebilir. Ek olarak buraya lodash/groupBy demek yerine baska isim kullanabiliriz.

return arr.reduce((obj, item) => {
// Check if the predicate is a function to run on the item or a property of it
const key = predicate
? typeof predicate === 'function'
? predicate(item)
: item[predicate]
: item;

if (obj && !obj.hasOwnProperty(key)) {
obj[key] = [];
}

// Push the value to the object
obj[key].push(item);

// Return the object to the next item in the loop
return obj;
}, {});
}

export default groupBy;
20 changes: 20 additions & 0 deletions src/universal/utils/lodash/omit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const keyControl = (keys, key) => {
for (const item in keys) {
if (Array.isArray(keys[item])) {
const arrayStatus = keyControl(keys[item], key);
if (!arrayStatus) {
return false;
}
}
if (keys[item] === key) {
return false;
}
}
return true;
};

function omit(obj, ...keys) {
return Object.fromEntries(Object.entries(obj).filter(([k]) => keyControl(keys, k)));
}

export default omit;

0 comments on commit 7cb6261

Please sign in to comment.