Skip to content

Instantly share code, notes, and snippets.

@jeromepl
jeromepl / getQuery-plugin.js
Last active Sep 18, 2017
Get a CSS-style query to a DOM element. (With JQuery)
View getQuery-plugin.js
// Same as the other file, but this time as a JQuery plugin.
// Usage: $(someElement).getQuery();
(function ($) {
$.fn.getQuery = function() {
var id = this.attr('id');
var localName = this.prop('localName');
if (id)
return '#' + escapeCSSString(id);
@jeromepl
jeromepl / debounceGroup.js
Last active Jul 17, 2017
Debouncer that keeps the last N calls active
View debounceGroup.js
// Keep the last N calls active
// A regular debounce function would only keep a single function call
// on timeout at a time.
function debounceGroup(func, wait, groupSize) {
var timeouts = []; // Use this array as a queue of method calls
return function() {
var context = this,
args = Array.prototype.slice.call(arguments, 0);
if (timeouts.length >= groupSize)
clearTimeout(timeouts.shift());
@jeromepl
jeromepl / Enhance.js
Last active Apr 6, 2020 — forked from sebmarkbage/Enhance.js
Higher-order Components in React with ES7
View Enhance.js
import { Component } from "React";
export default (ComposedComponent) => class extends Component {
constructor(props) {
super(props);
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}