Skip to content

Instantly share code, notes, and snippets.

View vdsabev's full-sized avatar

Vlad Sabev vdsabev

View GitHub Profile
<template>
<div>
<button type="button" @click="decrement(step)">-</button>
<input type="text" :value="value" @input="setValue($event.target.value)" />
<button type="button" @click="increment(step)">+</button>
</div>
</template>
<script>
export default {
@vdsabev
vdsabev / 02-edit-form-meaningful.jsx
Last active December 22, 2018 20:10
A Simple Rule for Naming Event Handlers
class EditForm extends React.Component {
state = { discardModalIsShown: false };
// Previously `onClick`
showDiscardModal = () => this.setState({ discardModalIsShown: true });
// Previously `onNo` / `onClose`
hideDiscardModal = () => this.setState({ discardModalIsShown: false });
// Previously `onSubmit`
@vdsabev
vdsabev / 01-edit-form-vague.jsx
Last active December 21, 2018 20:16
A Simple Rule for Naming Event Handlers
class EditForm extends React.Component {
state = { discardModalIsShown: false };
onSubmit = ($event) => {
$event.preventDefault();
this.setState({ discardModalIsShown: false });
this.props.onSave();
};
onClick = () => this.setState({ discardModalIsShown: true });

Keybase proof

I hereby claim:

  • I am vdsabev on github.
  • I am vdsabev (https://keybase.io/vdsabev) on keybase.
  • I have a public key ASDMrSIeb-X_-iGrkkbOejCsR3PM-JDagUCyYbk_fWi76wo

To claim this, I am signing this object:

@vdsabev
vdsabev / download.js
Last active June 30, 2023 02:14
Bookmarklet - download all links on a page
javascript:(() => {
const items = document.querySelectorAll('a');
let delay = 0;
for (let index = 0; index < items.length; index++) {
const item = items[index];
item.setAttribute('download', item.getAttribute('href'));
setTimeout(() => item.click(), delay);
delay += 500;
}
})();
@vdsabev
vdsabev / awesome.md
Last active October 26, 2017 15:17
An awesome list of awesome things

Development

Animation & Interactivity

  • IntersectionObserver - get notified when element properties change, e.g. when an element becomes visible or invisible

Authentication

Components

  • Web components - encapsulate HTML / CSS / JS components and use them across the whole web
@vdsabev
vdsabev / 01-mithril-counter-class.jsx
Last active August 17, 2017 09:17
Exploring Unidirectional Components in Mithril
class Counter {
oninit({ attrs }) {
this.count = attrs.count || 0;
}
decrement = () => this.count--;
increment = () => this.count++;
view() {
return (
@vdsabev
vdsabev / 06-hypermithril-counter.jsx
Last active August 15, 2017 13:28
Exploring Unidirectional Components in Mithril
const Counter = component({
state: {
count: 0
},
actions: {
decrement: ({ count }) => ({ count: count - 1 }),
increment: ({ count }) => ({ count: count + 1 })
},
view: ({ count }, { decrement, increment }) => <div>...</div>
});
@vdsabev
vdsabev / 05-hypermithril-basic.jsx
Last active August 17, 2017 10:28
Exploring Unidirectional Components in Mithril
const component = (options = {}) => (vnode) {
let state = { ...options.state, ...vnode.attrs };
const proxyActions = {};
Object.keys(options.actions).forEach((key) => {
proxyActions[key] = (...args) => {
const newState = options.actions[key](state, proxyActions, ...args);
if (newState) {
state = { ...state, ...newState };
}
@vdsabev
vdsabev / 04-mithril-counter-trimmed.jsx
Last active August 15, 2017 13:27
Exploring Unidirectional Components in Mithril
const Counter = ({ attrs: { count = 0 } }) => {
const decrement = () => count--;
const increment = () => count++;
return {
view: () => <div>...</div>
};
};