Skip to content

Conversation

viskosa
Copy link
Collaborator

@viskosa viskosa commented Jul 20, 2018

No description provided.

@viskosa
Copy link
Collaborator Author

viskosa commented Jul 21, 2018

I've done virtualizing of contacts page. There are two solutions, the second I like more

];

const captions = ['Name', 'Last name', 'Email'];
const footerContent = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

footer content is a static no need to virtualize it

}
]

const contactsPage = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use class instead of object

email: 'ViktorKriv@ec.ua'
}
];
this.footerContent = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just a static content, not a data that should be virtualized.

The difference between static content in "virtualized" for example,
The server would never know how many pages do you have but the server would know about users.

So you make a decision based on that knowledge

@viskosa
Copy link
Collaborator Author

viskosa commented Jul 23, 2018

Footer was made like a static content

}

renderFooter() {
document.body.innerHTML += this.createFooter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use document.body :)

create an additional tag and work inside it.
You can meet some unpredictable behavior if you rewrite the whole body content. It will be very hard to debug it and found a mistake

}

createFooter(){
return `<footer class="footer">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just place such html-layout inside render

buttonsHandler(){
let buttonsParent = document.querySelector('.keypad-holder');

buttonsParent.addEventListener('click', this.clickHandler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure it works correctly?

<tr>
<td>Влад</td>
<td>Яма</td>
<td>VladYama@ec.ua</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to delete commented part

class KeypadPage {
constructor(){
this.title = 'Keypad';
this.buttonsValues = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#', ''];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move all content specifiec part to innerHTML it's better to omit such data inside

<span class = "tab-text">Contacts</span>
</a>
<a href="keypad.html" class="tab">
<span class="glyphicon glyphicon-th" aria-hidden="true"></span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.renderLink({glyphicon:'pencil', href:'keypad.html'})
this.renderLink({glyphicon:'th', href:'contacts'})
this.renderLink({glyphicon:'pencil', href})
this.renderLink({glyphicon:'pencil', href})

}

render(){
document.body.innerHTML = this.renderHeader() + this.renderMain() + this.renderFooter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move all HTML specific content to render, and remove additional properties
for example:
renderHeader, renderMain, renderFooter

phoneApp/main.js Outdated
}
]

const contactsPage = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please create class ContactsPage and move all logic there

phoneApp/main.js Outdated
let nav = this.newEl('div', null, {className: 'main-nav'});

footerContent.forEach((item) => {
let link = this.newEl('a', null, {className: `tab ${item.additionalClass}` , hrefAttr: item.href } );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please create innerHTML instead of createElement

phoneApp/main.js Outdated
},

setAttribute(element, attributes) {
let {className, typeAttr, forAttr, idAttr, placeholderAttr, hrefAttr, ariahiddenAttr} = attributes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 super method/function


this.pages = {
contacts: new ContactsPage(this.state), // тут передали ссылку на this.state
adduser: new AddUser(this.state),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there a typo with formatting

</footer>`;

//this.initializeRouterHandlers();
this.appDOMNode = mountNode.querySelector('#app'); // сюда будем делать рендер всех страниц
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getElementById working around in 10 times faster than querySelector, I guess it's better to switch it

parent.addEventListener('click', (e) => {
e.preventDefault();
//let target = e && e.target;
let target = e && e.target && (e.target.closest('a') || e.target.classList.contains('tab'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... such checks look like a bit overhead.
You can add additional attributes to every link and indicate "user clicked on link" that way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on real word usage probably we should be always 100% be sure about our target


if (target.classList.contains('active')) return;
if (target.classList.contains('tab')) {
let active = document.querySelector('.active');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querySelector is always performance costly operation it better to omit every time you can do it.

So, for example, you could the same solution as we did with a slider in class.


let href = target.getAttribute('href');
//console.log(href);
this.state.activePage = href.replace(/-/g, '').toLowerCase();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably href.replace(/-/g, '').toLowerCase() such transformation adding new mental layout for understanding your app. You could just make "already" prepared data in the HTML without requires to transform it in future.

Or you can just use your HTML-attribute to indicate path of navigation and build "Map" to connect your active page

</div>`;
}

renderLink(options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's not used anymore? we may delete it

@@ -0,0 +1,70 @@
class User {
constructor(globalState){
this.state = globalState; //стал равен this.state-у со страницы App.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something went wrong with the formatting. Try to install prettier to improve your code-base formatting.


}

initializeRouter () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure you can create an additional file and call it "Router.js" - and move all specific to navigation logic in.

Then initialize as other pages.

The main goal what we trying to solve the minimal splitting by responsibilities have you feel it?

}

renderLink(options) {
let {href, glyphicon, text, active} = options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be moved to Router.js also



switchRouter() {
const parent = document.querySelector('.main-nav');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make such selector once - and remember the link to it, no need to make it on every

let buttonsParent = document.querySelector('main');
buttonsParent.addEventListener('click', this.clickHandler.bind(this));
}
buttonsHandler() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so huge tabs

buttonsParent.addEventListener('click', this.clickHandler.bind(this));
}
buttonsHandler() {
let buttonsParent = document.querySelector("main");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use const instead of let

e &&
e.target &&
(e.target.closest("button") ||
e.target.classList.contains("add-btn"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if another dev would change that className at button - javascript would break ?
We shouldn't rely on classsNames

e.target &&
(e.target.closest("button") ||
e.target.classList.contains("add-btn"));
if (active == false) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (active == false) return;

let input = active.querySelector("input");
input.style.backgroundColor = "lightgreen";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably you can make it something like with CSS

 :focus {

}

JavaScript not really required there

buttonsParent.addEventListener('click', this.clickHandler.bind(this, placeToInsertNumbers));
window.addEventListener('keypress', this.keyHandler.bind(this, placeToInsertNumbers));
buttonsHandler() {
let buttonsParent = document.querySelector("main");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please you const keyword instead of let

"click",
this.clickHandler.bind(this, placeToInsertNumbers)
);
window.addEventListener(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are ever remove such listener?
for example when-even you changing a page

name: "Дарий",
lastName: "Смирнов",
email: "DariySmirnov@ec.ua"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess such mock data no need anymore because you download them from the server ?

if (insertedNumbersArr.length > 0) {
let numberWithoutLast = insertedNumbersArr.slice(0,-1).join('');
let numberWithoutLast = insertedNumbersArr.slice(0, -1).join("");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please you const instead of let

let target =
e &&
e.target &&
(e.target.closest("a") || e.target.classList.contains("tab")); //You can add additional attributes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you don't need such event delegation because of your event working on a small area of responsibilities.

function switchRounter, should only change the router and don't make any checks and probably has a minimal of conditionalsa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants