Skip to content

Instantly share code, notes, and snippets.

View vadym1930's full-sized avatar
🏄

Vadym Horbonos vadym1930

🏄
View GitHub Profile
@vadym1930
vadym1930 / inherits.js
Created January 11, 2017 19:16
inherits function ( from https://github.com/nodejs/node-v0.x-archive/blob/master/lib/util.js#L634-L644), OOP classical pattern example
function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
@vadym1930
vadym1930 / prototypal.js
Created January 11, 2017 21:43
OOP prototypal pattern example
var human = {
species: "human",
sayName: function() {
console.log("My name is " + this.name);
},
isAlive: true,
/**
* create an object with set of properties. Getting object within needing
* properties and values and in will be the instanse of current object
import jQuery from "jquery";
jQuery(() => {
const w3SliderModule = (() => {
"use strict";
function Slider(slider){
this.slides = slider.find('.slidesImages');

Review

Folder structure

  1. The good way of understanding code is separating containers, components, js-components, typo, some partials in own folders or / and files. Sass, (js, if more code) should be separated;
  2. Another bonn tone is dividing source and dest code in own folders.
    src — folder for source stuff: sass, js, images etc.
    dist (dest) — foder for dest stuff: latest minifyied .js .css files
    to some opinion — all files are needed to deploy on the server should be exist in dest(dist) folder

Sass (bad things, recomendations)

  1. Bad way to make spacings with margins, especialy margin-top.
  2. More than 2 nested css selectors.
@vadym1930
vadym1930 / Slider.js
Last active May 11, 2019 15:41
Example of slider component in class pattern, jquery + slick-carousel with Drupal.behaviors
import $ from 'jquery';
import 'slick-carousel';
class Slider {
constructor(props) {
this.selector = props.selector;
this.slide = props.slide;
this.key = props.key;
this.slickOptions = props.slickOptions;
this.Drupal = Drupal;
@vadym1930
vadym1930 / .block
Created February 7, 2019 12:37
test chart
license: mit
/**
* Implements hook_preprocess_HOOK().
*/
function THEME_preprocess_paragraph__button_icon(&$variables) {
$paragraph = $variables['elements']['#paragraph'];
$icon = $paragraph->get('field_icon_button')->getValue();
if (!empty($icon)) {
$entity = \Drupal::entityTypeManager()->getStorage("media")->load($icon[0]['target_id']);
$variables['button_icon'] = $entity->field_media_svg->entity->getFileUri();