Skip to content

Instantly share code, notes, and snippets.

View igorvolnyi's full-sized avatar

Igor Volnyi igorvolnyi

View GitHub Profile
@igorvolnyi
igorvolnyi / README.md
Last active February 23, 2021 22:18
DRY solution for Sequelize.js models vs migrations problem
@igorvolnyi
igorvolnyi / pass-slots.md
Created May 29, 2019 11:56 — forked from loilo/pass-slots.md
Vue: Pass Slots through from Parent to Child Components

Vue: Pass Slots through from Parent to Child Components

The Situation

  • We've got some components A, B and C which provide different slots.
    const A = {
      template: `<div><slot name="a">Default A Content</slot></div>`
    }

const B = {

@igorvolnyi
igorvolnyi / DomKeepAlive.md
Created May 29, 2019 12:00 — forked from loilo/DomKeepAlive.md
Keep pre-existing DOM nodes alive inside Vue components

Keep pre-existing DOM alive in Vue

For my use cases, Vue has one critical pitfall: I frequently have/want to use Vue components with <slot>s as wrappers for content from a CMS which I don't have control over. That is, the content comes over the wire via HTML, and I have to activate Vue for some of it.

<interactive-element>
  <p>Slot content I don't have control over</p>
</interactive-element>

I need to activate the Vue component <interactive-element>.

@igorvolnyi
igorvolnyi / split-pull-requests.md
Created May 29, 2019 12:03 — forked from loilo/split-pull-requests.md
Split a large pull request into two
@igorvolnyi
igorvolnyi / magic-methods.js
Created May 29, 2019 12:04 — forked from loilo/magic-methods.js
PHP Magic Methods in JavaScript
function magicMethods (clazz) {
// A toggle switch for the __isset method
// Needed to control "prop in instance" inside of getters
let issetEnabled = true
const classHandler = Object.create(null)
// Trap for class instantiation
classHandler.construct = (target, args) => {
// Wrapped class instance
@igorvolnyi
igorvolnyi / bubble.md
Created May 29, 2019 12:06 — forked from loilo/bubble.md
Make Vue events bubble

Make Vue events bubble

Vue events don't bubble the component tree themselves. However when writing wrapper components this can be the desired behaviour.

This code registers a global bubble directive which allows to re-emit all given events:

Let's say we want to bubble events start, accelerate and brake of our component Car.

Without any help, we'd roughly have to do this:

@igorvolnyi
igorvolnyi / deepAsync.js
Last active May 29, 2019 12:19 — forked from loilo/deepAsync.js
Deeply resolves all promises in a data structure
// Arbitrarily nested object containing Promises goes in
// Plain data structure comes out
async function deepAsync (object) {
// Walk arrays
if (Array.isArray(object)) {
return Promise.all(object.map(async item => await deepAsync(item)))
// Walk objects
} else if (object instanceof Object) {
return Object
@igorvolnyi
igorvolnyi / rangeslider.md
Created May 29, 2019 12:21 — forked from loilo/rangeslider.md
Rangeslider

Rangeslider

This is a small Rangeslider library. It's probably not production ready yet (i.e. not been tested in a production project), therefore it's just a Gist and not a fully-blown GitHub repo.

Try it out in this CodePen!

I created this because no existing library met all my criteria:

  • no heavy-weight third-party dependencies (i.e. no jQuery)
@igorvolnyi
igorvolnyi / composition.js
Created January 27, 2020 19:51
Inheritance vs composition in JavaScript
function createProgrammer(name) {
const programmer = { name };
return {
...programmer,
...canCode(programmer)
};
}
function canCode({ name }) {
return {
@igorvolnyi
igorvolnyi / index.html
Created January 28, 2020 00:24
Drag-n-drop in pure JavaScript
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Drag-n-drop на чистом JS</title>
</head>
<body>