Skip to content

Instantly share code, notes, and snippets.

View teimurjan's full-sized avatar
:electron:

Teimur Gasanov teimurjan

:electron:
View GitHub Profile
@teimurjan
teimurjan / arrow-in-child.js
Last active May 21, 2018 06:55
blog-react-applications-optimization
class Todo extends React.Component {
handleClick = e => {
this.props.onClick(this.props.todo.id);
};
render() {
return (
<li className="todo" onClick={this.handleClick}>
{this.props.todo}
</li>
@teimurjan
teimurjan / bind-in-render.js
Created May 21, 2018 06:48
blog-react-applications-optimization
render() {
return (
<ul>
{this.props.todos.map(todo => (
<Todo
todo={todo}
onClick={this.props.handleClick.bind(this)}
/>
))}
</ul>
@teimurjan
teimurjan / bind-in-constructor.js
Created May 21, 2018 06:49
blog-react-applications-optimization
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
@teimurjan
teimurjan / arrow-instead-of-bind.js
Created May 21, 2018 06:52
blog-react-applications-optimization
handleClick = todoId => {
this.setState({
[todoId]: { clicked: true }
});
};
@teimurjan
teimurjan / constant-object-in-render.js
Last active May 21, 2018 06:54
blog-react-applications-optimization
export default class extends React.PureComponent {
render() {
return (
<TodoList
options={{
wrap: false,
maximizeOnFoucs: true
}}
/>
);
@teimurjan
teimurjan / constant-object-variable.js
Created May 21, 2018 06:56
blog-react-applications-optimization
const TODO_LIST_OPTIONS = {
wrap: false,
maximizeOnFoucs: true
};
export default class extends React.PureComponent {
render() {
return <TodoList options={TODO_LIST_OPTIONS} />;
}
}
@teimurjan
teimurjan / keys-as-indexes.js
Created May 21, 2018 06:58
blog-react-applications-optimization
// You have this 4 components
const elements = [
{ type: "div", key: 0, textContent: "Container #0" },
{ type: "div", key: 1, textContent: "Container #1" },
{ type: "div", key: 2, textContent: "Container #2" },
{ type: "div", key: 3, textContent: "Container #3" }
];
// Delete Container #1
const elements = [
@teimurjan
teimurjan / avoid-lifecycle.js
Created May 21, 2018 07:00
blog-react-applications-optimization
const TodoFactory = ({ todo, onClick }) => (
<li className="todo" onClick={onClick}>
{todo.title}
</li>
);
export default ({ todos }) => (
<ul>{todos.map(todo => TodoFactory({ todo, onClick: console.log }))}</ul>
);
@teimurjan
teimurjan / dto.py
Created July 5, 2018 04:21
django-solid-architecture
class DTO:
def __init__(self, id_):
self._id = id_
@property
def id(self):
return self._id
class UserDTO(DTO):
@teimurjan
teimurjan / index.js
Last active May 22, 2019 05:12
Gatsby Google Optimize Utils
const React = require("react");
const config = require("../config");
const createGoogleOptimizeSnippet = experimentsIds => `
gtag('config', '${config.GTM_ID}', {'optimize_id': '${
config.GOOGLE_OPTIMIZE_ID
}'});
${experimentsIds.map(expId => `gtag('set', {'expId': '${expId}'});`)}
window.onload = function(){dataLayer.push({'event': 'optimize.activate'});};
`;